Skip to content

ci: fix changelog generation in CD workflow#114

Merged
JacobCoffee merged 3 commits intomainfrom
ci/fix-changelog-generation
Nov 23, 2025
Merged

ci: fix changelog generation in CD workflow#114
JacobCoffee merged 3 commits intomainfrom
ci/fix-changelog-generation

Conversation

@JacobCoffee
Copy link
Owner

@JacobCoffee JacobCoffee commented Nov 23, 2025

Summary

Fixes the changelog generation in the CD workflow to actually write changes to docs/changelog.rst and commit them properly using git worktree strategy.

Changes

  • Add multiple trigger types: git tags (v*), releases, and manual dispatch
  • Add contents: write permission for changelog commits
  • Implement proper git worktree strategy for isolated changelog generation
  • Add --output docs/changelog.rst to git-cliff command (was missing!)
  • Commit changes from worktree with [skip ci] to prevent infinite loops
  • Proper worktree cleanup with if: always() condition

Problem 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

  • Changelog actually gets written to file before committing
  • Isolated worktree prevents branch state issues
  • Automatic changelog updates on releases/tags
  • No more manual changelog generation needed

Test Plan

  • Local make ci passes
  • GitHub Actions workflow succeeds
  • Manual trigger test (workflow_dispatch)

🤖 Generated with Claude Code

Summary by Sourcery

Fix the CD workflow to correctly generate, write, and commit the changelog during deployment events.

New Features:

  • Trigger the CD workflow on version tags, published releases, and manual dispatch events.

Bug Fixes:

  • Ensure the changelog is written to docs/changelog.rst before committing, preventing empty or failed changelog commits.
  • Prevent CI feedback loops by tagging automated changelog commits with a skip-ci marker.

Enhancements:

  • Use a dedicated git worktree for isolated changelog generation and commits on the main branch, including proper cleanup.
  • Grant the workflow explicit contents: write permissions to allow pushing changelog updates from CI.

CI:

  • Update the CD GitHub Actions workflow to handle changelog generation, commit, and push via a worktree-based strategy.

- 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>
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Nov 23, 2025

Reviewer's Guide

Updates 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 workflow

sequenceDiagram
  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"
Loading

Flow diagram for generate-changelog job with worktree and conditional commit

flowchart 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"]
Loading

File-Level Changes

Change Details Files
Expand CD workflow triggers and permissions to support automated changelog updates on releases and tags.
  • Add push tag trigger for tags matching v*
  • Add release trigger for published releases
  • Retain manual workflow_dispatch trigger
  • Grant contents: write permission to the generate-changelog job so it can push commits
.github/workflows/cd.yml
Rework changelog generation to use a dedicated git worktree and write directly to docs/changelog.rst.
  • Keep initial git-cliff run for release_body output but without file writes
  • Fetch latest main branch and create worktree-changelog worktree tracking origin/main
  • Run git-cliff in the worktree with --output docs/changelog.rst so the changelog file is actually written
.github/workflows/cd.yml
Adjust commit/push logic and add cleanup to make changelog commits safe and idempotent.
  • Configure git user in the worktree before committing
  • Stage docs/changelog.rst and commit only when there are actual staged changes
  • Include [skip ci] in the commit message to avoid triggering CI loops
  • Push changes from the worktree to origin HEAD:main instead of using an inline token URL
  • Always attempt to remove the worktree in a final cleanup step using if: always()
.github/workflows/cd.yml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@railway-app
Copy link

railway-app bot commented Nov 23, 2025

🚅 Deployed to the byte-pr-114 environment in byte

Service Status Web Updated (UTC)
byte ◻️ Removed (View Logs) Nov 23, 2025 at 4:46 am

@railway-app railway-app bot temporarily deployed to byte (byte / byte-pr-114) November 23, 2025 04:43 Destroyed
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and found some issues that need to be addressed.

  • 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.
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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@railway-app railway-app bot temporarily deployed to byte (byte / byte-pr-114) November 23, 2025 04:44 Destroyed
- 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>
@railway-app railway-app bot temporarily deployed to byte (byte / byte-pr-114) November 23, 2025 04:45 Destroyed
@JacobCoffee JacobCoffee merged commit 16959f5 into main Nov 23, 2025
4 checks passed
@JacobCoffee JacobCoffee deleted the ci/fix-changelog-generation branch November 23, 2025 04:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant