Skip to content

Commit 32c1bc5

Browse files
committed
feat: update changelog generation and add pre-commit hook for automatic updates
1 parent 07f0d63 commit 32c1bc5

File tree

3 files changed

+46
-33
lines changed

3 files changed

+46
-33
lines changed

.githooks/pre-commit

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
# filepath: /workspaces/codebaseinterface/.githooks/pre-commit
3+
4+
# Pre-commit hook to generate changelog using git-cliff
5+
# This ensures the changelog is updated and included in the current commit
6+
7+
set -e
8+
9+
# Check if git-cliff is available
10+
if ! command -v git-cliff &> /dev/null; then
11+
echo "Warning: git-cliff not found. Skipping changelog generation."
12+
exit 0
13+
fi
14+
15+
# Check if cliff.toml exists
16+
if [ ! -f "cliff.toml" ]; then
17+
echo "Warning: cliff.toml not found. Skipping changelog generation."
18+
exit 0
19+
fi
20+
21+
echo "Updating changelog with new entries..."
22+
23+
# Check if CHANGELOG.md exists
24+
if [ -f "CHANGELOG.md" ]; then
25+
# Changelog exists, only add new unreleased entries
26+
echo "Existing changelog found. Adding new unreleased entries..."
27+
git-cliff --unreleased --prepend CHANGELOG.md
28+
else
29+
# No changelog exists, create it from scratch
30+
echo "No existing changelog found. Creating new changelog..."
31+
git-cliff --output CHANGELOG.md
32+
fi
33+
34+
# Check if changelog was modified
35+
if git diff --quiet CHANGELOG.md; then
36+
echo "Changelog is up to date."
37+
else
38+
echo "Changelog updated. Adding to commit..."
39+
# Stage the updated changelog
40+
git add CHANGELOG.md
41+
echo "Changelog has been updated and staged for this commit."
42+
fi
43+
44+
exit 0

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- Add commit message validation script for Conventional Commits _(2025-10-16)_
2525
- Enhance changelog generation and update Taskfile with new tasks _(2025-10-16)_
2626
- Enhance changelog generation and update Taskfile with new hooks and tasks _(2025-10-16)_
27+
- Enhance changelog generation and update Taskfile with new hooks _(2025-10-16)_
2728

2829
### 🐛 Bug Fixes
2930

Taskfile.yml

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -43,36 +43,4 @@ tasks:
4343
changelog:update:
4444
desc: Update changelog with new commits since last tag
4545
cmds:
46-
- git cliff --latest --output CHANGELOG.md --prepend
47-
48-
changelog:setup-hook:
49-
desc: Setup git hook to automatically update and commit changelog
50-
cmds:
51-
- echo '#!/bin/bash' > .git/hooks/post-commit
52-
- echo 'git cliff --output CHANGELOG.md' >> .git/hooks/post-commit
53-
- echo 'git add CHANGELOG.md' >> .git/hooks/post-commit
54-
- echo 'git diff --cached --quiet || git commit --amend --no-edit' >> .git/hooks/post-commit
55-
- chmod +x .git/hooks/post-commit
56-
- echo "Git hook installed! Changelog will update and amend automatically on each commit."
57-
58-
changelog:setup-pre-commit:
59-
desc: Setup pre-commit hook to update changelog before committing
60-
cmds:
61-
- echo '#!/bin/bash' > .git/hooks/pre-commit
62-
- echo 'git cliff --output CHANGELOG.md' >> .git/hooks/pre-commit
63-
- echo 'git add CHANGELOG.md' >> .git/hooks/pre-commit
64-
- chmod +x .git/hooks/pre-commit
65-
- echo "Pre-commit hook installed! Changelog will update automatically before each commit."
66-
67-
changelog:remove-hooks:
68-
desc: Remove changelog git hooks
69-
cmds:
70-
- rm -f .git/hooks/post-commit .git/hooks/pre-commit
71-
- echo "Git hooks removed."
72-
73-
changelog:commit:
74-
desc: Update changelog and commit it
75-
cmds:
76-
- git cliff --output CHANGELOG.md
77-
- git add CHANGELOG.md
78-
- git commit -m "docs: update changelog" || echo "No changes to commit"
46+
- git cliff --latest --output CHANGELOG.md --prepend

0 commit comments

Comments
 (0)