Skip to content

ci: rewrite README links to absolute URLs for PyPI#3074

Merged
markphelps merged 6 commits into
mainfrom
issue-1375
Jun 25, 2026
Merged

ci: rewrite README links to absolute URLs for PyPI#3074
markphelps merged 6 commits into
mainfrom
issue-1375

Conversation

@anish-sahoo

Copy link
Copy Markdown
Collaborator

Problem

PyPI renders a package's README from the long_description baked into the distribution metadata at build time, and ships no other repo files. The Cog SDK README uses relative links (docs/*.md, CONTRIBUTING.md), so every one of them 404s on https://pypi.org/project/cog/.

The publish step can't fix this — pypa/gh-action-pypi-publish only uploads pre-built artifacts and explicitly disclaims transforming them, and twine check does not validate links. The README has to be transformed at build time.

Change

In the build-sdk job of release-build.yaml (the job that produces the artifacts published to PyPI), add two steps:

  1. Rewrite README links to absolute URLs for PyPI — before uv build, rewrite relative Markdown links to absolute https://github.com/replicate/cog/blob/<tag>/<path> URLs, editing the checked-out README in place (ephemeral on the runner, never committed). Pinning to the release tag (github.ref_name) makes the links immutable and version-correct. Only relative links are rewritten; images and any absolute link (URL scheme, protocol-relative //, in-page # anchors) are left untouched.
  2. Verify PyPI README links are absolute — after the build, fail the job if any relative link remains in the wheel METADATA or sdist PKG-INFO (the exact bytes PyPI renders).

The committed README.md is unchanged (so GitHub keeps its relative links), and no new files are added to the repo. The tag is passed via step env: and read with os.environ, so there is no ${{ }} script-injection surface.

Test plan

Validated locally with a real uv build:

  • Original README → metadata contains the relative links → verify fails.
  • Rewritten README → metadata contains only absolute blob/ URLs → verify passes.
  • A relative image is left relative and is caught by the verify step (a blob/ URL would serve HTML, not raw bytes).
  • Absolute links (https/http/mailto////uppercase scheme) and the nested DeepWiki linked-image are left untouched.
  • YAML parses and both embedded Python blocks compile after de-indentation.

Fixes #1375

PyPI renders the README from the package metadata baked in at build time and ships no other repo files, so the README's relative links (docs/*, CONTRIBUTING.md) 404 on the project page.

In the release-build SDK job, rewrite relative Markdown links to absolute GitHub blob URLs pinned to the release tag, editing the checked-out README in place (never committed) before `uv build` bakes it into the long_description. A follow-up verify step fails the build if any relative link remains in the wheel METADATA or sdist PKG-INFO. Images and absolute links are left untouched.

Fixes #1375

@ask-bonk ask-bonk Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm Bonk, and I've done a quick review of your PR.

The PR adds two steps to rewrite README relative links to absolute GitHub blob URLs before building the SDK wheel, plus a verification step to catch any stragglers. The approach is sound and well-tested.

I found one robustness issue in the verify script: if the wheel/sdist glob returns empty or the metadata file isn't found, the script crashes with an unhelpful error (IndexError or RuntimeError from StopIteration) instead of a clear message about what went wrong.

Comment thread .github/workflows/release-build.yaml Outdated
@ask-bonk

ask-bonk Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

I'm Bonk, and I've done a quick review of your PR.

The PR adds two steps to rewrite README relative links to absolute GitHub blob URLs before building the SDK wheel, plus a verification step to catch any stragglers. The approach is sound and well-tested.

I found one robustness issue in the verify script: if the wheel/sdist glob returns empty or the metadata file isn't found, the script crashes with an unhelpful error (IndexError or RuntimeError from StopIteration) instead of a clear message about what went wrong.

Posted as review comment on .github/workflows/release-build.yaml:214.

github run

@ask-bonk ask-bonk Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm Bonk, and I've done a quick review of your PR.

The PR adds two steps to rewrite README relative links to absolute GitHub blob URLs before building the SDK wheel, plus a verification step to catch any stragglers. The approach is sound and well-tested.

I found one robustness issue in the verify script: if the wheel/sdist glob returns empty or the metadata file isn't found, the script crashes with an unhelpful error (IndexError or RuntimeError from StopIteration) instead of a clear message about what went wrong.

Comment thread .github/workflows/release-build.yaml Outdated
@ask-bonk

ask-bonk Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

I'm Bonk, and I've done a quick review of your PR.

The PR adds two steps to rewrite README relative links to absolute GitHub blob URLs before building the SDK wheel, plus a verification step to catch any stragglers. The approach is sound and well-tested.

I found one robustness issue in the verify script: if the wheel/sdist glob returns empty or the metadata file isn't found, the script crashes with an unhelpful error (IndexError or RuntimeError from StopIteration) instead of a clear message about what went wrong.

Posted as review comment on .github/workflows/release-build.yaml:214.

github run

@ask-bonk

ask-bonk Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

I've thoroughly reviewed PR #3074. The previous feedback about robustness in the verify script has been addressed — the glob and metadata lookups now have explicit checks with clear error messages. The implementation is clean, secure, and well-tested. No actionable issues remain.

LGTM

github run

@ask-bonk

ask-bonk Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

I'm Bonk, and I've done a quick review of your PR.

The PR adds two steps to rewrite README relative links to absolute GitHub blob URLs before building the SDK wheel, plus a verification step to catch any stragglers. The approach is sound and well-tested.

I found one robustness issue in the verify script: if the wheel/sdist glob returns empty or the metadata file isn't found, the script crashes with an unhelpful error (IndexError or RuntimeError from StopIteration) instead of a clear message about what went wrong.

Posted as review comment on .github/workflows/release-build.yaml:214.

github run

@anish-sahoo anish-sahoo marked this pull request as ready for review June 23, 2026 21:49
@anish-sahoo anish-sahoo requested a review from a team as a code owner June 23, 2026 21:49
@ask-bonk

ask-bonk Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

LGTM

github run

@markphelps markphelps added this pull request to the merge queue Jun 25, 2026
Merged via the queue into main with commit 5e3a8c9 Jun 25, 2026
43 checks passed
@markphelps markphelps deleted the issue-1375 branch June 25, 2026 16:19
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.

pypi docs dead link

2 participants