|
| 1 | +# Merge-to-release automation |
| 2 | +# |
| 3 | +# Flow: |
| 4 | +# 1. A PR merges to master (or workflow_dispatch for the first guarded run). |
| 5 | +# 2. svu inspects the commit log since the last vX.Y.Z tag and computes |
| 6 | +# the next semver based on conventional commits (feat→minor, fix→patch, |
| 7 | +# breaking→major). |
| 8 | +# 3. If the computed next version differs from current (i.e. there are |
| 9 | +# releasable commits), the job tags HEAD with the new version and pushes |
| 10 | +# the tag — all in the SAME job that runs goreleaser. |
| 11 | +# This avoids the "default GITHUB_TOKEN-pushed tag doesn't trigger a |
| 12 | +# downstream workflow" trap: tag + release happen in one atomic job. |
| 13 | +# 4. goreleaser builds the binaries and creates the GitHub Release. |
| 14 | +# 5. If there are no new feat/fix commits, the job exits early without |
| 15 | +# creating a release. |
| 16 | +# |
| 17 | +# First-launch guard: |
| 18 | +# The `environment: release` line below requires manual approval via |
| 19 | +# GitHub → Settings → Environments → release before any run proceeds. |
| 20 | +# Once the monorepo branch has landed on master and one release has been |
| 21 | +# verified, remove the `environment: release` line in a follow-up PR to |
| 22 | +# enable fully automatic releases. |
| 23 | + |
1 | 24 | name: Release |
2 | 25 |
|
3 | 26 | on: |
4 | 27 | push: |
5 | | - tags: |
6 | | - - '*' |
| 28 | + branches: [master] |
| 29 | + workflow_dispatch: {} # manual trigger for the first guarded run |
| 30 | + |
| 31 | +concurrency: |
| 32 | + group: release |
| 33 | + cancel-in-progress: false # never cancel an in-flight release |
7 | 34 |
|
8 | 35 | jobs: |
9 | 36 | release: |
10 | | - if: contains(github.ref, 'refs/tags/') |
11 | 37 | runs-on: ubuntu-latest |
| 38 | + # FIRST-LAUNCH GUARD: requires manual approval via GitHub Environment. |
| 39 | + # Remove this line after the first verified release. |
| 40 | + environment: release |
| 41 | + permissions: |
| 42 | + contents: write # push tags + create GitHub Releases |
| 43 | + |
12 | 44 | steps: |
13 | | - - name: Checkout |
14 | | - uses: actions/checkout@v3 |
| 45 | + - uses: actions/checkout@v4 |
| 46 | + with: |
| 47 | + fetch-depth: 0 # svu and goreleaser both need full tag history |
15 | 48 |
|
16 | | - - name: Set up go |
17 | | - uses: actions/setup-go@v3 |
18 | | - with: |
19 | | - go-version: 1.19.2 |
| 49 | + - uses: actions/setup-go@v5 |
| 50 | + with: |
| 51 | + go-version: '1.25' |
20 | 52 |
|
21 | | - - name: Build |
22 | | - run: bash hack/github-release.sh |
| 53 | + - name: Install svu |
| 54 | + run: go install github.com/caarlos0/svu@latest |
| 55 | + env: |
| 56 | + GOPROXY: https://goproxy.cn,direct |
23 | 57 |
|
24 | | - - name: Create release |
25 | | - uses: softprops/action-gh-release@v1 |
26 | | - with: |
27 | | - token: ${{ secrets.RELEASE_GITHUB_TOKEN }} |
28 | | - files: | |
29 | | - out/*.zip |
| 58 | + - name: Compute next version & tag |
| 59 | + id: ver |
| 60 | + run: | |
| 61 | + NEXT="$("$(go env GOPATH)/bin/svu" next)" |
| 62 | + CURRENT="$("$(go env GOPATH)/bin/svu" current)" |
| 63 | + echo "next=$NEXT" >> "$GITHUB_OUTPUT" |
| 64 | + echo "current=$CURRENT" >> "$GITHUB_OUTPUT" |
| 65 | + if [ "$NEXT" != "$CURRENT" ]; then |
| 66 | + git config user.name "github-actions[bot]" |
| 67 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 68 | + git tag "$NEXT" |
| 69 | + git push origin "$NEXT" |
| 70 | + echo "released=true" >> "$GITHUB_OUTPUT" |
| 71 | + else |
| 72 | + echo "No new feat/fix commits since $CURRENT — skipping release." |
| 73 | + echo "released=false" >> "$GITHUB_OUTPUT" |
| 74 | + fi |
30 | 75 |
|
| 76 | + - uses: goreleaser/goreleaser-action@v6 |
| 77 | + if: steps.ver.outputs.released == 'true' |
| 78 | + with: |
| 79 | + version: latest |
| 80 | + args: release --clean |
| 81 | + env: |
| 82 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 83 | + GOPROXY: https://goproxy.cn,direct |