@@ -57,13 +57,21 @@ jobs:
5757 - name : Cache Go modules
5858 uses : actions/cache@v4
5959 with :
60- path : ~/go/pkg/mod
61- key : ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
60+ path : |
61+ ~/.cache/go-build
62+ ~/go/pkg/mod
63+ key : ${{ runner.os }}-go-${{ matrix.goos }}-${{ matrix.goarch }}-${{ hashFiles('**/go.sum') }}-${{ hashFiles('**/go.mod') }}
6264 restore-keys : |
65+ ${{ runner.os }}-go-${{ matrix.goos }}-${{ matrix.goarch }}-
6366 ${{ runner.os }}-go-
67+ fail-on-cache-miss : false
6468
6569 - name : Download dependencies
66- run : go mod download
70+ run : |
71+ go mod download
72+ go mod tidy
73+ go mod verify || true
74+ # 如果verify失败,继续构建,因为可能是CI环境中的临时问题
6775
6876 - name : Build
6977 env :
7482 run : |
7583 mkdir -p dist
7684 output_name="${{ matrix.filename }}"
77- go build -ldflags="-s -w -X main.version=${{ github.ref_name }}" -o "dist/${output_name}" .
85+ # 确保在构建前重新同步依赖
86+ go mod download
87+ go build -mod=readonly -ldflags="-s -w -X main.version=${{ github.ref_name }}" -o "dist/${output_name}" .
7888
7989 - name : Create archive
8090 run : |
@@ -116,23 +126,7 @@ jobs:
116126 done
117127 ls -la release-assets/
118128
119- - name : Generate changelog
120- id : changelog
121- run : |
122- # 获取上一个tag
123- PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
124- if [ -n "$PREVIOUS_TAG" ]; then
125- echo "## 更新内容" > CHANGELOG.md
126- echo "" >> CHANGELOG.md
127- git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..HEAD >> CHANGELOG.md
128- else
129- echo "## 首次发布" > CHANGELOG.md
130- echo "" >> CHANGELOG.md
131- git log --pretty=format:"- %s (%h)" >> CHANGELOG.md
132- fi
133- echo "changelog<<EOF" >> $GITHUB_OUTPUT
134- cat CHANGELOG.md >> $GITHUB_OUTPUT
135- echo "EOF" >> $GITHUB_OUTPUT
129+
136130
137131 - name : Create Release
138132 uses : softprops/action-gh-release@v2
@@ -141,8 +135,6 @@ jobs:
141135 body : |
142136 # 🎉 Release ${{ github.ref_name }}
143137
144- ${{ steps.changelog.outputs.changelog }}
145-
146138 ## 📦 下载
147139
148140 选择适合您系统的二进制文件:
0 commit comments