| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- name: Release
- on:
- push:
- branches: [main]
- paths: [VERSION]
- workflow_dispatch:
- permissions:
- contents: write
- jobs:
- release:
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v4
- with:
- fetch-depth: 0
- - name: Read version
- id: version
- run: |
- version="$(tr -d '[:space:]' < VERSION)"
- if [ -z "$version" ]; then
- echo "VERSION file is empty" >&2
- exit 1
- fi
- echo "version=$version" >> "$GITHUB_OUTPUT"
- echo "tag=v$version" >> "$GITHUB_OUTPUT"
- - name: Skip if tag already exists
- id: check
- env:
- TAG: ${{ steps.version.outputs.tag }}
- run: |
- if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then
- echo "Tag $TAG already exists; nothing to do."
- echo "exists=true" >> "$GITHUB_OUTPUT"
- else
- echo "exists=false" >> "$GITHUB_OUTPUT"
- fi
- - name: Extract changelog section
- if: steps.check.outputs.exists == 'false'
- env:
- VERSION: ${{ steps.version.outputs.version }}
- run: |
- awk -v ver="$VERSION" '
- $0 ~ "^## \\[" ver "\\]" { found=1; print; next }
- found && /^## \[/ { exit }
- found { print }
- ' CHANGELOG.md > .release-notes.md
- if [ ! -s .release-notes.md ]; then
- echo "No changelog entry found for $VERSION" >&2
- exit 1
- fi
- - name: Create tag and GitHub Release
- if: steps.check.outputs.exists == 'false'
- env:
- GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- TAG: ${{ steps.version.outputs.tag }}
- run: |
- gh release create "$TAG" \
- --target "$GITHUB_SHA" \
- --title "$TAG" \
- --notes-file .release-notes.md
|