Repository navigation
75 lines (64 loc) · 2.46 KB
/
Copy pathrelease.yml
File metadata and controls
75 lines (64 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Automated release.
#
# On every push/merge to main, git-cliff computes the next semantic version
# from the Conventional Commit history since the last tag, regenerates
# CHANGELOG.md for that version, tags it, and publishes a GitHub Release whose
# notes are that version's changelog section.
#
# The release commit is pushed with GITHUB_TOKEN, which by design does not
# retrigger workflows — so this never loops. If there are no releasable commits
# since the last tag, the job is a no-op.
name: Release
on:
push:
branches: [main]
permissions:
contents: write
concurrency:
group: release
cancel-in-progress: false
jobs:
release:
# Belt and braces: never react to our own release commit.
if: ${{ !startsWith(github.event.head_commit.message, 'chore(release):') }}
runs-on: ubuntu-latest
steps:
- name: Check out full history
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install git-cliff
uses: taiki-e/install-action@v2
with:
tool: git-cliff
- name: Compute next version
id: version
run: |
next="$(git cliff --bumped-version)"
latest="$(git describe --tags --abbrev=0 2>/dev/null || echo '')"
echo "next=$next" >> "$GITHUB_OUTPUT"
if [ -n "$next" ] && [ "$next" != "$latest" ]; then
echo "release=true" >> "$GITHUB_OUTPUT"
else
echo "release=false" >> "$GITHUB_OUTPUT"
echo "No releasable changes since ${latest:-repo start}."
fi
- name: Update changelog, tag and release
if: steps.version.outputs.release == 'true'
env:
VERSION: ${{ steps.version.outputs.next }}
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
# Regenerate the whole changelog with the new version, and the
# release notes (just the new section, no header/footer).
git cliff --bump --output CHANGELOG.md
git cliff --bump --unreleased --strip all --output RELEASE_NOTES.md
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add CHANGELOG.md
git commit -m "chore(release): ${VERSION#v}"
git tag -a "$VERSION" -m "$VERSION"
git push origin HEAD:main
git push origin "$VERSION"
gh release create "$VERSION" --title "$VERSION" --notes-file RELEASE_NOTES.md