Skip to content

ci: align release jobs, absolute README images - #50

Merged
uniqueg merged 4 commits into
devfrom
ci/release-align
Nov 1, 2026
Merged

uniqueg merged 4 commits into
devfrom
ci/release-align

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Align the release job IDs and names with cloud-registry, proTES and FOCA: build becomes prepare ("Prepare release"), the PyPI job is named "Release package" (ID pypi) and its step "Upload to PyPI"; attest ("Attest distributions") and publish ("Publish release") stay. needs: and needs.<job>.outputs follow. Environment, permissions, attestations and trusted publishing are unchanged (the trusted publishers name the workflow file and the environment, not the jobs).
  • Before uv build, the release workflow rewrites the relative image paths of the package's README.md (${PACKAGE}/README.md) to https://raw.githubusercontent.com/${{ github.repository }}/<tag>/<package path>/<path> (paths resolve from the package directory, as on GitHub) with python -m scripts.readme_images (stdlib only), then runs check. Versions here are static, so the dirty tree does not matter; the rewrite is deterministic, so builds stay reproducible.
  • Tests (tests/test_readme_images.py, 100% branch coverage) include every package's README.
  • Docs: "What the workflow does" in docs/releasing.md uses the new job names and mentions the rewrite.

Closes #27
Closes #28

Verification

  • ruff check, ruff format --check, mypy scripts tests docs/hooks.py, actionlint .github/workflows/release.yml: clean.
  • coverage run --branch --source scripts,docs -m pytest tests (138 passed), coverage report: 100%.
  • Dry run locally on a copy with an image added to meta/README.md: rewrite + check, then uv build --package foca-plugins; the wheel's METADATA has the absolute URL with the package path.
  • Fork dry run: not possible, uniqueg/foca-plugins does not exist; the workflow was only linted.
  • CI: pending.

Review

Regular lane (release workflow): adversarial and quality review, two rounds. Fixed: step order/comments, hardening of the rewrite (unquoted attributes, data-src, srcset edge cases, > in attributes, reference-style and shortcut images, leading slash, non-UTF-8).

Declined review findings

  • Nested brackets in alt text, multi-line images, definitions with the path on the next line, HTML comments and code fences are not handled specially (documented limits; no package README has images today).
  • Percent-encoding of spaces in angle-bracket paths: not needed now.
  • Tag in the URL is not encoded: tags are validated by scripts.release release.

Open questions

None. Only images are rewritten; relative links in package READMEs still do not resolve on PyPI.

🤖 Generated with Claude Code

Summary by Sourcery

Align the release workflow with the organisation’s standard job naming and make package README images render reliably on PyPI.

New Features:

  • Rewrite relative package README image paths to release-tagged absolute GitHub URLs before building distributions.

Bug Fixes:

  • Ensure package README images render correctly in PyPI long descriptions.

Enhancements:

  • Align release workflow job IDs and names with the organisation’s other release workflows.
  • Add validation and comprehensive tests for Markdown and HTML image path rewriting, including all package READMEs.

Documentation:

  • Update release documentation to reflect the renamed jobs and README image URL rewriting.

Tests:

  • Add comprehensive README image rewriting tests with full branch coverage.

uniqueg and others added 3 commits November 1, 2026 18:00
Rename the release jobs as in cloud-registry and proTES: build to
prepare ("Prepare release") and the PyPI job to "Release package"; needs
and outputs follow. Rewrite the relative image paths of the package
README to URLs pinned to the release tag before building, as PyPI cannot
resolve them (scripts/readme_images.py, with tests).

Closes #27
Closes #28

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Handle unquoted attributes, data-src, commas in srcset URLs, paths in
angle brackets and reference-style images (through their
definitions); rename the PyPI upload step; re-wrap comments.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Find images in quoted attributes with a ">", srcset candidates
without a space after the comma, and shortcut reference images; refuse
paths with a leading slash; report non-UTF-8 READMEs as errors.

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

sourcery-ai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Aligns release workflow job naming with the organization’s standard stages and adds a deterministic pre-build step that converts package README image references into release-tagged absolute GitHub URLs, with comprehensive tests and updated release documentation.

Sequence diagram for release README image rewriting and publication

sequenceDiagram
    participant GitHub as GitHub Actions
    participant Prepare as prepare: Prepare release
    participant Images as scripts.readme_images
    participant PyPI as PyPI
    participant Publish as publish: Publish release

    GitHub->>Prepare: Validate tag and package
    Prepare->>Images: rewrite(base URL, package README)
    Images-->>Prepare: README with tag-pinned image URLs
    Prepare->>Images: check(package README)
    Images-->>Prepare: Verify no relative image paths
    Prepare->>Prepare: uv build and check distributions
    GitHub->>PyPI: attest distributions
    GitHub->>PyPI: pypi: Upload to PyPI
    GitHub->>Publish: Create GitHub release with distributions
Loading

Flow diagram for renamed release workflow stages

flowchart LR
    prepare[Prepare release]
    attest[Attest distributions]
    pypi[Release package]
    publish[Publish release]

    prepare --> attest
    prepare --> pypi
    attest --> pypi
    prepare --> publish
    pypi --> publish
Loading

File-Level Changes

Change Details Files
Standardize release workflow stages and update all dependency and output references.
  • Renamed the distribution-building job from build to prepare and aligned its display name.
  • Renamed the PyPI job and upload step to Release package/Upload to PyPI.
  • Updated needs dependencies, environment URLs, and job output references while preserving publishing permissions and trusted-publishing configuration.
  • Updated workflow comments and release documentation with the standardized job IDs and names.
.github/workflows/release.yml
docs/releasing.md
Add deterministic README image URL rewriting before release builds.
  • Added a stdlib-only CLI that rewrites relative Markdown and HTML image paths to tag-pinned raw GitHub URLs.
  • Handled Markdown inline, reference-style, shortcut, HTML src, and srcset images while preserving already absolute URLs and rejecting unsafe paths.
  • Runs rewrite and validation before uv build, resolving paths relative to each package directory.
scripts/readme_images.py
.github/workflows/release.yml
Provide comprehensive coverage for README image processing and package compatibility.
  • Added unit tests for path classification, normalization, error handling, Markdown/HTML variants, srcset, references, encoding, and CLI behavior.
  • Parameterized checks across every discovered package README to ensure rewritten content contains no relative image paths.
tests/test_readme_images.py

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 Nov 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (dev@c0dd2f3). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             dev       #50   +/-   ##
=======================================
  Coverage       ?   100.00%           
=======================================
  Files          ?         6           
  Lines          ?       553           
  Branches       ?        71           
=======================================
  Hits           ?       553           
  Misses         ?         0           
  Partials       ?         0           
Flag Coverage Δ
foca-plugin-generic-example-noop 100.00% <ø> (?)
foca-plugin-generic-routing-random 100.00% <ø> (?)
foca-plugin-tes-routing-distance 100.00% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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 November 1, 2026 17:17

@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/readme_images.py" line_range="40" />
<code_context>
+# Paths with a scheme (`https:`, `data:`), `//host/...` and `#fragment`
+_ABSOLUTE = re.compile(r"^(?:[A-Za-z][A-Za-z0-9+.\-]*:|//|#)")
+# `![alt](path "title")` or `![alt](<path>)`; the path is group 3
+_MARKDOWN_IMAGE = re.compile(r"(!\[[^\]]*\]\(\s*)(<?)(?:(?<=<)([^>]+)|([^)\s>]+))")
+# `![alt][ref]` (or `![ref][]`), whose path is in a definition (`[ref]: path`);
+# the label is group 1 or 2
</code_context>
<issue_to_address>
**Invalid image paths pass checks**

When a Markdown image destination contains escaped or balanced parentheses, especially followed by enough `../` segments to leave the repository, `_MARKDOWN_IMAGE` stops at the first `)`, so `convert_images` rewrites only a destination prefix and leaves malformed Markdown; `check` can also treat the rewritten destination as absolute and miss a path that escapes the repository. The image fails to render or an escaping path passes the workflow check.

Parse Markdown image destinations with support for escaped and balanced parentheses before rewriting or validating them.

Also at `scripts/readme_images.py:100-102`.
</issue_to_address>

### Comment 2
<location path="scripts/readme_images.py" line_range="101-102" />
<code_context>
+            " README"
+        )
+    normalized = posixpath.normpath(path)
+    if normalized == ".." or normalized.startswith("../"):
+        raise ImagePathError(f"Image path '{path}' leaves the repository")
+    return f"{base.rstrip('/')}/{normalized}"
+
</code_context>
<issue_to_address>
**Valid parent paths abort releases**

When a package README uses `../` to reference an image elsewhere inside the repository, `absolute()` normalizes the image path without the package directory, so a path such as `../images/logo.png` is rejected even when it resolves to a file inside the repository from the package README. The `prepare` job then fails instead of building the release.

Validate the normalized path after resolving it against the package directory, and reject it only if that resolved path escapes the repository.
</issue_to_address>

### Comment 3
<location path="scripts/readme_images.py" line_range="169" />
<code_context>
+
+    # Labels of reference-style images, normalized as in CommonMark
+    labels = {
+        (ref or alt).strip().lower() for alt, ref in _REFERENCE_IMAGE.findall(text)
+    }
+    text = _DEFINITION.sub(definition, text)
</code_context>
<issue_to_address>
**Reference images stay relative**

When a reference-style image and its definition have labels that CommonMark considers equivalent after whitespace collapsing or Unicode case folding, `convert_images` and `relative_paths` compare labels using only `strip().lower()`, so they miss the equivalent definition; the relative image URL remains unchanged, `check` passes, and the image does not render on PyPI.

Apply the same CommonMark label normalization, including whitespace collapsing and Unicode case folding, when collecting, matching, and checking reference labels.

Also at `scripts/readme_images.py:162`, `scripts/readme_images.py:170`.
</issue_to_address>

### Comment 4
<location path="tests/test_readme_images.py" line_range="119" />
<code_context>
+    text = (ROOT / package.path / "README.md").read_text(encoding="utf-8")
+    base = f"{BASE}/{package.path}"
+    rewritten = readme_images.rewrite(text, base)
+    assert readme_images.relative_paths(rewritten) == []
+
+
</code_context>
<issue_to_address>
**Package rewrite check is vacuous**

When all discovered package READMEs contain no recognized image paths, when the discovered package READMEs contain no recognized images, `test_readmes_have_no_relative_image_paths_after_rewrite` at lines 118–119 passes even if `rewrite` is a no-op: `relative_paths` finds nothing in the unchanged text, so this package-level check gives no evidence that release README rewriting works.

Add a relative image to a package README fixture and assert its exact rewritten URL, including the package path.
</issue_to_address>

Linked issues

#27 ci: align the release job names · 3 of 3 met

# Requirement Status Notes
1 Add a prepare job named “Prepare release” for the checks, and make the other jobs depend on it. ✅ Met The prepare job holds the release checks; attest, pypi, and publish depend on it directly or through their dependency chain.
2 Name registry-publishing jobs after what they release, uniquely across the repository’s workflows. ✅ Met The PyPI job is named “Release package”; that name is unique among the repository’s workflow jobs.
3 Keep publish / “Publish release” for creating the GitHub release. ✅ Met

#28 ci: rewrite README image paths for PyPI · 3 of 3 met

# Requirement Status Notes
1 Before building, rewrite relative package README image paths to absolute, release-tag-pinned GitHub URLs, using the repository from the run context and paths relative to the package directory. ✅ Met The workflow rewrites ${PACKAGE}/README.md using the repository and tag from the run context, then checks it before uv build.
2 Test that rewritten READMEs have no relative image paths left. ✅ Met The test applies the rewrite and checks for remaining relative image paths in every discovered package README.
3 Keep the setuptools + setuptools-scm build backend. ✅ Met The diff does not change the build backend.

Sourcery assessment

Needs a human reviewer. 4 findings to address first, and the release build rewrites README image paths before packaging, so an incorrect rewrite could ship in the PyPI distribution and its published description. Reverting the workflow would not change versions already released; the bounded issue would need a corrected release.

Blocking findings: scripts/readme_images.py:40, scripts/readme_images.py:102, scripts/readme_images.py:169, tests/test_readme_images.py:119


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

Comment thread scripts/readme_images.py Resolved
Comment thread scripts/readme_images.py Resolved
Comment thread scripts/readme_images.py Resolved
Comment thread tests/test_readme_images.py Resolved
Collapse whitespace and fold case when matching reference-style
images with their definitions, as CommonMark does.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@uniqueg
uniqueg merged commit 03c3c28 into dev Nov 1, 2026
78 checks passed
@uniqueg
uniqueg deleted the ci/release-align branch November 1, 2026 19:05
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: rewrite README image paths for PyPI ci: align the release job names

1 participant