Skip to content

ci: hash-check setuptools-scm in the push job - #378

Merged
uniqueg merged 3 commits into
devfrom
ci/hash-checked-version
Nov 1, 2026
Merged

uniqueg merged 3 commits into
devfrom
ci/hash-checked-version

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Summary

The push job of ci.yml holds the Docker Hub credentials (environment dev-images) and ran pip install "setuptools-scm>=8", unpinned and without hash checks, to derive the version of dev images. Following cloud-registry#305 (#288 there), it now:

  • exports the dependency group build-system (new in pyproject.toml, equal to build-system.requires, locked in uv.lock) with uv export --frozen --only-group build-system --no-emit-project, run with the uv image pinned by digest in the Dockerfile (ghcr.io/astral-sh/uv:0.13.6@sha256:…, as in cloud-registry). The container has no network and mounts pyproject.toml and uv.lock read-only;
  • installs the export with pip install --require-hashes --only-binary :all: --no-deps -r into a virtual environment of its own, then runs python -m setuptools_scm from it.

The uv stage of the Dockerfile is new and isn't used by the image build: no build passes a target, so BuildKit skips it. It exists so that Dependabot's docker entry updates the tag and the digest together. Installing the image itself from the lock is still #365. release.yml was checked: its jobs install no Python packages.

New tests (tests/test_workflows.py):

  • jobs with publishing credentials run pip only as pip install --require-hashes --only-binary :all: --no-deps -r <exported file>, and no other installer;
  • the push job derives the version from the exported lock, before logging in to Docker Hub;
  • the step's sed finds the digest-pinned uv image in the Dockerfile;
  • the build-system group equals build-system.requires and is locked.

Docs: docs/development.md (Dependencies) and comments in Dockerfile, pyproject.toml and .github/dependabot.yml.

Closes #376

Verification

  • The exact Derive version script, extracted from ci.yml and run locally with bash -e (Docker, RUNNER_TEMP, GITHUB_OUTPUT set): pulls the uv image by digest and installs packaging 26.3, setuptools 84.2.1, setuptools-scm 10.3.4 and vcs-versioning 2.6.0, all hash-checked. It outputs the same version as the old method on the same tree (0.3.1.dev37+gaa5da02a9.d20261101 for both).
  • tests/test_workflows.py: 67 passed (after review fixes). tests/test_build.py and tests/test_check_release_pins.py: passed. uv lock --check: passed.
  • pre-commit run --all-files: passed.
  • The push job runs only on pushes to dev, so this PR's CI doesn't run it. The first dev run after the merge will be checked: the version in the "Derive version" log and the image label.
  • CI: all checks passed (run 41315291003; Push image skipped on pull requests). Sourcery: four threads; docs scope and step-name uniqueness fixed, exporter-overwrite and option-order findings answered (tests guard regressions; one exact form on purpose).

Declined review findings

  • String checks of the export command in test_dev_version_from_locked_build_requirements (quality, medium): kept, as in cloud-registry. The security property is enforced by the stricter, shlex-based credential-job test.
  • The sed regex exists in both the step and the test, and the test needs GNU sed (quality, medium): the test runs the step's own sed, so the two copies can't drift unnoticed. CI runs on Linux.
  • The paragraph in docs/development.md is long (quality, low): kept, matching cloud-registry.

🤖 Generated with Claude Code

uniqueg and others added 2 commits November 1, 2026 15:03
The push job holds the Docker Hub credentials and installed
setuptools-scm unpinned. It now exports the dependency group
build-system (the same as build-system.requires) from uv.lock with the
uv image of the Dockerfile, pinned by digest and run without network,
and installs it with `pip install --require-hashes --only-binary :all:
--no-deps` into a virtual environment of its own. The uv stage is new
and unused by the image build; Dependabot's docker entry updates it.

Tests check that jobs with publishing credentials install only
hash-checked requirements, that the push job derives the version from
the exported lock before logging in, that the step finds the pinned uv
image, and that the group matches build-system.requires.

Closes #376

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test compares the locked group with the names of
build-system.requires; the docs name the runner's pip as the one
unchecked tool of the push job.

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

sourcery-ai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The PR secures dev-image version derivation by exporting build requirements from uv.lock with a digest-pinned, network-isolated uv image, installing them hash-checked in an isolated environment before credential use, and adding dependency consistency, image-pin, and credential-job regression tests.

Sequence diagram for hash-checked dev-image version derivation

sequenceDiagram
    participant Push as push job
    participant Docker as Docker
    participant UV as Digest-pinned uv image
    participant Pip as Isolated pip environment
    participant SCM as setuptools_scm
    participant Hub as Docker Hub

    Push->>Docker: docker run --network none
    Docker->>UV: export --frozen --only-group build-system --no-emit-project
    UV-->>Push: build-requirements.txt from uv.lock
    Push->>Pip: pip install --require-hashes --only-binary :all: --no-deps -r
    Pip->>SCM: python -m setuptools_scm
    SCM-->>Push: version
    Push->>Hub: Docker login
Loading

File-Level Changes

Change Details Files
Harden version derivation in the credentialed push job by replacing the unpinned installation with a locked, offline, hash-verified build-dependency workflow.
  • Extract a digest-pinned uv image from the Dockerfile.
  • Export the locked build-system group without network access or the project itself.
  • Install only hashed binary requirements into an isolated virtual environment and run setuptools_scm from it before registry login.
.github/workflows/ci.yml
Dockerfile
Add and maintain a locked dependency group representing the package build requirements.
  • Define the build-system dependency group to match build-system.requires.
  • Update uv.lock with the resolved packages and hashes.
  • Document lock maintenance and Dependabot coverage for the dependency group and uv image.
pyproject.toml
uv.lock
docs/development.md
.github/dependabot.yml
Add regression tests enforcing the supply-chain and workflow ordering guarantees.
  • Require credential-bearing jobs to use only hash-checked, wheel-only pip installs from requirement files.
  • Verify version derivation uses the locked build group, offline uv execution, and occurs before Docker Hub login.
  • Validate the Dockerfile's digest-pinned uv image and consistency between build-system.requires and its locked dependency group.
tests/test_workflows.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

@read-the-docs-community

read-the-docs-community Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 proTES | 🛠️ Build #35559786 | 📁 Comparing e7c46db against latest (95d58ba)

  🔍 Preview build  

1 file changed
± development/index.html

@uniqueg
uniqueg marked this pull request as ready for review November 1, 2026 14:10
@codecov

codecov Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (95d58ba) to head (e7c46db).
⚠️ Report is 1 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #378   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           23        23           
  Lines         2217      2217           
=========================================
  Hits          2217      2217           

☔ 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.

@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="docs/development.md" line_range="135" />
<code_context>
+(`build-system.requires`) are locked the same way, as the dependency group
+`build-system`: CI's `push` job derives the version of dev images with
+them, exported by the uv image of the `Dockerfile` (pinned by digest) and
+installed with hash checks, so that no job that holds publishing
+credentials installs a package without hash checks (the tests check this;
+the pip that installs them is that of the runner's Python, `ensurepip`,
</code_context>
<issue_to_address>
**Credentialed builds install unhashed packages**

When a credentialed push or release job builds the image, the Docker build runs the Dockerfile's `pip install` commands for runtime dependencies without hash checks, while the test scans only workflow `run` commands. The stated credential-job guarantee is therefore false even when the test passes.

Add hash checks to the Dockerfile installs and extend the test to cover installs performed during image builds.

Also at `tests/test_workflows.py:629-630`, `docs/development.md:136-137`.
</issue_to_address>

### Comment 2
<location path="tests/test_workflows.py" line_range="680" />
<code_context>
+    (with hash checks, see `test_credential_jobs_install_hash_checked`).
+    """
+    script = " ".join(_commands(_derive_version()))
+    assert '"${uv_image}" export --frozen --only-group build-system' in script
+    assert "--no-emit-project" in script
+    assert "--network none" in script
</code_context>
<issue_to_address>
**Unpinned export can supply requirements**

When the script retains the expected pinned export but later overwrites its requirements file using an unpinned, network-enabled export, `test_dev_version_from_locked_build_requirements` checks for the pinned export, network restriction and output redirection as separate substrings, without checking that they belong to the same command or that this command is the final writer. A later export from an unpinned, network-enabled image can overwrite the requirements file and still pass, so pip installs requirements from an unverified exporter.

Parse the export commands and assert that the sole command producing the file pip reads uses the pinned image and network isolation.
</issue_to_address>

### Comment 3
<location path="tests/test_workflows.py" line_range="664" />
<code_context>
+        The step.
+    """
+    jobs = _load(WORKFLOWS / "ci.yml")["jobs"]
+    steps = {step["name"]: step for step in jobs["push"]["steps"]}
+    names = list(steps)
+    # Before the job logs in to Docker Hub
</code_context>
<issue_to_address>
**Duplicate names bypass login ordering**

When the `push` job contains a second step named `Derive version` after `Log in to Docker Hub`, `_derive_version` overwrites duplicate step names in `steps` but preserves the key’s first insertion position. `test_dev_version_from_locked_build_requirements` can therefore validate a later “Derive version” step while the ordering assertion sees the earlier one, allowing version derivation after Docker Hub login to pass.

Assert step-name uniqueness before building the dictionary, or compare the actual step indexes directly.
</issue_to_address>

### Comment 4
<location path="tests/test_workflows.py" line_range="654" />
<code_context>
+                    file = options.index("-r")
+                    assert options[file + 1].startswith("$"), where
+                    rest = options[:file] + options[file + 2 :]
+                    assert rest == HASH_CHECKED, where
+
+
</code_context>
<issue_to_address>
**Safe option reordering fails**

When a credentialed job uses the same required pip options in a different order, `test_credential_jobs_install_hash_checked` compares the parsed options to `HASH_CHECKED` in one fixed order. A valid `pip install` with the same hash, wheel-only and no-dependency options reordered fails this assertion despite preserving the tested behavior.

Compare the parsed options as an order-independent collection while still checking duplicates and the `:all:` argument.
</issue_to_address>

Linked issues

#376 ci: hash-check setuptools-scm in the push job · 6 of 6 met

# Requirement Status Notes
1 Lock build-system.requires as the build-system dependency group in uv.lock. ✅ Met The group matches build-system.requires, and the workflow test checks that its dependencies are present in the lock.
2 Export the locked group with a digest-pinned uv image, without network access. ✅ Met The push job extracts the digest-pinned uv image from the Dockerfile and runs the frozen export with networking disabled.
3 Install the exported requirements into their own virtual environment with hash checks, wheels only, and no dependency resolution. ✅ Met The job uses pip with --require-hashes, --only-binary :all:, and --no-deps, then runs setuptools-scm from that environment.
4 Check release.yml for the same pattern. ✅ Met The release workflow runs Python scripts but does not install Python packages.
5 Ensure no job holding publishing credentials installs Python packages without hash checks, and check this with tests. ✅ Met The new test scans credential-bearing jobs across the workflow files and requires pip installs to use hash-checked requirements.
6 Derive dev image versions as before. ✅ Met The push job still runs setuptools-scm from the repository checkout and passes its version to the image build; the new test checks that derivation uses the locked requirements.

Sourcery assessment

Needs a human reviewer. 3 findings to address first, and if the locked build tools or version derivation produce the wrong value, the push job could publish a dev image under an incorrect version tag. That artifact can outlive a revert, but the tag can be removed or corrected by rebuilding and republishing.

Blocking findings: docs/development.md:135, tests/test_workflows.py:680, tests/test_workflows.py:664


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

Comment thread docs/development.md Resolved
Comment thread tests/test_workflows.py Resolved
Comment thread tests/test_workflows.py Resolved
Comment thread tests/test_workflows.py Resolved
The image build in the credential jobs still installs from ranges
(#365); the docs say so. The test of the push job requires unique step
names, so that the order checked is that of the step it validates.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit f56f0ca into dev Nov 1, 2026
32 checks passed
@uniqueg
uniqueg deleted the ci/hash-checked-version branch November 1, 2026 14:23
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: hash-check setuptools-scm in the push job

1 participant