Skip to content

Commit bb81d88

Browse files
authored
Create GitHub releases with changelog (#6756)
* Create GitHub releases with changelog - Add script to extract a specific changelog entry from CHANGELOG.md - Add GitHub workflow to automatically create releases on tag push - Write the extracted changelog entry into the release notes The extraction is adapted to Phoenix's changelog header format ("## 1.8.9 (2026-07-07)", without a "v" prefix), unlike the phoenix_live_view equivalent which uses "## v1.2.7 ...". See phoenixframework/phoenix_live_view#4135 * Align changelog format
1 parent 12a0a0c commit bb81d88

2 files changed

Lines changed: 92 additions & 0 deletions

File tree

.github/extract-changelog.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Extract changelog for a specific version from CHANGELOG.md
4+
#
5+
# Usage: ./extract-changelog.sh <version>
6+
# Example: ./extract-changelog.sh v1.8.9
7+
8+
set -euo pipefail
9+
10+
VERSION="${1:-}"
11+
12+
if [[ -z "$VERSION" ]]; then
13+
echo "Usage: $0 <version>" >&2
14+
echo "Example: $0 v1.8.9" >&2
15+
exit 1
16+
fi
17+
18+
# Normalize version to include 'v' prefix
19+
VERSION="${VERSION#v}" # Remove 'v' if present
20+
VERSION="v${VERSION}" # Add 'v' prefix
21+
22+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
23+
CHANGELOG_PATH="${SCRIPT_DIR}/../CHANGELOG.md"
24+
25+
if [[ ! -f "$CHANGELOG_PATH" ]]; then
26+
echo "Error: CHANGELOG.md not found at $CHANGELOG_PATH" >&2
27+
exit 1
28+
fi
29+
30+
# Extract the section for the specified version
31+
# Match from "## vX.Y.Z" until the next "## v" header
32+
awk -v version="$VERSION" '
33+
BEGIN { found = 0; printing = 0 }
34+
35+
# Match the start of our target version section
36+
/^## v[0-9]/ {
37+
if (printing) {
38+
# We hit the next version, stop printing
39+
exit
40+
}
41+
# Check if this line contains our version
42+
if (index($0, "## " version " ") > 0) {
43+
found = 1
44+
printing = 1
45+
next # Skip the version header line
46+
}
47+
}
48+
49+
printing { print }
50+
51+
END {
52+
if (!found) {
53+
print "Error: Version " version " not found in changelog" > "/dev/stderr"
54+
exit 1
55+
}
56+
}
57+
' "$CHANGELOG_PATH"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Creates a GitHub Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
env:
14+
GITHUB_TOKEN: ${{ github.token }}
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
18+
19+
- name: Extract version from tag
20+
id: version
21+
run: echo "version=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
22+
23+
- name: Extract changelog for version
24+
run: bash .github/extract-changelog.sh "${{ steps.version.outputs.version }}" > release_notes.md
25+
26+
- name: Create GitHub Release
27+
run: |
28+
PRERELEASE_FLAG=""
29+
if [[ "${{ steps.version.outputs.version }}" == *-rc* ]]; then
30+
PRERELEASE_FLAG="--prerelease"
31+
fi
32+
gh release create "${{ steps.version.outputs.version }}" \
33+
--title "${{ steps.version.outputs.version }}" \
34+
--notes-file release_notes.md \
35+
$PRERELEASE_FLAG

0 commit comments

Comments
 (0)