Skip to content

ci: start notes at the first release - #225

Merged
uniqueg merged 6 commits into
devfrom
ci/221-first-release-notes
Oct 24, 2026
Merged

uniqueg merged 6 commits into
devfrom
ci/221-first-release-notes

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Summary

Without a previous published release, GitHub's generate-notes API picks an older tag itself, even one that has no release. That is why the generated list of v0.4.0 started at the tag v0.3.0. For a first release, the "Create release" step now builds the generated notes itself:

  • scripts/release_notes.py first <tag> --repository <owner/repo> --pulls <file> --commits <file> prints notes in GitHub's format: "What's Changed", "New Contributors" and **Full Changelog**: …/commits/<tag>. The inputs are the closed pull requests (gh api --paginate --slurp "repos/…/pulls?state=closed&per_page=100") and the release's commits (git rev-list HEAD at the release commit).
  • It lists every merged pull request whose merge commit is in the history of the release commit, in merge order. New contributors are authors whose first merged pull request is among them. Titles are kept on one line. Pull requests without a merge commit are skipped, so they can't fail the release after the image is published.
  • With a previous published release, the step works as before (previous_tag_name). The job gets pull-requests: read.
  • body() now splits generated notes only at line breaks (LF, CRLF, CR). Before, it also split at other separators such as U+2028, which would let a pull request title add a heading.
  • docs/development.md describes how a first release works and how to preview its notes.

Builds on the draft → upload → publish step of #219.

Closes #221

How it was verified

Declined review findings

  • An end-to-end test of the workflow step: that step only runs at a real first release. The Python parts are tested, and the docs give the commands to preview the notes locally.

  • First contributions ignore merged pull requests without a merge commit: this is a rare edge case. The approximation is accepted.

  • Sourcery: Markdown in titles (not escaped): GitHub's generated notes keep titles as they are too, and titles stay on one line.

  • Sourcery: concurrent releases repeating notes: the previous-release logic is unchanged by this PR; releases wait for the approval of the release environment one at a time.

  • Sourcery: ties of merged_at: the API has no finer merge order; the number is a stable tie-breaker.

  • Fixed from Sourcery: pull requests repeated across pages are listed once.

Open questions

None (whether to correct the published v0.4.0 notes is outside this PR).

🤖 Generated with Claude Code

uniqueg and others added 5 commits October 24, 2026 05:15
Without a previous published release, GitHub's generate-notes API
starts at an older tag of its choice, even one without a release (as
for v0.4.0, whose list started at v0.3.0). For a first release, the
workflow now lists all merged pull requests in the history of the
release commit itself, in GitHub's format, with
"scripts/release_notes.py first"; the job may read pull requests for
it.

Closes #221

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Skip merged pull requests without a merge commit, so that they can't
  fail the release after the image is published.
- Keep titles on one line, and split generated notes at line breaks
  only, so that a title can't add a heading to the release body.
- Pin the output of `first` in its CLI test, test non-UTF-8 input, and
  document the inputs, the permission and how to preview the notes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The release workflow now handles a first release by collecting closed pull requests and the release commit history, then using a new Python command to produce GitHub-format notes from merged pull requests reachable from that release. Existing releases continue using GitHub's generated-notes API, while parsing, documentation, permissions, and comprehensive tests are updated to cover the new path and edge cases.

Sequence diagram for first-release note generation

sequenceDiagram
    participant Workflow as Release workflow
    participant GitHub as GitHub API
    participant Git as Git history
    participant Script as release_notes.py
    participant Release as GitHub release

    Workflow->>GitHub: List closed pull requests
    GitHub-->>Workflow: Paginated pull request pages
    Workflow->>Git: git rev-list HEAD
    Git-->>Workflow: Release commit SHAs
    Workflow->>Script: first tag --repository --pulls --commits
    Script->>Script: merged_pull_requests(pages)
    Script->>Script: first_release_notes(tag, repository, pulls, commits)
    Script-->>Workflow: GitHub-format generated notes
    Workflow->>Release: Create release with generated notes
Loading

Flow diagram for first versus subsequent release notes

flowchart TD
    Start[Create release] --> Previous{Previous published release?}
    Previous -->|Yes| API[GitHub generate-notes API with previous_tag_name]
    Previous -->|No| Inputs[Collect closed pull requests and git rev-list HEAD]
    Inputs --> First[release_notes.py first]
    First --> Filter[Keep merged pull requests in release history]
    Filter --> Notes[Build changed, new contributors, and full changelog sections]
    API --> Body[Combine generated notes with curated notes]
    Notes --> Body
    Body --> Publish[Publish release]
Loading

File-Level Changes

Change Details Files
Generate first-release notes from repository history instead of relying on GitHub's tag selection.
  • Fetch all closed pull requests and release-commit history in the workflow.
  • Add a first CLI command that filters merged pull requests by merge-commit ancestry, orders them by merge time, derives new contributors, and emits GitHub-compatible sections.
  • Skip pull requests without merge commits and normalize titles to one line.
  • Retain the existing generate-notes API path when a previous published release exists.
  • Grant the release job read access to pull requests.
.github/workflows/release.yaml
scripts/release_notes.py
Make generated-note parsing robust against nonstandard Unicode separators.
  • Normalize CRLF and CR line endings while splitting only on actual line breaks.
  • Prevent pull-request titles containing separators such as U+2028 from creating release-note headings.
scripts/release_notes.py
Document and test first-release note generation and formatting behavior.
  • Document local preview commands, API inputs, permissions, and first-release behavior.
  • Add coverage for note ordering, contributor detection, malformed API data, CLI output/errors, title normalization, and line-ending parsing.
docs/development.md
tests/test_release_notes.py

Assessment against linked issues

Issue Objective Addressed Explanation
#221 For a first release with no previously published release, generate notes from all merged pull requests in the release commit’s history, rather than letting GitHub choose an older tag; format the list, new contributors, and full changelog line as GitHub does. ✅
#221 Keep using GitHub’s generate-notes API with previous_tag_name when a previous published release exists. ✅
#221 Test the first-release pull request list, including ordering, contributor detection, and excluding pull requests outside the release commit’s history, and document how to preview the notes. ✅

Possibly linked issues


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

@codecov

codecov Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (0894160) to head (ab67135).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #225   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           16        16           
  Lines         1296      1362   +66     
=========================================
+ Hits          1296      1362   +66     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review October 24, 2026 03:42

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 4 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="scripts/release_notes.py" line_range="531" />
<code_context>
+        lines.append(WHATS_CHANGED)
+        lines += [
+            f"* {pull.title} by @{pull.author} in {pull.url}" for pull in released
+        ]
+        new = [pull for pull in released if first[pull.author] == pull.number]
+        if new:
</code_context>
<issue_to_address>
**Pull request titles inject release links**

When a merged PR author sets its title to Markdown containing a misleading link or other formatted content, the title is whitespace-normalized but not Markdown-escaped before `first_release_notes` inserts it into the release body, so readers can be shown attacker-controlled links or misleading release-note text as project-published content.

Escape Markdown syntax in PR titles before inserting them into generated notes, or otherwise render titles as plain text.
</issue_to_address>

### Comment 2
<location path=".github/workflows/release.yaml" line_range="464-472" />
<code_context>
+              gh api "repos/${GH_REPO}/releases/generate-notes" \
+                  -f "tag_name=${TAG}" -f "previous_tag_name=${PREVIOUS}" \
+                  --jq .body > "${notes_file}"
+          else
+              pulls="$(mktemp)"
+              commits="$(mktemp)"
+              gh api --paginate --slurp \
+                  "repos/${GH_REPO}/pulls?state=closed&per_page=100" > "${pulls}"
+              git rev-list HEAD > "${commits}"
+              python scripts/release_notes.py first "${TAG}" \
+                  --repository "${GH_REPO}" --pulls "${pulls}" \
+                  --commits "${commits}" > "${notes_file}"
           fi
-          notes_file="$(mktemp)"
</code_context>
<issue_to_address>
**Concurrent releases repeat earlier notes**

When two release runs for different tags determine the previous release before either has published, two different tag runs can both read an empty published-release list before either publishes. Since concurrency is keyed by ref, both take this first-release branch and include the full history, so the later release repeats pull requests already listed in the earlier release.

Serialize release publication across tags, or coordinate the previous-release check and notes generation so concurrent runs cannot both use the first-release history.
</issue_to_address>

### Comment 3
<location path="scripts/release_notes.py" line_range="521" />
<code_context>
+        The notes, as the `body` of a `generate-notes` response.
+    """
+    history = set(commits)
+    ordered = sorted(pulls, key=lambda pull: (pull.merged_at, pull.number))
+    first: dict[str, int] = {}
+    for pull in ordered:
</code_context>
<issue_to_address>
**Pull requests appear in wrong merge order**

When two pull requests share a `merged_at` timestamp and their merge order differs from their pull-request-number order, `ordered` sorts tied pulls by `pull.number`, so `first_release_notes` lists them out of merge order and can choose the wrong first-contribution entry for an author.

`ordered` must use the actual merge sequence to break `merged_at` ties instead of `pull.number`.
</issue_to_address>

### Comment 4
<location path=".github/workflows/release.yaml" line_range="467-469" />
<code_context>
+          else
+              pulls="$(mktemp)"
+              commits="$(mktemp)"
+              gh api --paginate --slurp \
+                  "repos/${GH_REPO}/pulls?state=closed&per_page=100" > "${pulls}"
+              git rev-list HEAD > "${commits}"
+              python scripts/release_notes.py first "${TAG}" \
+                  --repository "${GH_REPO}" --pulls "${pulls}" \
</code_context>
<issue_to_address>
**Pagination repeats pull requests**

When the closed-pull-request list changes while a first-release run is fetching multiple pages, a closed pull request entering the paginated result between page requests shifts the page boundaries. `merged_pull_requests` keeps repeated records, so `first_release_notes` emits the affected pull request more than once in the release notes.

Deduplicate paginated results by pull-request number and reconcile the pages against a stable complete result before generating notes.

Also at `scripts/release_notes.py:468`.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 4 findings to address first, and the release job gains permission to read closed pull requests, and its first-release notes are published from that data. If the commit matching or PR selection is wrong, readers may see an incorrect public release note; the release text can be edited, but that cannot undo what was already seen.

Blocking findings: scripts/release_notes.py:531, .github/workflows/release.yaml:472, scripts/release_notes.py:521, .github/workflows/release.yaml:469


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread scripts/release_notes.py Resolved
Comment thread .github/workflows/release.yaml Resolved
Comment thread scripts/release_notes.py Resolved
Comment thread .github/workflows/release.yaml Resolved
Pages of closed pull requests fetched while pull requests are closed
may repeat one; list each pull request once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit e3a3b26 into dev Oct 24, 2026
19 checks passed
@uniqueg
uniqueg deleted the ci/221-first-release-notes branch October 24, 2026 03:59
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.

ci: start notes at the first release

1 participant