Skip to content

Commit 3a9fff2

Browse files
authored
Merge pull request #515 from unlayer/claude/release-automation
Automate GitHub Releases on version tag push
2 parents 0155e26 + 4b36005 commit 3a9fff2

2 files changed

Lines changed: 54 additions & 1 deletion

File tree

.github/workflows/release.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Release
2+
3+
# Publishing to npm stays local (`npm run release`, using the maintainer's
4+
# 2FA). That command pushes a `vX.Y.Z` tag, which triggers this workflow to
5+
# create the matching GitHub Release from the CHANGELOG entry.
6+
on:
7+
push:
8+
tags:
9+
- 'v*'
10+
11+
permissions:
12+
contents: write
13+
14+
jobs:
15+
github-release:
16+
name: Create GitHub Release
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v7
20+
21+
- name: Extract changelog notes for this tag
22+
run: |
23+
VERSION="${GITHUB_REF_NAME#v}"
24+
# Pull the section between "## <version> (...)" and the next "## ".
25+
# index()==1 matches the literal header start, so no regex escaping
26+
# of the version's dots is needed.
27+
awk -v h="## ${VERSION} (" '
28+
index($0, h) == 1 { f = 1; next }
29+
f && /^## / { exit }
30+
f { print }
31+
' CHANGELOG.md > release-notes.md
32+
# Fall back to a pointer if the version has no changelog section.
33+
if [ ! -s release-notes.md ]; then
34+
echo "See [CHANGELOG.md](https://github.com/${GITHUB_REPOSITORY}/blob/master/CHANGELOG.md)." > release-notes.md
35+
fi
36+
echo "----- release notes for ${VERSION} -----"
37+
cat release-notes.md
38+
39+
- name: Create release
40+
env:
41+
GH_TOKEN: ${{ github.token }}
42+
run: |
43+
# Mark tags containing a hyphen (e.g. v1.7.0-beta.0) as prereleases.
44+
case "$GITHUB_REF_NAME" in
45+
*-*) PRERELEASE="--prerelease" ;;
46+
*) PRERELEASE="" ;;
47+
esac
48+
gh release create "$GITHUB_REF_NAME" \
49+
--repo "$GITHUB_REPOSITORY" \
50+
--title "$GITHUB_REF_NAME" \
51+
--notes-file release-notes.md \
52+
$PRERELEASE

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"lint": "prettier --check .",
3838
"format": "prettier --write .",
3939
"prepare": "npm run build",
40-
"release": "npm run build && npm publish",
40+
"release": "npm run build && npm publish && npm run release:tag",
41+
"release:tag": "git tag v$npm_package_version && git push origin v$npm_package_version",
4142
"netlify-build": "cd demo && npm install && npm run build"
4243
},
4344
"peerDependencies": {

0 commit comments

Comments
 (0)