Skip to content

Commit f8eaf14

Browse files
JacobCoffeeclaude
andauthored
ci: optimize git-cliff workflow for automated changelog (#117)
Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6da403d commit f8eaf14

File tree

3 files changed

+47
-21
lines changed

3 files changed

+47
-21
lines changed

.github/workflows/cd.yml

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,41 @@ jobs:
1515
runs-on: ubuntu-22.04
1616
permissions:
1717
contents: write
18+
pull-requests: write
1819
outputs:
19-
release_body: ${{ steps.git-cliff.outputs.content }}
20+
release_body: ${{ steps.git-cliff-latest.outputs.content }}
2021
steps:
2122
- name: Checkout
2223
uses: actions/checkout@v4
2324
with:
2425
fetch-depth: 0
2526

26-
- name: Generate a changelog
27-
uses: orhun/git-cliff-action@main
28-
id: git-cliff
27+
- name: Generate latest changelog for release
28+
uses: orhun/git-cliff-action@v4
29+
id: git-cliff-latest
2930
with:
3031
config: pyproject.toml
3132
args: -vv --latest --strip header
33+
env:
34+
GITHUB_REPO: ${{ github.repository }}
3235

3336
- name: Fetch latest main
3437
run: git fetch origin main
3538

3639
- name: Create worktree for changelog
3740
run: git worktree add worktree-changelog origin/main
3841

39-
- name: Install git-cliff
40-
uses: taiki-e/install-action@v2
42+
- name: Generate full changelog in worktree
43+
working-directory: worktree-changelog
44+
uses: orhun/git-cliff-action@v4
4145
with:
42-
tool: git-cliff
43-
44-
- name: Generate changelog in worktree
45-
run: |
46-
cd worktree-changelog
47-
git-cliff --config ../pyproject.toml -vv --latest --strip header --output docs/changelog.rst
46+
config: pyproject.toml
47+
args: -vv
48+
env:
49+
OUTPUT: docs/changelog.rst
50+
GITHUB_REPO: ${{ github.repository }}
4851

49-
- name: Commit and push changelog
52+
- name: Create PR with changelog updates
5053
working-directory: worktree-changelog
5154
run: |
5255
git config user.name 'github-actions[bot]'
@@ -55,9 +58,37 @@ jobs:
5558
if git diff --staged --quiet; then
5659
echo "No changes to commit"
5760
else
58-
git commit -m "docs: update changelog [skip ci]"
59-
git push origin HEAD:main
61+
# Create unique branch name (includes run ID to avoid collisions on reruns)
62+
BRANCH_NAME="changelog/update-$(git rev-parse --short HEAD)-${{ github.run_id }}"
63+
git checkout -b "$BRANCH_NAME"
64+
65+
git commit -m "docs: update changelog"
66+
67+
# Push and create PR
68+
git push origin "$BRANCH_NAME"
69+
gh pr create \
70+
--base main \
71+
--head "$BRANCH_NAME" \
72+
--title "docs: update changelog" \
73+
--body "Automated changelog update generated by git-cliff.
74+
75+
This PR updates the changelog with the latest commits.
76+
77+
--label "documentation" \
78+
--label "automated"
6079
fi
80+
env:
81+
GH_TOKEN: ${{ github.token }}
82+
83+
- name: Update GitHub release body
84+
if: github.event_name == 'release'
85+
run: |
86+
# Update release body with latest changelog
87+
gh release edit "${{ github.event.release.tag_name }}" \
88+
--notes "${{ steps.git-cliff-latest.outputs.content }}" \
89+
--repo ${{ github.repository }}
90+
env:
91+
GH_TOKEN: ${{ github.token }}
6192

6293
- name: Cleanup worktree
6394
if: always()

.pre-commit-config.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ repos:
2323
- id: ruff-check
2424
args: ["--fix"]
2525
- id: ruff-format
26-
- repo: https://github.com/sourcery-ai/sourcery
27-
rev: v1.40.0
28-
hooks:
29-
- id: sourcery
30-
args: [--diff=git diff HEAD, --no-summary]
31-
stages: [commit]
3226
- repo: https://github.com/codespell-project/codespell
3327
rev: v2.4.1
3428
hooks:

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ known-first-party = ["byte_common", "byte_api", "tests"]
269269
]
270270

271271
[tool.git-cliff.changelog]
272+
output = "docs/changelog.rst"
272273
header = """
273274
=========
274275
Changelog

0 commit comments

Comments
 (0)