Skip to content

chore: remove pre-commit hook for changelog generation #2

chore: remove pre-commit hook for changelog generation

chore: remove pre-commit hook for changelog generation #2

Workflow file for this run

name: Generate Changelog
on:
push:
branches: [main]
workflow_dispatch: # Allow manual triggering
jobs:
changelog:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch full history for changelog generation
token: ${{ secrets.GITHUB_TOKEN }}
- name: Install git-cliff
uses: taiki-e/install-action@v2
with:
tool: git-cliff
- name: Check for changes since last changelog update
id: check_changes
run: |
# Get the last commit that modified CHANGELOG.md
LAST_CHANGELOG_COMMIT=$(git log -1 --format="%H" -- CHANGELOG.md 2>/dev/null || echo "")
if [ -z "$LAST_CHANGELOG_COMMIT" ]; then
echo "No previous changelog found, generating full changelog"
echo "has_changes=true" >> $GITHUB_OUTPUT
else
# Check if there are commits since the last changelog update
COMMITS_SINCE=$(git rev-list --count ${LAST_CHANGELOG_COMMIT}..HEAD)
if [ "$COMMITS_SINCE" -gt 1 ]; then
echo "Found $COMMITS_SINCE commits since last changelog update"
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "No new commits to add to changelog"
echo "has_changes=false" >> $GITHUB_OUTPUT
fi
fi
- name: Generate changelog
if: steps.check_changes.outputs.has_changes == 'true'
run: |
echo "Generating changelog..."
git-cliff --output CHANGELOG.md
- name: Check if changelog was updated
if: steps.check_changes.outputs.has_changes == 'true'
id: check_diff
run: |
if git diff --quiet CHANGELOG.md; then
echo "No changes to changelog"
echo "changelog_updated=false" >> $GITHUB_OUTPUT
else
echo "Changelog was updated"
echo "changelog_updated=true" >> $GITHUB_OUTPUT
fi
- name: Commit and push changelog
if: steps.check_changes.outputs.has_changes == 'true' && steps.check_diff.outputs.changelog_updated == 'true'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add CHANGELOG.md
git commit -m "docs: update changelog [skip ci]"
git push