Skip to content

优化截图提示 #138

优化截图提示

优化截图提示 #138

Workflow file for this run

# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
name: cicd
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
env:
BINARY_PREFIX: "MiniBot"
BINARY_SUFFIX: ""
jobs:
build:
strategy:
matrix:
goos: [linux]
goarch: [amd64]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Set up Go
uses: actions/setup-go@master
with:
go-version: '1.22'
# - name: Cache downloaded module
# uses: actions/cache@master
# continue-on-error: true
# with:
# path: |
# ~/.cache/go-build
# ~/go/pkg/mod
# key: ${{ runner.os }}-go-${{ matrix.goos }}-${{ matrix.goarch }}-${{ hashFiles('**/go.sum') }}
- name: Build
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
if [ $GOOS = "windows" ]; then export BINARY_SUFFIX="$BINARY_SUFFIX.exe"; fi
export CGO_ENABLED=0
export BINARY_NAME="${BINARY_PREFIX}_${GOOS}_$GOARCH$BINARY_SUFFIX"
go build -o "output/$BINARY_NAME" -trimpath -ldflags "-w -s" .
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.goos }}_${{ matrix.goarch }}
path: output/
- name: Copy Fils
env:
KEY: ${{ secrets.SSH_PRIVATE_KEY }}
HOST: ${{ secrets.SERVER_IP }}
USER: "root"
run: |
echo "Saving key to file..."
echo "${KEY}" > key.txt
echo "Set key file access rights..."
chmod 600 key.txt
ssh -v -p 22 -o StrictHostKeyChecking=no -i key.txt "$USER"@"$HOST" "rm -f /root/MiniBot/${BINARY_PREFIX}*"
echo "Starting SCP process..."
scp -pqrv -P 22 -o StrictHostKeyChecking=no -i key.txt output/* "$USER"@"$HOST":"/root/MiniBot/"
echo "SCP operation completeted."