Repository navigation
feat: add a shared publish-release action - #67
Conversation
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]>
Reviewer's GuideAPIDefine the reusable action’s inputs, output, permissions-facing environment wiring, and invocation contract.
ImplementationImplement release-note validation, version and tag selection, safe existing-release handling, GitHub CLI calls, and action outputs.
ConfigurationAdd CI coverage for the script and live check-only behaviour, including action wiring against this repository.
Ignore generated Python artefacts.
DocumentationDocument the action’s release-note format, usage, inputs, outputs, behaviour, and caller requirements.
Add the action to the repository catalogue and describe how to run its tests locally.
TestsExercise note validation, body generation, version selection, publishing, check-only mode, and the script’s real CLI calls against a stub GitHub CLI.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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
- 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]>
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:## Commits: GitHub's generated notes (releases/generate-notes), verbatim with "New Contributors", without## What's Changed;**Full Changelog**line last.Details:
check-only: "true"for thepreparejob (needs onlycontents: read): checks the notes, the pre-release policy, that the tag and an explicitprevious-tagexist, and that no release of the tag exists, so that a release fails before anything is published.auto(default): pre-release below 1.0.0 and fora/b/rcversions;true/falseoverride it. Pre-releases are never the latest release; a final release is the latest unless a higher published release exists.v1.0,v1.1but no GitHub releases, so its v1.2.0 starts atv1.1). A final release skips its own pre-releases, so1.2.0starts at1.1.0, not at1.2.0rc1.gh release create --verify-tag; only the job'sGITHUB_TOKEN; inputs reach the script through the environment only.scripts/release_notes.py(without its FOCA-specific moving-link check).publish.py) uses the Python standard library andghonly; it is tested withunittest(tests/publish-release/test.sh), like the other actions' tests run from CI'stestjob.Closes #66
Verification
bash tests/publish-release/test.sh: 41 tests pass (many with sub-tests), including an end-to-end run ofpublish.py publishagainst a recording stubghthat checks the real command lines and flags. Branch coverage ofpublish.py: 99% (only the__main__guard is not traced).ruff check(E, F, W, B, UP, D, ANN, S, SIM, RUF, PL),ruff format --checkandmypy --stricton 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).elixir-cloud-aai/.githubv1.0.0fails with "exists already",v0.0.0with "doesn't exist on GitHub";elixir-cloud-aai/tesk-apiv1.1passes.CI passed).Lane
Full review lane (release workflow building block):
adversarial-reviewerandquality-reviewer, two rounds. Fixed: committed bytecode (now.gitignore), check-only covering the settings and repository, the previous tag of a final release,check-onlyvalues 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
commitinput (tag must point to the built commit), previous tag must be lower and must still exist, existing release checked beforegenerate-notes, relative HTMLhref/srcandTODO/FIXMErejected, concurrency group recommended in the README.Declined review findings
# vX.Y.Ztitle line (callers' notes have none; the title comes from the tag); concurrent publish of the same tag (callers run one run per tag); no## Commitswithout 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;preparefails on any existing release); CI action step only checks wiring (the preceding step asserts each error message). Each answered in its thread.contents: read,check-onlycan't see drafts (documented);publishstill fails on a draft before generating notes.Notes for callers
🤖 Generated with Claude Code