name: Auto Release on Tag on: push: tags: - 'v*' permissions: contents: write jobs: release: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Extract version from tag id: ver run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT - name: Extract CHANGELOG section id: notes run: | set -euo pipefail VERSION="${{ steps.ver.outputs.version }}" NOTES=/tmp/release-notes.md # Extract section for this version from CHANGELOG.md # Pattern: "## v${VERSION}" through the next "## " or EOF if [ ! -f CHANGELOG.md ]; then echo "No CHANGELOG.md found; using minimal release notes" # MUST write the file, not just an output: the create step consumes a FILE, so an # early exit here used to leave --notes-file pointing at a path that never existed, # turning "degrade to minimal notes" into a failed release job (#202). echo "Release v${VERSION}" > "$NOTES" echo "notes_file=$NOTES" >> $GITHUB_OUTPUT exit 0 fi awk -v ver="v${VERSION}" ' $0 ~ "^## " ver { found=1; print; next } found && /^## v/ { exit } found { print } ' CHANGELOG.md > "$NOTES" if [ ! -s "$NOTES" ]; then echo "No matching section in CHANGELOG for v${VERSION}; using minimal notes" echo "Release v${VERSION}" > "$NOTES" fi echo "--- release notes (${VERSION}) ---"; cat "$NOTES" echo "notes_file=$NOTES" >> $GITHUB_OUTPUT - name: Create GitHub Release env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | if gh release view "v${{ steps.ver.outputs.version }}" >/dev/null 2>&1; then echo "Release v${{ steps.ver.outputs.version }} already exists — skipping" exit 0 fi gh release create "v${{ steps.ver.outputs.version }}" \ --title "v${{ steps.ver.outputs.version }}" \ --notes-file "${{ steps.notes.outputs.notes_file }}" \ --latest