|
| 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 | + VERSION: ${{ steps.version.outputs.version }} |
| 37 | + run: | |
| 38 | + if gh release view "$VERSION" >/dev/null 2>&1; then |
| 39 | + echo "exists=true" >> "$GITHUB_OUTPUT" |
| 40 | + echo "Release $VERSION already exists; skipping." |
| 41 | + else |
| 42 | + echo "exists=false" >> "$GITHUB_OUTPUT" |
| 43 | + fi |
| 44 | +
|
| 45 | + - name: Extract changelog notes |
| 46 | + if: steps.check.outputs.exists == 'false' |
| 47 | + env: |
| 48 | + VERSION: ${{ steps.version.outputs.version }} |
| 49 | + run: | |
| 50 | + # Write notes to a file (never interpolated into the shell) so that |
| 51 | + # special characters in the changelog (backticks, parentheses, etc.) |
| 52 | + # are passed verbatim to gh via --notes-file. |
| 53 | + awk -v ver="$VERSION" ' |
| 54 | + index($0, "`" ver "`") == 1 { capture = 1; next } |
| 55 | + capture && /^### / { exit } |
| 56 | + capture { print } |
| 57 | + ' RELEASE.CHANGELOG.md > release-notes.md |
| 58 | + # Trim leading/trailing blank lines. |
| 59 | + sed -i -e '/./,$!d' release-notes.md |
| 60 | + if [ ! -s release-notes.md ]; then |
| 61 | + echo "Release $VERSION" > release-notes.md |
| 62 | + fi |
| 63 | + echo "----- release notes -----" |
| 64 | + cat release-notes.md |
| 65 | +
|
| 66 | + - name: Create GitHub Release |
| 67 | + if: steps.check.outputs.exists == 'false' |
| 68 | + env: |
| 69 | + GH_TOKEN: ${{ github.token }} |
| 70 | + VERSION: ${{ steps.version.outputs.version }} |
| 71 | + run: | |
| 72 | + gh release create "$VERSION" \ |
| 73 | + --target "$GITHUB_SHA" \ |
| 74 | + --title "AWS Lambda Runtime Interface Client for Python v$VERSION" \ |
| 75 | + --notes-file release-notes.md \ |
| 76 | + --latest |
0 commit comments