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 & Generate Notes id: versioning run: | PREV_TAG=$(git tag -l "v*" --sort=-v:refname | head -n1) echo "Previous tag: $PREV_TAG" if [[ "${{ github.ref }}" == refs/tags/v* ]]; then TAG="${GITHUB_REF#refs/tags/}" else if [ -z "$PREV_TAG" ]; then TAG="v1.0.0" else VER_NUM="${PREV_TAG#v}" IFS='.' read -r MAJOR MINOR PATCH <<< "$VER_NUM" PATCH=$((PATCH + 1)) TAG="v${MAJOR}.${MINOR}.${PATCH}" fi echo "Auto incremented patch version to $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 # 生成详细的 Release Changelog 正文 cat << NOTES > release_notes.md ### 🚀 What's Changed in ${TAG} NOTES if [ -n "$PREV_TAG" ]; then git log "${PREV_TAG}..HEAD" --pretty=format:"- %s (%h by @%an)" >> release_notes.md else git log -n 10 --pretty=format:"- %s (%h by @%an)" >> release_notes.md fi echo "" >> release_notes.md echo "" >> release_notes.md if [ -n "$PREV_TAG" ]; then echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREV_TAG}...${TAG}" >> release_notes.md fi cat release_notes.md - 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 }} body_path: release_notes.md files: | dist/*