Skip to content

feat: add a shared publish-release action - #67

Merged
uniqueg merged 3 commits into
mainfrom
feat/66-publish-release
Nov 9, 2026
Merged

uniqueg merged 3 commits into
mainfrom
feat/66-publish-release

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds the shared composite action actions/publish-release, so that every release workflow in the organisation creates its GitHub release itself, in the organisation's release notes format:

  1. the curated notes from a file in the calling repository (intro + grouped sections), checked for the format;
  2. ## Commits: GitHub's generated notes (releases/generate-notes), verbatim with "New Contributors", without ## What's Changed;
  3. GitHub's **Full Changelog** line last.

Details:

  • check-only: "true" for the prepare job (needs only contents: read): checks the notes, the pre-release policy, that the tag and an explicit previous-tag exist, and that no release of the tag exists, so that a release fails before anything is published.
  • Pre-release policy auto (default): pre-release below 1.0.0 and for a/b/rc versions; true/false override it. Pre-releases are never the latest release; a final release is the latest unless a higher published release exists.
  • Previous tag (default): the highest lower version with a published release, else the highest lower version tag (tesk-api has tags v1.0, v1.1 but no GitHub releases, so its v1.2.0 starts at v1.1). A final release skips its own pre-releases, so 1.2.0 starts at 1.1.0, not at 1.2.0rc1.
  • Existing releases: a draft fails ("delete it and re-run"); a published release fails, unless it is the one an earlier attempt created (body starts with the curated notes, same title and pre-release flag), so that "Re-run failed jobs" after an unreported success passes.
  • gh release create --verify-tag; only the job's GITHUB_TOKEN; inputs reach the script through the environment only.
  • The checker of the curated notes is ported from FOCA's scripts/release_notes.py (without its FOCA-specific moving-link check).
  • The script (publish.py) uses the Python standard library and gh only; it is tested with unittest (tests/publish-release/test.sh), like the other actions' tests run from CI's test job.

Closes #66

Verification

  • bash tests/publish-release/test.sh: 41 tests pass (many with sub-tests), including an end-to-end run of publish.py publish against a recording stub gh that checks the real command lines and flags. Branch coverage of publish.py: 99% (only the __main__ guard is not traced).
  • ruff check (E, F, W, B, UP, D, ANN, S, SIM, RUF, PL), ruff format --check and mypy --strict on the new Python files: clean (run by hand: this repository's pre-commit has no Python hooks yet; adding ruff there is a possible follow-up).
  • pre-commit run --all-files: all hooks pass (gitleaks-all not run locally, as it scans untracked caches).
  • Live check-only runs against the API: elixir-cloud-aai/.github v1.0.0 fails with "exists already", v0.0.0 with "doesn't exist on GitHub"; elixir-cloud-aai/tesk-api v1.1 passes.
  • CI: all checks pass (Lint, Test with the new steps against this repository's API, CodeQL, CI passed).

Lane

Full review lane (release workflow building block): adversarial-reviewer and quality-reviewer, two rounds. Fixed: committed bytecode (now .gitignore), check-only covering the settings and repository, the previous tag of a final release, check-only values other than true/false, robust re-runs (CRLF, changed generated part, title and flag), case-insensitive versions, CI asserting each expected error and not depending on a fork's releases, more tests and docs.

Sourcery (13 findings): fixed in 7dc7b36 the commit input (tag must point to the built commit), previous tag must be lower and must still exist, existing release checked before generate-notes, relative HTML href/src and TODO/FIXME rejected, concurrency group recommended in the README.

Declined review findings

  • Sourcery: links checked inside code blocks/comments (kept on purpose: the notes are published as written); # vX.Y.Z title line (callers' notes have none; the title comes from the tag); concurrent publish of the same tag (callers run one run per tag); no ## Commits without changes and unexpected generated notes kept with a warning (on purpose, so a release doesn't fail after its artefacts are out); a matching existing release passes (on purpose: idempotent re-run of the failed job; prepare fails on any existing release); CI action step only checks wiring (the preceding step asserts each error message). Each answered in its thread.
  • Accepted limitation: with contents: read, check-only can't see drafts (documented); publish still fails on a draft before generating notes.

Notes for callers

  • Callers pin the commit of a release of this repository; the action needs a release (v1.1.0, minor: new action) before repositories can pin it as RELEASING.md describes.

🤖 Generated with Claude Code

uniqueg and others added 2 commits November 9, 2026 14:20
Add the composite action actions/publish-release, which creates the
GitHub release of a tag in the organisation's release notes format: the
curated notes from a file in the calling repository, then GitHub's
generated notes under "## Commits" (without "## What's Changed"), and
the "**Full Changelog**" line last. In check-only mode it checks that
the release can be created (notes, settings, tags, existing releases),
for the prepare job of a release workflow.

Releases are pre-releases below 1.0.0 and for a/b/rc versions (policy
"auto"); the previous tag is the highest lower published release, else
the highest lower version tag, for a final release without its own
pre-releases. A draft of the tag, or a published release with another
body, fails; a re-run after a creation that succeeded passes. The script uses the Python
standard library and gh only, and is tested with unittest; CI runs the
tests and the action in check-only mode.

Closes #66

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Treat an existing published release as created by an earlier attempt
when its body starts with the curated notes and its title and
pre-release flag match, so that a re-run of the publish job also passes
when the generated part differs or GitHub returns CRLF line endings.

CI now runs the script in check-only mode against this repository's
releases and asserts each expected error (bad notes, released tag,
missing tag); the action's own run is limited to this repository, as
forks have other releases. More check-only cases are tested, and the
README says to re-run only the failed jobs.

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

sourcery-ai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Define the reusable action’s inputs, output, permissions-facing environment wiring, and invocation contract.

  • actions/publish-release/action.yml L1-81

Implementation

Implement release-note validation, version and tag selection, safe existing-release handling, GitHub CLI calls, and action outputs.

  • actions/publish-release/publish.py L1-887

Configuration

Add CI coverage for the script and live check-only behaviour, including action wiring against this repository.

  • .github/workflows/ci.yml L125-182

Ignore generated Python artefacts.

  • .gitignore L1-3

Documentation

Document the action’s release-note format, usage, inputs, outputs, behaviour, and caller requirements.

  • actions/publish-release/README.md L1-154

Add the action to the repository catalogue and describe how to run its tests locally.

  • README.md L114-116, L133-135, L145

Tests

Exercise note validation, body generation, version selection, publishing, check-only mode, and the script’s real CLI calls against a stub GitHub CLI.

  • tests/publish-release/test.sh L1-8
  • tests/publish-release/test_publish.py L1-967

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

@uniqueg
uniqueg marked this pull request as ready for review November 9, 2026 13:30

@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 13 issues

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

## Individual Comments

### Comment 1
<location path="actions/publish-release/publish.py" line_range="769" />
<code_context>
+                "create",
+                settings.tag,
+                "--verify-tag",
+                "--title",
+                settings.title or settings.tag,
+                "--notes-file",
</code_context>
<issue_to_address>
**Release points to changed tag**

When a caller permits tag updates and the tag is moved after its workflow checks out the commit but before this action creates the release, if a caller's tag is moved after checkout or artifact building, `--verify-tag` only requires the tag to exist; it does not ensure it still points to the built commit. The release can therefore point to different source than the published artifacts. Require immutable release tags or verify the expected commit under an immutability guarantee.

Require immutable release tags in callers, or pass and verify the expected commit SHA before creating the release.
</issue_to_address>

### Comment 2
<location path="actions/publish-release/publish.py" line_range="757-774" />
<code_context>
+            " or pre-release flag: releases are not changed or replaced, so"
+            " release the next version"
+        )
+    latest = is_latest(settings.tag, prerelease, releases)
+    with tempfile.NamedTemporaryFile(
+        "w", encoding="utf-8", suffix=".md", delete=False
+    ) as file:
+        file.write(text)
+    try:
+        url = gh(
+            [
+                "release",
+                "create",
+                settings.tag,
+                "--verify-tag",
+                "--title",
+                settings.title or settings.tag,
+                "--notes-file",
+                file.name,
+                f"--prerelease={str(prerelease).lower()}",
+                *([] if latest is None else [f"--latest={str(latest).lower()}"]),
+            ]
+        )
</code_context>
<issue_to_address>
**Older release becomes latest**

When two final-version release jobs for different tags read the releases list before either creates its release, `is_latest` uses the stale snapshot for both jobs, so both pass `--latest=true`; if the higher version is created first and the lower version last, GitHub marks the lower version as latest.

Serialize release publication per repository or coordinate latest selection against the current releases.
</issue_to_address>

### Comment 3
<location path="actions/publish-release/publish.py" line_range="509" />
<code_context>
+        ]
+        return max(lower)[1] if lower else None
+
+    published = [str(r["tag_name"]) for r in releases if not r.get("draft")]
+    return highest(published) or highest(tags)
+
</code_context>
<issue_to_address>
**Deleted prior tag breaks publishing**

When a lower published release remains in the releases API after its associated tag has been deleted, `previous_release` can select that missing tag, and check-only returns before selecting or validating it; `generate-notes` then receives the stale tag and fails after artifacts are published.

Exclude published releases whose tags are absent from the fetched tags, and validate the selected previous tag before check-only returns.

Also at `actions/publish-release/publish.py:510`, `actions/publish-release/publish.py:731-733`.
</issue_to_address>

### Comment 4
<location path="actions/publish-release/publish.py" line_range="766" />
<code_context>
+        url = gh(
+            [
+                "release",
+                "create",
+                settings.tag,
+                "--verify-tag",
</code_context>
<issue_to_address>
**Concurrent publish reports failure**

When two publish jobs for the same tag both check for an existing release before either creates it, `gh release create` fails in the losing job after the other job creates the release, and the job exits without checking whether that release matches its settings; the workflow reports failure despite the matching release existing.

On a create conflict, re-fetch the release and accept it if `_is_ours` matches.

Also at `actions/publish-release/publish.py:707`, `actions/publish-release/publish.py:764-765`.
</issue_to_address>

### Comment 5
<location path="actions/publish-release/publish.py" line_range="739" />
<code_context>
+    if previous:
+        args += ["-f", f"previous_tag_name={previous}"]
+    generated = gh([*args, "--jq", ".body"])
+    text, warnings = body(curated, generated)
+    for warning in warnings:
+        print(f"::warning::{warning}; kept as they are", file=sys.stderr)
</code_context>
<issue_to_address>
**Matching release reruns fail**

When a rerun finds a matching published release but the generate-notes API call fails, `publish` calls `generate-notes` before checking whether the existing release matches via `_is_ours`, so the API error makes the rerun fail even though the release was already created successfully.

Check whether the existing release matches before calling `generate-notes`.

Also at `actions/publish-release/publish.py:738`.
</issue_to_address>

### Comment 6
<location path="actions/publish-release/publish.py" line_range="375" />
<code_context>
+    lines = markdown.removeprefix("\ufeff").splitlines()
+    findings = _Checker().run(lines)
+    for number, line in enumerate(lines, start=1):
+        if RELATIVE.search(line):
+            findings.append(Finding(number, RELATIVE_LINK))
+    return sorted(findings, key=lambda finding: finding.line)
</code_context>
<issue_to_address>
**Link examples block publishing**

When curated notes contain relative-link syntax inside a fenced code block or an HTML comment, `check` scans those source lines with `RELATIVE` even though GitHub does not render them as links, so it diagnoses valid notes as broken and blocks publishing.

Skip fenced code blocks and HTML comments when checking for relative links.
</issue_to_address>

### Comment 7
<location path="actions/publish-release/publish.py" line_range="373" />
<code_context>
+        line.
+    """
+    lines = markdown.removeprefix("\ufeff").splitlines()
+    findings = _Checker().run(lines)
+    for number, line in enumerate(lines, start=1):
+        if RELATIVE.search(line):
</code_context>
<issue_to_address>
**Unfinished notes get published**

When the curated notes contain `TODO` in their intro or a bullet, `check` does not reject `TODO`, so `read_notes` accepts unfinished notes and `publish` includes them in the public release body.

Make `check` report TODO occurrences so `read_notes` blocks publication.
</issue_to_address>

### Comment 8
<location path="actions/publish-release/publish.py" line_range="167" />
<code_context>
+        A finding unless the heading is a section of `SECTIONS` after `last`.
+    """
+    allowed = ", ".join(SECTIONS)
+    if level != 2:
+        return Finding(
+            number,
</code_context>
<issue_to_address>
**Existing notes fail validation**

When a caller supplies curated notes in the repository's existing `docs/releases` format, beginning with `# vX.Y.Z`, `_heading_finding` treats the required level-1 title as an illegal heading, so `read_notes` aborts the release check instead of stripping the title as the existing release workflow does.

Accept and strip a matching release-title heading before checking and publishing the curated notes.
</issue_to_address>

### Comment 9
<location path="actions/publish-release/publish.py" line_range="88-90" />
<code_context>
+# resolves against the release page, not the docs
+_NO_SCHEME = r"(?:<|(?!<))(?![a-z][a-z0-9+.-]*:)"
+RELATIVE = re.compile(
+    rf"\]\([ \t]*{_NO_SCHEME}[^)\s<>]"
+    rf"|^ {{0,3}}\[[^\]]+\]:[ \t]*{_NO_SCHEME}[^\s<>]",
+    re.ASCII | re.IGNORECASE,
+)
+RELATIVE_LINK = (
</code_context>
<issue_to_address>
**HTML links remain relative**

When curated notes use a relative URL in an HTML link, `RELATIVE` recognizes Markdown inline links and reference definitions but not HTML `href` attributes, so `<a href="../guide.md">Guide</a>` passes validation and is published with a link that does not resolve to the docs.

Detect relative URLs in HTML link attributes as well, or reject raw HTML links that cannot be validated.
</issue_to_address>

### Comment 10
<location path="actions/publish-release/publish.py" line_range="728-730" />
<code_context>
+        ]
+    ).split()
+    for name, kind in ((settings.tag, "tag"), (settings.previous, "previous tag")):
+        if name and name not in tags:
+            raise ReleaseError(f"The {kind} {name} doesn't exist on GitHub")
+    if settings.check_only:
+        # Generating notes needs `contents: write`, which `prepare` lacks
+        return curated, ""
</code_context>
<issue_to_address>
**Release changelog omits commits**

When the configured `previous-tag` equals the release tag, gitHub receives the release tag as its own `previous_tag_name`, so the generated notes have no intervening commits; `check-only` passes and the published release has an empty generated changelog.

Reject a `previous-tag` equal to the release tag, and validate ordering when both tags are versions.
</issue_to_address>

### Comment 11
<location path="actions/publish-release/publish.py" line_range="405-413" />
<code_context>
+    # Also after a comment (e.g., with a configuration in `.github/release.yml`)
+    if WHATS_CHANGED in lines:
+        lines.remove(WHATS_CHANGED)
+    if not lines or not lines[-1].startswith(f"{FULL_CHANGELOG}: "):
+        warnings.append(f"Generated notes don't end with a '{FULL_CHANGELOG}: ' line")
+        changes, last = "\n".join(lines).strip(), []
+    else:
+        changes, last = "\n".join(lines[:-1]).strip(), [lines[-1]]
+    parts = [curated.removeprefix("\ufeff").strip()]
+    if changes:
+        parts.append(f"## {COMMITS}\n\n{changes}")
+    return "\n\n".join(parts + last) + "\n", warnings
+
+
</code_context>
<issue_to_address>
**Generated sections can be omitted**

The issue requires the generated `## Commits` section and final `**Full Changelog**` line. This code omits the section when there are no changes and, when the generated response lacks the expected final line, warns but still publishes without it.
</issue_to_address>

### Comment 12
<location path="actions/publish-release/publish.py" line_range="743-752" />
<code_context>
+    for warning in warnings:
+        print(f"::warning::{warning}; kept as they are", file=sys.stderr)
+    if existing:
+        release = existing[0]
+        if _is_ours(release, settings, curated, prerelease):
+            print(
+                f"::notice::The release {settings.tag} exists already, with these"
+                " curated notes, title and pre-release flag (created by an"
+                " earlier attempt)",
+                file=sys.stderr,
+            )
+            return str(release.get("body") or ""), str(release.get("html_url") or "")
+        raise ReleaseError(
+            f"The release {settings.tag} exists already, with other notes, title"
+            " or pre-release flag: releases are not changed or replaced, so"
</code_context>
<issue_to_address>
**Matching existing release passes**

The issue asks for an existing release to fail clearly. The action instead treats a matching published release as a successful earlier attempt and returns success, although drafts and conflicting published releases do fail.
</issue_to_address>

### Comment 13
<location path=".github/workflows/ci.yml" line_range="179-182" />
<code_context>
+        env:
+          OUTCOME: ${{ steps.released-tag.outcome }}
+        run: |
+          if [[ "${OUTCOME}" != failure ]]; then
+            echo "::error::Expected the check of the released tag to fail, got ${OUTCOME}"
+            exit 1
+          fi
       # scan-image: a clean image passes and yields the full report; an image
       # with fixable critical and high findings fails. No upload to code
</code_context>
<issue_to_address>
**Any action failure passes**

When the action fails before checking whether the tag's release already exists, the `Expect the check of the released tag to fail` step checks only `steps.released-tag.outcome`; an action that fails for an unrelated reason, including broken input wiring, still passes this test without proving that the existing release was detected.

Capture the action's error output and assert that it reports the existing release, or add an equivalent observable assertion for the rejection reason.
</issue_to_address>

Linked issues

#66 feat: add a shared publish-release action · 5 of 7 met

# Requirement Status Notes
1 Publish curated notes, then ## Commits, then the final **Full Changelog** line. 🟡 Partly met The expected generated-notes format is assembled, but the action omits ## Commits when there are no generated changes and publishes without a full-changelog line when GitHub returns an unexpected format.
2 Mark releases below 1.0.0 and a/b/rc versions as pre-releases. ✅ Met The default auto policy implements this, with true and false overrides.
3 Provide a shared composite action with tag, notes, pre-release policy, and optional previous-tag inputs; detect the previous tag by default. ✅ Met The action defines these inputs, and the script selects the highest lower published release or, failing that, version tag; final releases skip their own pre-releases.
4 Provide check-only mode so notes are checked before anything is published. ✅ Met Check-only validates the notes, pre-release policy, tag, explicit previous tag, and existing releases without generating notes or creating a release.
5 Generate GitHub's notes, merge them with the curated notes, and create the release with gh release create --verify-tag. ✅ Met The script calls the generate-notes API and creates the release with --verify-tag.
6 Fail clearly if a release or draft of the tag already exists, using only the job's GITHUB_TOKEN with contents: write. 🟡 Partly met Drafts and conflicting published releases fail, and the action defaults to the job token; a matching published release from an earlier attempt instead returns success.
7 Add tests, a README for the action, and an entry in the repository README. ✅ Met The change adds the action README, unit tests and test runner, and documents the action and test command in the repository README.

Sourcery assessment

Needs a human reviewer. 12 findings to address first, and when a caller runs this action outside check-only mode, it creates a published GitHub release with the supplied notes and settings. This PR does not wire that mode into a release workflow, but if a future invocation publishes the wrong release, reverting the action cannot retract notifications or erase what users have already seen.

Blocking findings: actions/publish-release/publish.py:769, actions/publish-release/publish.py:774, actions/publish-release/publish.py:509, actions/publish-release/publish.py:766, actions/publish-release/publish.py:739, and 7 more


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

Comment thread actions/publish-release/publish.py Resolved
Comment thread actions/publish-release/publish.py Resolved
Comment thread actions/publish-release/publish.py Resolved
Comment thread actions/publish-release/publish.py Resolved
Comment thread actions/publish-release/publish.py Resolved
Comment thread actions/publish-release/publish.py Resolved
Comment thread actions/publish-release/publish.py Resolved
Comment thread actions/publish-release/publish.py Resolved
Comment thread actions/publish-release/publish.py Resolved
Comment thread .github/workflows/ci.yml Resolved
- Add the input commit: the tag must point to it (e.g., the commit
  the artefacts were built from).
- Reject a previous tag that isn't lower than the tag, and skip
  releases whose tag was deleted when detecting it; check both also
  in check-only mode.
- Check an existing release before generating notes, so that a re-run
  doesn't depend on the generate-notes API.
- Reject relative HTML href/src links and TODO/FIXME marks.
- Recommend a concurrency group for the publish job in the README.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit e1bbeba into main Nov 9, 2026
6 checks passed
@uniqueg
uniqueg deleted the feat/66-publish-release branch November 9, 2026 14:16
This was referenced Nov 9, 2026
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.

feat: add a shared publish-release action

1 participant