From 8f40c70504948959d78a5879bc591be5651af12d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=85=8E=E9=A5=BC=E6=9E=9C=E5=AD=90=E5=8D=B7=E9=B2=A8?= =?UTF-8?q?=E9=B1=BC=E8=BE=A3=E6=A4=92?= Date: Mon, 30 Dec 2024 19:25:59 +0800 Subject: [PATCH] chore: update GoReleaser configuration and enhance auto-tag workflow - Upgraded GoReleaser configuration to version 2, adding build verification and improved release settings. - Replaced 'go mod download' with 'go mod vendor' and 'go mod verify' for better dependency management. - Introduced additional build information such as version, commit, and date in the build flags. - Enhanced the auto-tag workflow by adding a step to prepare the build environment and sync the vendor directory. - Improved release notes formatting with a header and footer for better clarity in changelogs. --- .github/workflows/auto-tag-release.yml | 32 ++++++++++++++++++++++++-- .goreleaser.yml | 27 +++++++++++++++++++++- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/.github/workflows/auto-tag-release.yml b/.github/workflows/auto-tag-release.yml index 38945e8..73e2f54 100644 --- a/.github/workflows/auto-tag-release.yml +++ b/.github/workflows/auto-tag-release.yml @@ -149,6 +149,14 @@ jobs: go mod vendor fi + # 添加构建环境准备步骤 + - name: Prepare Build Environment + run: | + echo "Building version: ${VERSION:-development}" + echo "GOOS=${GOOS:-$(go env GOOS)}" >> $GITHUB_ENV + echo "GOARCH=${GOARCH:-$(go env GOARCH)}" >> $GITHUB_ENV + echo "GO111MODULE=on" >> $GITHUB_ENV + # 修改 GoReleaser 步骤 - name: Run GoReleaser if: ${{ startsWith(github.ref, 'refs/tags/v') || (success() && steps.get_latest_tag.outputs.version != '') }} @@ -156,18 +164,38 @@ jobs: with: distribution: goreleaser version: latest - args: release --clean --timeout 60m --snapshot + args: release --clean --timeout 60m env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} VERSION: ${{ steps.get_latest_tag.outputs.version }} CGO_ENABLED: 0 - GOFLAGS: -mod=vendor GOPATH: ${{ github.workspace }}/go GOROOT: ${{ env.GOROOT }} GOCACHE: ${{ github.workspace }}/.cache/go-build GOMODCACHE: ${{ github.workspace }}/go/pkg/mod GORELEASER_DEBUG: 1 GORELEASER_CURRENT_TAG: ${{ steps.get_latest_tag.outputs.version }} + # 添加额外的构建信息 + BUILD_TIME: ${{ steps.get_latest_tag.outputs.version }} + BUILD_COMMIT: ${{ github.sha }} + + # 优化 vendor 同步步骤 + - name: Sync vendor directory + run: | + echo "Syncing vendor directory..." + go mod tidy + go mod vendor + go mod verify + # 验证 vendor 目录 + if [ -d "vendor" ]; then + echo "Verifying vendor directory..." + go mod verify + # 检查是否有未跟踪的文件 + if [ -n "$(git status --porcelain vendor/)" ]; then + echo "Warning: Vendor directory has uncommitted changes" + git status vendor/ + fi + fi # 添加错误检查步骤 - name: Check GoReleaser Output diff --git a/.goreleaser.yml b/.goreleaser.yml index b170c38..1934821 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,7 +1,10 @@ +version: 2 + before: hooks: - go mod tidy - - go mod download + - go mod vendor + - go mod verify builds: - id: cursor-id-modifier @@ -23,10 +26,32 @@ builds: ldflags: - -s -w - -X 'main.version={{.Version}}' + - -X 'main.commit={{.Commit}}' + - -X 'main.date={{.Date}}' flags: - -trimpath mod_timestamp: '{{ .CommitTimestamp }}' +# 添加构建时的项目设置 +project_name: cursor-id-modifier + +# 添加构建验证 +builds_verify: + - skip: false + cmd: "{{.Binary}} --version" + +# 改进发布配置 +release: + draft: true + prerelease: auto + mode: replace + header: | + ## Release {{.Tag}} ({{.Date}}) + + See [CHANGELOG.md](CHANGELOG.md) for details. + footer: | + **Full Changelog**: https://github.com/owner/repo/compare/{{ .PreviousTag }}...{{ .Tag }} + archives: - id: binary format: binary