Skip to content

Commit 7c1cb6b

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 7c1cb6b

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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
22+
id: version
23+
run: |
24+
VERSION="$(grep -Po '__version__\s*=\s*"\K[^"]+' awslambdaric/__init__.py)"
25+
if [ -z "$VERSION" ]; then
26+
echo "Could not determine version from awslambdaric/__init__.py" >&2
27+
exit 1
28+
fi
29+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
30+
echo "Detected version: $VERSION"
31+
32+
- name: Check if release already exists
33+
id: check
34+
env:
35+
GH_TOKEN: ${{ github.token }}
36+
run: |
37+
if gh release view "${{ steps.version.outputs.version }}" >/dev/null 2>&1; then
38+
echo "exists=true" >> "$GITHUB_OUTPUT"
39+
echo "Release ${{ steps.version.outputs.version }} already exists; skipping."
40+
else
41+
echo "exists=false" >> "$GITHUB_OUTPUT"
42+
fi
43+
44+
- name: Extract changelog notes
45+
if: steps.check.outputs.exists == 'false'
46+
id: notes
47+
run: |
48+
VERSION="${{ steps.version.outputs.version }}"
49+
NOTES="$(awk -v ver="$VERSION" '
50+
index($0, "`" ver "`") == 1 { capture = 1; next }
51+
capture && /^### / { exit }
52+
capture { print }
53+
' RELEASE.CHANGELOG.md)"
54+
# Trim leading/trailing blank lines
55+
NOTES="$(printf '%s\n' "$NOTES" | sed -e '/./,$!d' | tac | sed -e '/./,$!d' | tac)"
56+
if [ -z "$NOTES" ]; then
57+
NOTES="Release $VERSION"
58+
fi
59+
{
60+
echo "body<<EOF"
61+
echo "$NOTES"
62+
echo "EOF"
63+
} >> "$GITHUB_OUTPUT"
64+
65+
- name: Create GitHub Release
66+
if: steps.check.outputs.exists == 'false'
67+
env:
68+
GH_TOKEN: ${{ github.token }}
69+
run: |
70+
VERSION="${{ steps.version.outputs.version }}"
71+
gh release create "$VERSION" \
72+
--target "${{ github.sha }}" \
73+
--title "AWS Lambda Runtime Interface Client for Python v$VERSION" \
74+
--notes "${{ steps.notes.outputs.body }}"

0 commit comments

Comments
 (0)