Skip to content

Commit 38b953f

Browse files
authored
docs: Add CHANGELOG.md with auto-update workflow (#2690)
* feat: Add automated changelog generation and update workflow * feat: Add token parameter to GitHub Action for changelog updates * fix: add error handling for missing CHANGELOG.md in workflows * fix: also exclude docs/changelog.md from codespell * feat: Refactor CHANGELOG.md initialization to use echo for improved readability
1 parent 114feaa commit 38b953f

6 files changed

Lines changed: 2823 additions & 1 deletion

File tree

.github/workflows/changelog.yaml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Update CHANGELOG
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
update-changelog:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: write
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
ref: main
16+
token: ${{ secrets.PAT }}
17+
18+
- name: Get release info and update CHANGELOG
19+
env:
20+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
run: |
22+
set -euo pipefail
23+
24+
TAG="${{ github.event.release.tag_name }}"
25+
DATE=$(gh release view "$TAG" --json publishedAt --jq '.publishedAt | split("T")[0]')
26+
BODY=$(gh release view "$TAG" --json body --jq '.body // ""')
27+
28+
# Create new entry
29+
{
30+
echo "## [$TAG](https://github.com/${{ github.repository }}/releases/tag/$TAG) - $DATE"
31+
echo ""
32+
printf '%s\n' "$BODY"
33+
echo ""
34+
echo "---"
35+
echo ""
36+
} > new_entry.md
37+
38+
# Initialize CHANGELOG.md if it doesn't exist
39+
if [ ! -f CHANGELOG.md ]; then
40+
{
41+
echo "# Changelog"
42+
echo ""
43+
echo "All notable changes to this project are documented in this file."
44+
echo "This changelog is automatically generated from GitHub Releases."
45+
echo ""
46+
echo "---"
47+
echo ""
48+
} > CHANGELOG.md
49+
fi
50+
51+
# Split CHANGELOG.md at first "---" separator (content-based, not line-number based)
52+
# Header includes everything up to and including the first "---" line
53+
# Old entries are everything after the first "---" line
54+
awk '/^---$/ && !found {found=1; print > "header.md"; next} !found {print > "header.md"} found {print > "old_entries.md"}' CHANGELOG.md
55+
56+
# Ensure old_entries.md exists even if empty
57+
touch old_entries.md
58+
59+
# Reassemble: header + new entry + old entries
60+
cat header.md new_entry.md old_entries.md > CHANGELOG.md
61+
rm -f header.md new_entry.md old_entries.md
62+
63+
- name: Commit and push
64+
run: |
65+
git config user.name "github-actions[bot]"
66+
git config user.email "github-actions[bot]@users.noreply.github.com"
67+
git add CHANGELOG.md
68+
git diff --cached --quiet || git commit -m "docs: update CHANGELOG.md for ${{ github.event.release.tag_name }}"
69+
git push

.github/workflows/docs.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ jobs:
2121
python-version: 3.13
2222
- name: Install dependencies
2323
run: uv sync
24+
- name: Copy CHANGELOG to docs
25+
run: |
26+
if [ -f CHANGELOG.md ]; then
27+
cp CHANGELOG.md docs/changelog.md
28+
else
29+
echo "# Changelog" > docs/changelog.md
30+
echo "" >> docs/changelog.md
31+
echo "Changelog will be available after the first release." >> docs/changelog.md
32+
fi
2433
- name: build site
2534
run: zensical build --clean
2635
- name: Deploy

0 commit comments

Comments
 (0)