|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + bump: |
| 7 | + description: "Version bump (patch | minor | major)" |
| 8 | + required: true |
| 9 | + default: patch |
| 10 | + |
| 11 | +jobs: |
| 12 | + release: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + permissions: |
| 15 | + contents: write # allow push + release |
| 16 | + |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 # first-party |
| 19 | + with: |
| 20 | + fetch-depth: 0 # we need all tags |
| 21 | + |
| 22 | + - uses: actions/setup-go@v5 # first-party |
| 23 | + with: |
| 24 | + go-version: '1.22' |
| 25 | + |
| 26 | + # ───────── 1. figure out next tag ───────── |
| 27 | + - id: version |
| 28 | + shell: bash |
| 29 | + run: | |
| 30 | + last=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") |
| 31 | + echo "previous=$last" >>"$GITHUB_OUTPUT" |
| 32 | +
|
| 33 | + v=${last#v}; IFS=. read -r major minor patch <<<"$v" |
| 34 | + case "${{ github.event.inputs.bump }}" in |
| 35 | + patch) patch=$((patch+1));; |
| 36 | + minor) minor=$((minor+1)); patch=0;; |
| 37 | + major) major=$((major+1)); minor=0; patch=0;; |
| 38 | + esac |
| 39 | + next="v${major}.${minor}.${patch}" |
| 40 | + echo "next=$next" >>"$GITHUB_OUTPUT" |
| 41 | +
|
| 42 | + # ───────── 2. update CHANGELOG.md ───────── |
| 43 | + - name: Update changelog |
| 44 | + shell: bash |
| 45 | + run: | |
| 46 | + next=${{ steps.version.outputs.next }} |
| 47 | + prev=${{ steps.version.outputs.previous }} |
| 48 | +
|
| 49 | + { |
| 50 | + echo "## $next" |
| 51 | + echo |
| 52 | + git log "$prev"..HEAD --pretty=format:"- %s" |
| 53 | + echo |
| 54 | + cat CHANGELOG.md 2>/dev/null || true |
| 55 | + } >CHANGELOG.tmp |
| 56 | + mv CHANGELOG.tmp CHANGELOG.md |
| 57 | + git config user.name "github-actions[bot]" |
| 58 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 59 | + git add CHANGELOG.md |
| 60 | + git commit -m "docs: update changelog for $next" |
| 61 | +
|
| 62 | + # ───────── 3. tag & push ───────── |
| 63 | + - name: Tag and push |
| 64 | + shell: bash |
| 65 | + run: | |
| 66 | + tag=${{ steps.version.outputs.next }} |
| 67 | + git tag -s "$tag" -m "Release $tag" || git tag -a "$tag" -m "Release $tag" |
| 68 | + git push origin HEAD:main |
| 69 | + git push origin "$tag" |
| 70 | +
|
| 71 | + # ───────── 4. create & upload release ───────── |
| 72 | + - name: Create GitHub release |
| 73 | + env: |
| 74 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 75 | + shell: bash |
| 76 | + run: | |
| 77 | + tag=${{ steps.version.outputs.next }} |
| 78 | + gh release create "$tag" dist/* \ |
| 79 | + --title "$tag" \ |
| 80 | + --generate-notes |
0 commit comments