name: Release on: push: branches: - main tags: - 'v*' permissions: contents: write jobs: build: name: Build & Release runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 with: fetch-depth: 0 - name: Determine Version Tag id: versioning run: | if [[ "${{ github.ref }}" == refs/tags/v* ]]; then TAG="${GITHUB_REF#refs/tags/}" else # 获取最新语义化版本 tag (例如 v1.1.0) LATEST_TAG=$(git tag -l "v*" --sort=-v:refname | head -n1) if [ -z "$LATEST_TAG" ]; then LATEST_TAG="v1.0.0" fi # 去除前缀 v VER_NUM="${LATEST_TAG#v}" # 拆解 MAJOR.MINOR.PATCH IFS='.' read -r MAJOR MINOR PATCH <<< "$VER_NUM" PATCH=$((PATCH + 1)) TAG="v${MAJOR}.${MINOR}.${PATCH}" echo "Auto incremented patch version to $TAG" # 打上本地 tag 并推送到远程 git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" git tag "$TAG" git push origin "$TAG" fi echo "tag=$TAG" >> $GITHUB_OUTPUT - name: Set up Go uses: actions/setup-go@v5 with: go-version: '1.22' - name: Build Hub & Agent run: | mkdir -p dist # Linux AMD64 CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w" -o dist/vps-commander-hub-linux-amd64 ./cmd/hub CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w" -o dist/vps-commander-agent-linux-amd64 ./cmd/agent # Linux ARM64 CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -ldflags "-s -w" -o dist/vps-commander-hub-linux-arm64 ./cmd/hub CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -ldflags "-s -w" -o dist/vps-commander-agent-linux-arm64 ./cmd/agent # Checksums cd dist sha256sum * > checksums.txt cd .. - name: Create GitHub Release uses: softprops/action-gh-release@v2 with: tag_name: ${{ steps.versioning.outputs.tag }} name: Release ${{ steps.versioning.outputs.tag }} files: | dist/* generate_release_notes: true