Skip to content

Commit 96099f0

Browse files
committed
ci: auto-create GitHub Release on version bump to main
Adds a workflow that detects a change to __version__ in awslambdaric/__init__.py on main, then creates a tag and GitHub Release using notes from RELEASE.CHANGELOG.md. Skips if the release already exists.
1 parent 0bd2a49 commit 96099f0

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: release-on-version-change
2+
3+
# Creates a GitHub Release automatically whenever the package version in
4+
# awslambdaric/__init__.py changes on main. The release notes are taken from
5+
# the matching section of RELEASE.CHANGELOG.md.
6+
on:
7+
push:
8+
branches: [ main ]
9+
paths:
10+
- 'awslambdaric/__init__.py'
11+
12+
permissions:
13+
contents: write
14+
15+
jobs:
16+
release:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Read version and check for existing release
22+
id: version
23+
env:
24+
GH_TOKEN: ${{ github.token }}
25+
run: |
26+
VERSION="$(sed -n 's/^__version__[[:space:]]*=[[:space:]]*"\([^"]*\)".*/\1/p' awslambdaric/__init__.py)"
27+
if [ -z "$VERSION" ]; then
28+
echo "Could not determine version from awslambdaric/__init__.py" >&2
29+
exit 1
30+
fi
31+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
32+
echo "Detected version: $VERSION"
33+
if gh release view "$VERSION" >/dev/null 2>&1; then
34+
echo "release_exists=true" >> "$GITHUB_OUTPUT"
35+
echo "Release $VERSION already exists; skipping."
36+
else
37+
echo "release_exists=false" >> "$GITHUB_OUTPUT"
38+
fi
39+
40+
- name: Extract changelog notes
41+
if: steps.version.outputs.release_exists == 'false'
42+
env:
43+
VERSION: ${{ steps.version.outputs.version }}
44+
run: |
45+
# Write notes to a file (never interpolated into the shell) so that
46+
# special characters in the changelog (backticks, parentheses, etc.)
47+
# are passed verbatim to gh via --notes-file.
48+
awk -v ver="$VERSION" '
49+
index($0, "`" ver "`") == 1 { capture = 1; next }
50+
capture && /^### / { exit }
51+
capture { print }
52+
' RELEASE.CHANGELOG.md > release-notes.md
53+
# Trim leading blank lines.
54+
sed -i -e '/./,$!d' release-notes.md
55+
if [ ! -s release-notes.md ]; then
56+
echo "No changelog entry found for $VERSION in RELEASE.CHANGELOG.md." >&2
57+
echo "Add a '\`$VERSION\`' section before bumping the version." >&2
58+
exit 1
59+
fi
60+
echo "----- release notes -----"
61+
cat release-notes.md
62+
63+
- name: Create GitHub Release
64+
if: steps.version.outputs.release_exists == 'false'
65+
env:
66+
GH_TOKEN: ${{ github.token }}
67+
VERSION: ${{ steps.version.outputs.version }}
68+
run: |
69+
gh release create "$VERSION" \
70+
--target "$GITHUB_SHA" \
71+
--title "AWS Lambda Runtime Interface Client for Python v$VERSION" \
72+
--notes-file release-notes.md \
73+
--latest

0 commit comments

Comments
 (0)