Skip to content

Commit 8fb0136

Browse files
committed
Automate release creation on package version bumps
1 parent f61e5f4 commit 8fb0136

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Release on Version Bump
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout repo
17+
uses: actions/checkout@v5
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Detect version bump
22+
id: version
23+
run: |
24+
set -euo pipefail
25+
26+
NEW_VERSION=$(jq -r .version precise/package.json)
27+
28+
if git show HEAD^:precise/package.json >/tmp/previous-package.json 2>/dev/null; then
29+
PREVIOUS_VERSION=$(jq -r .version /tmp/previous-package.json)
30+
else
31+
PREVIOUS_VERSION=""
32+
fi
33+
34+
{
35+
echo "new_version=$NEW_VERSION"
36+
echo "previous_version=$PREVIOUS_VERSION"
37+
} >> "$GITHUB_OUTPUT"
38+
39+
if [ "$NEW_VERSION" = "$PREVIOUS_VERSION" ]; then
40+
echo "bumped=false" >> "$GITHUB_OUTPUT"
41+
echo "No version bump detected; skipping release creation."
42+
exit 0
43+
fi
44+
45+
echo "bumped=true" >> "$GITHUB_OUTPUT"
46+
47+
- name: Generate changelog
48+
id: changelog
49+
if: steps.version.outputs.bumped == 'true'
50+
run: |
51+
set -euo pipefail
52+
53+
PREVIOUS_TAG=$(git tag --list "*.*.*" --sort=-v:refname | head -n 1 || true)
54+
55+
if [ -n "$PREVIOUS_TAG" ]; then
56+
RANGE="${PREVIOUS_TAG}..HEAD"
57+
LOG=$(git log --no-merges --pretty=format:"- %s (%h)" "$RANGE")
58+
else
59+
LOG=$(git log --no-merges --pretty=format:"- %s (%h)")
60+
fi
61+
62+
if [ -z "$LOG" ]; then
63+
LOG="Changelog not available."
64+
fi
65+
66+
{
67+
echo "changelog<<'EOF'"
68+
echo "$LOG"
69+
echo "EOF"
70+
} >> "$GITHUB_OUTPUT"
71+
72+
- name: Create GitHub release
73+
if: steps.version.outputs.bumped == 'true'
74+
uses: softprops/action-gh-release@v2
75+
with:
76+
tag_name: ${{ steps.version.outputs.new_version }}
77+
name: ${{ steps.version.outputs.new_version }}
78+
body: ${{ steps.changelog.outputs.changelog }}
79+
env:
80+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)