44 push :
55 branches :
66 - main
7- - master
7+ tags :
8+ - ' v*'
89 pull_request :
910 branches :
1011 - main
11- - master
1212 workflow_dispatch :
13+ inputs :
14+ tag :
15+ description : ' Tag to release (existing tag name)'
16+ required : true
1317
1418jobs :
1519 build :
@@ -32,11 +36,16 @@ jobs:
3236 steps :
3337 - name : Checkout code
3438 uses : actions/checkout@v4
39+ with :
40+ fetch-depth : 0
41+ ref : ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag || github.ref }}
3542
3643 - name : Set up Go
3744 uses : actions/setup-go@v5
3845 with :
39- go-version : ' 1.23'
46+ go-version-file : go.mod
47+ cache : true
48+ cache-dependency-path : go.sum
4049
4150 - name : Set up Node.js
4251 uses : actions/setup-node@v4
4554 cache : ' npm'
4655 cache-dependency-path : frontend/package-lock.json
4756
48- - name : Get Go cache directory
49- id : gocache
50- shell : bash
51- run : echo "dir=$(go env GOCACHE)" >> $GITHUB_OUTPUT
52-
53- - name : Get Go module cache
54- id : gomodcache
55- shell : bash
56- run : echo "dir=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
57-
58- - name : Cache Go modules
59- uses : actions/cache@v4
60- with :
61- path : |
62- ${{ steps.gomodcache.outputs.dir }}
63- ${{ steps.gocache.outputs.dir }}
64- key : ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
65- restore-keys : |
66- ${{ runner.os }}-go-
67-
6857 - name : Install Wails CLI
6958 run : |
7059 go install github.com/wailsapp/wails/v2/cmd/wails@latest
@@ -236,21 +225,96 @@ jobs:
236225
237226 release :
238227 needs : build
239- if : github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
228+ if : github.event_name == 'workflow_dispatch' || (github.event_name == ' push' && startsWith(github.ref, 'refs/tags/') )
240229 runs-on : ubuntu-latest
241230 permissions :
242231 contents : write
232+ env :
233+ RELEASE_TAG : ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag || github.ref_name }}
234+ RELEASE_REF : ${{ github.event_name == 'workflow_dispatch' && format('refs/tags/{0}', github.event.inputs.tag) || github.ref }}
243235
244236 steps :
237+ - name : Checkout (for git history)
238+ uses : actions/checkout@v4
239+ with :
240+ fetch-depth : 0
241+ ref : ${{ env.RELEASE_REF }}
242+
245243 - name : Download all artifacts
246244 uses : actions/download-artifact@v4
247245 with :
248246 pattern : green-wall-*
249247
248+ - name : Generate contributors list
249+ id : contrib
250+ shell : bash
251+ env :
252+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
253+ run : |
254+ set -euo pipefail
255+ CURRENT_TAG="$RELEASE_TAG"
256+ PREV_TAG=""
257+ RANGE_EXPR="$CURRENT_TAG"
258+ SUMMARY_LABEL="Changes in this release"
259+ if PREV_FOUND=$(git describe --abbrev=0 --tags "${CURRENT_TAG}^" 2>/dev/null); then
260+ PREV_TAG=$PREV_FOUND
261+ RANGE_EXPR="${PREV_TAG}..${CURRENT_TAG}"
262+ SUMMARY_LABEL="Changes since $PREV_TAG"
263+ fi
264+ echo "Using range expression: $RANGE_EXPR"
265+ CONTRIBUTORS=$(git log --format='%aN' $RANGE_EXPR | \
266+ grep -viE '\\[bot\\]' | sort -fu | sed 's/^/- @/')
267+ if [ -z "$CONTRIBUTORS" ]; then
268+ CONTRIBUTORS="- (No user-contributed commits in this range)"
269+ fi
270+ echo "contributors<<EOF" >> $GITHUB_OUTPUT
271+ echo "$CONTRIBUTORS" >> $GITHUB_OUTPUT
272+ echo "EOF" >> $GITHUB_OUTPUT
273+ echo "range_expr=$RANGE_EXPR" >> $GITHUB_OUTPUT
274+ echo "range_label=$SUMMARY_LABEL" >> $GITHUB_OUTPUT
275+ echo "previous_tag=$PREV_TAG" >> $GITHUB_OUTPUT
276+
277+ - name : Summarize changes
278+ id : changes
279+ shell : bash
280+ run : |
281+ set -euo pipefail
282+ RANGE_EXPR="${{ steps.contrib.outputs.range_expr }}"
283+ CHANGES=$(git log --no-merges --pretty='- %s' $RANGE_EXPR)
284+ if [ -z "$CHANGES" ]; then
285+ CHANGES="- No code changes recorded in this range."
286+ fi
287+ echo "summary<<EOF" >> $GITHUB_OUTPUT
288+ echo "$CHANGES" >> $GITHUB_OUTPUT
289+ echo "EOF" >> $GITHUB_OUTPUT
290+
291+ - name : Build release notes body
292+ id : notes
293+ shell : bash
294+ run : |
295+ set -euo pipefail
296+ TAG="$RELEASE_TAG"
297+ DATE=$(date -u +%Y-%m-%d)
298+ {
299+ echo "Release $TAG ($DATE)"
300+ echo
301+ echo "${{ steps.contrib.outputs.range_label }}:"
302+ echo
303+ printf '%s\n' "${{ steps.changes.outputs.summary }}"
304+ echo
305+ echo "## Thanks to our contributors:"
306+ echo "## 特别感谢以下几位贡献者:"
307+ echo
308+ printf '%s\n' "${{ steps.contrib.outputs.contributors }}"
309+ } > RELEASE_BODY.md
310+ echo "body_path=RELEASE_BODY.md" >> $GITHUB_OUTPUT
311+
250312 - name : Create Release
251313 uses : softprops/action-gh-release@v2
252314 with :
253315 draft : true
254316 prerelease : false
255317 files : green-wall-*/*
318+ body_path : ${{ steps.notes.outputs.body_path }}
319+ tag_name : ${{ env.RELEASE_TAG }}
256320
0 commit comments