ci: fix changelog generation in CD workflow#114
Merged
JacobCoffee merged 3 commits intomainfrom Nov 23, 2025
Merged
Conversation
- Add triggers for git tags (v*), releases, and manual dispatch - Add contents:write permission for changelog commits - Implement proper worktree-based changelog generation - Generate changelog with --output flag to write to docs/changelog.rst - Commit changes from isolated worktree to avoid branch state issues - Add [skip ci] to commit message to prevent infinite loops - Ensure proper cleanup of worktree after execution 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
Reviewer's GuideUpdates the CD GitHub Actions workflow to properly generate, write, and commit the changelog using an isolated git worktree, expanding triggers and ensuring safe, permissioned pushes to main. Sequence diagram for changelog generation using git worktree in CD workflowsequenceDiagram
participant GH as "GitHub Event (tag/release/dispatch)"
participant WF as "GitHub Actions Workflow: Continuous Deployment"
participant JOB as "Job: generate-changelog"
participant REPO as "Origin Repo (origin/main)"
participant WT as "Git Worktree: worktree-changelog"
participant CLF as "git-cliff Action"
GH->>WF: "Trigger workflow"
WF->>JOB: "Start job 'generate-changelog' with contents: write"
JOB->>REPO: "git fetch origin main"
REPO-->>JOB: "Updated refs for 'main'"
JOB->>REPO: "git worktree add worktree-changelog origin/main"
REPO-->>JOB: "Worktree directory created"
JOB->>WT: "Set working directory to 'worktree-changelog'"
JOB->>CLF: "Run git-cliff with --output docs/changelog.rst"
CLF-->>WT: "Write changelog to docs/changelog.rst"
JOB->>WT: "git config user.name and user.email"
JOB->>WT: "git add docs/changelog.rst"
JOB->>WT: "git diff --staged --quiet (check for changes)"
alt "Changes detected in changelog"
JOB->>WT: "git commit -m 'docs: update changelog [skip ci]'"
JOB->>REPO: "git push origin HEAD:main"
REPO-->>JOB: "main updated with new changelog"
else "No changes detected"
JOB-->>WF: "Skip commit and push"
end
WF->>REPO: "git worktree remove worktree-changelog (if: always())"
REPO-->>WF: "Worktree removed or ignore failure"
Flow diagram for generate-changelog job with worktree and conditional commitflowchart TD
A["Start job 'generate-changelog'"] --> B["Set permissions: contents: write"]
B --> C["Step: Checkout repository (actions/checkout)"]
C --> D["Step: Run git-cliff for release_body output (stdout)"]
D --> E["Step: git fetch origin main"]
E --> F["Step: git worktree add worktree-changelog origin/main"]
F --> G["Working-directory: worktree-changelog"]
G --> H["Run git-cliff with --output docs/changelog.rst"]
H --> I["Configure git user (github-actions[bot])"]
I --> J["git add docs/changelog.rst"]
J --> K{"git diff --staged --quiet?"}
K -- "Yes (no changes)" --> L["Log 'No changes to commit'"]
L --> N["Step: Cleanup worktree (if: always())"]
K -- "No (changes present)" --> M["git commit -m 'docs: update changelog [skip ci]' and git push origin HEAD:main"]
M --> N["Step: Cleanup worktree (if: always())"]
N --> O["End job"]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
🚅 Deployed to the byte-pr-114 environment in byte
|
Contributor
There was a problem hiding this comment.
Hey there - I've reviewed your changes and found some issues that need to be addressed.
- The
working-directorykey has no effect on steps that use an action (likeuses: orhun/git-cliff-action@main), so the changelog is still being generated in the default workspace rather than the worktree; consider runninggit-cliffvia arunstep insideworktree-changelogor restructuring so the action operates on that directory correctly. - You are referencing
orhun/git-cliff-action@main; consider pinning this to a specific tag or commit to avoid unexpected behavior from upstream changes in your CD workflow.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `working-directory` key has no effect on steps that use an action (like `uses: orhun/git-cliff-action@main`), so the changelog is still being generated in the default workspace rather than the worktree; consider running `git-cliff` via a `run` step inside `worktree-changelog` or restructuring so the action operates on that directory correctly.
- You are referencing `orhun/git-cliff-action@main`; consider pinning this to a specific tag or commit to avoid unexpected behavior from upstream changes in your CD workflow.
## Individual Comments
### Comment 1
<location> `.github/workflows/cd.yml:39-41` </location>
<code_context>
+ - name: Create worktree for changelog
+ run: git worktree add worktree-changelog origin/main
+
+ - name: Generate changelog in worktree
+ working-directory: worktree-changelog
+ uses: orhun/git-cliff-action@main
+ with:
+ config: pyproject.toml
</code_context>
<issue_to_address>
**issue (bug_risk):** The step combining `working-directory` and `uses` will be rejected by GitHub Actions.
In GitHub Actions, steps that use an action (`uses:`) cannot also set `run:`-only fields like `working-directory`. To run git-cliff from that directory, either: (a) invoke the CLI via a `run:` step, or (b) keep using the action and configure its inputs (e.g., a directory input if available) while running from the default workspace.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
- GitHub Actions doesn't allow working-directory with uses - Install git-cliff using taiki-e/install-action - Run git-cliff as CLI command in worktree directory - Fixes workflow validation error 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the changelog generation in the CD workflow to actually write changes to
docs/changelog.rstand commit them properly using git worktree strategy.Changes
v*), releases, and manual dispatchcontents: writepermission for changelog commits--output docs/changelog.rstto git-cliff command (was missing!)[skip ci]to prevent infinite loopsif: always()conditionProblem Fixed
The previous workflow generated the changelog to stdout but never wrote it to the file before attempting to commit. This resulted in empty commits or failed commits.
Benefits
Test Plan
make cipasses🤖 Generated with Claude Code
Summary by Sourcery
Fix the CD workflow to correctly generate, write, and commit the changelog during deployment events.
New Features:
Bug Fixes:
Enhancements:
CI: