Skip to content

fix: check the steps of builds - #107

Merged
uniqueg merged 4 commits into
devfrom
fix/94-build-steps
Nov 9, 2026
Merged

uniqueg merged 4 commits into
devfrom
fix/94-build-steps

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes the gaps of the build path listed in #94 (only with endpoints.builds.enabled), before the 0.2.0 tag:

  1. GitHub's response to the signing dispatch is checked: only 204 counts as triggered. Any other answer (e.g., 401 for a wrong GH_ACCESS_TOKEN, 404 for a wrong gh_action_path, 422) is logged with its status and takes the existing failure path: a 500, the build back to its previous status, files, pod and registry token kept, so the pod's next report (5 seconds later) triggers the signing again. Subscribers are no longer notified of an image that is never published.
  2. The updater works with any repository.id_length: build pods get REPOSITORYID, and the updater reports to that repository. Pods without it (created by earlier versions) fall back to the first 6 characters, as before.
  3. String splitting:
    • The clone's directory is named by the new clone_directory(): the last part of the URL's path (or of an scp-like address), without .git. Names that aren't plain file names (.., -repo, empty) or that would collide with the build's own files (config.json, *.yaml) get repository. Before, repo_url.split("/")[4] gave a 500 for URLs of other forms.
    • create_deployment_YAML() takes the build ID instead of split("/")[2] of its file's path, which assumed a base directory one level deep.
    • dockerhub_token is split at the first : only, so passwords may contain colons.

Docs: docs/deployment.md (log messages, signing failures and their retries, REPOSITORYID, the clone's directory).

Closes #94

Verification

  • pytest --cov: 715 passed, coverage 100%
  • MONGODB_TEST_URI=… pytest tests/integration against MongoDB 7.0: 45 passed
  • ruff check, ruff format --check, mypy: clean; mkdocs build --strict: clean
  • New tests: test_trigger_signing_image_accepted, test_trigger_signing_image_rejected (200, 401, 404, 422, 500), test_clone_directory, test_git_clone_and_checkout_other_url, test_create_deployment_yaml_names, test_report_build_repository_id; the repository ID is asserted from start_build() to the pod file
  • CI: all checks passed; code scanning: 0 open alerts (two CodeQL warnings on the first push, a substring check of the URL in the test mocks, fixed by comparing the host)

Review

Two rounds (adversarial and quality reviewer). Fixed: a repository named config.json would have been cloned onto the build's Docker configuration; tests for the repository ID's way to the pod and for a URL of another form; docs placement and wrapping; docstring style.

Declined review findings

  • Back-off for a signing that GitHub keeps refusing (low): a refused dispatch is requested again every 5 seconds per build, until the setting is fixed or the build is canceled. fix: check the steps of builds #94 asks for exactly the existing failure path (back to the previous status, retried with the next report); a back-off or marking 4xx answers as FAILED changes the retry design and fits a separate issue. The behaviour and the log message are documented.

  • Validate repository URLs (low, not new): repository URLs aren't checked when repositories are registered or updated (see the comment in repositories.py), so a local path or file:// URL can be cloned, as with the old split("/") too. Restricting them to remote schemes is new behaviour for the registration API and fits a separate issue; the docs now speak of remote URLs only, and builds are documented as for trusted repositories only.

Open questions

None.

🤖 Generated with Claude Code

Summary by Sourcery

Harden build creation and completion reporting across signing failures, configurable repository IDs, and varied repository and credential formats.

Bug Fixes:

  • Validate GitHub signing dispatch responses and retry builds through the existing failure path when signing is not accepted.
  • Support repository IDs of any configured length when build pods report completion.
  • Handle repository URLs and Docker Hub credentials with broader valid formats without build-path collisions.

Enhancements:

  • Make clone and deployment paths independent of URL and directory-depth assumptions.
  • Document signing failures, retries, repository identifiers, and clone directory naming.

Documentation:

  • Document GitHub signing response handling, retry behavior, repository identifiers, and clone directory naming.

Tests:

  • Add coverage for signing response statuses, repository ID propagation, flexible clone paths, deployment naming, and credentials containing colons.

uniqueg and others added 3 commits November 9, 2026 21:49
- Signing: only GitHub's 204 counts as a triggered dispatch; any
  other response is logged with its status and takes the existing
  failure path (500, build back to its previous status, token kept,
  retried with the pod's next report). Passwords of dockerhub_token
  are split at the first colon only.
- Updater: build pods get REPOSITORYID, and the updater reports to
  that repository, so any repository.id_length works; pods without it
  fall back to the first 6 characters, as before.
- Clones are named after the last part of the repository's URL, or
  "repository" if that isn't a plain file name, instead of the fifth
  part of the URL split at "/" (a 500 for other URL forms). The pod's
  name comes from the build ID, not from its file's path.

Docs: deployment guide (signing failures and retries, REPOSITORYID,
clone directory).

Closes #94

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review findings: a repository named config.json (or *.yaml) would be
cloned into the path of the build's own Docker configuration (or pod
file), failing every build; such names now get "repository". Tests
check that the repository ID reaches create_build and the pod file,
and that a URL of another form (a local path) is cloned. The docs
describe the clone directory where cloning is described, and the
signing retries in a paragraph of their own.

Refs #94

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Round-2 review: the docs presented every URL that Git can clone as
supported, including local paths. Name remote URLs of other forms
instead; wrap the paragraph on failed completions, and give the new
Args entries the types their siblings have.

Refs #94

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg uniqueg added this to the v0.2.0 milestone Nov 9, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Carry the repository ID from build registration into the generated pod so the updater can report builds to repositories with any configured ID length, while preserving the legacy fallback for existing pods.

  • build-complete-updater/updater.py L23-24, L53-56, L70-72
  • pubgrade/modules/endpoints/builds.py L339-806 (11 small edits)

Derive safe clone directory names from varied repository URL forms, and pass the build ID explicitly rather than inferring it from the deployment file path.

  • pubgrade/modules/endpoints/builds.py L58-61, L620-646 (+2 small edits)

Treat only GitHub's 204 response as an accepted signing dispatch, and split Docker Hub credentials only at the username-password separator.

  • pubgrade/modules/endpoints/builds.py L1288-1292, L1319, L1329-1337

Documentation

Explain GitHub response handling and the retry behavior when signing dispatches fail.

  • docs/deployment.md L92, L206-220

Document repository ID propagation and the fallback for pods created by earlier versions.

  • docs/deployment.md L105-108

Describe the clone directory naming rule and its support for remote URL forms.

  • docs/deployment.md L127-131

Tests

Test signing response validation and Docker Hub passwords containing colons, plus mock responses that distinguish GitHub by host.

  • tests/pubgrade/endpoints/test_builds.py L194-199, L573-577, L1604-1701 (+1 small edits)
  • tests/pubgrade/test_server.py L5, L58, L70-72

Test repository ID plumbing from build startup through the generated pod and updater report URL.

  • tests/pubgrade/endpoints/test_builds.py L743-761, L1081-1085, L1260-1263 (+11 small edits)
  • tests/pubgrade/test_server.py L205, L219
  • tests/test_updater.py L121-133

Test clone naming for varied URL forms, safe fallbacks, and cloning from a local path.

  • tests/pubgrade/endpoints/test_builds.py L14

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 9, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 Pubgrade | 🛠️ Build #35768032 | 📁 Comparing b2153a9 against latest (663f546)

  🔍 Preview build  

1 file changed
± deployment/index.html

Comment thread tests/pubgrade/test_server.py Fixed
@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #107   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           17        18    +1     
  Lines         1517      1545   +28     
=========================================
+ Hits          1517      1545   +28     

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

CodeQL (py/incomplete-url-substring-sanitization): the request mocks
told GitHub apart by a substring of the URL. Compare the host instead.

Refs #94

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg marked this pull request as ready for review November 9, 2026 21:30
@uniqueg
uniqueg requested a review from akash2237778 as a code owner November 9, 2026 21:30
@sourcery-ai

sourcery-ai Bot commented Nov 9, 2026

Copy link
Copy Markdown

Linked issues

Checked at commit b2153a9

#94 fix: check the steps of builds · 3 of 3 met

# Requirement Status Notes
1 Check GitHub’s signing-dispatch response; only 204 succeeds, and failures take the existing InternalServerError path. Update the deployment documentation. ✅ Met The dispatch raises InternalServerError for every response other than 204; build completion restores the previous status on failure, and the docs describe the failure and retry behavior.
2 Pass the repository ID (or its length) to the build pod so the updater works with any repository.id_length. ✅ Met The repository ID is passed through build creation into the pod’s REPOSITORYID environment variable, which the updater uses; pods without it retain the six-character fallback.
3 Fix string splitting for repository URLs, deployment file paths, and Docker Hub credentials. ✅ Met Clones use clone_directory() to derive a safe name from the URL, the pod name uses the explicit build ID, and credentials split at the first colon.

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

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

## Individual Comments

### Comment 1
<location path="pubgrade/modules/endpoints/builds.py" line_range="1331-1337" />
<code_context>
         raise InternalServerError from None
+    # GitHub accepts a dispatch with 204; anything else (e.g., a 401 for a
+    # wrong token, a 404 for a wrong `gh_action_path`) triggers no workflow
+    if response.status_code != 204:
+        logger.error(
+            "Triggering the signing of %s failed: GitHub answered %s",
+            push_tag,
+            response.status_code,
+        )
+        raise InternalServerError
</code_context>
<issue_to_address>
**Overlapping reports corrupt completion**

When two completion callbacks for the same build overlap, `build_completed` lets both callbacks pass the token check and update the build to `SUCCEEDED`, so both can dispatch signing and notify subscriptions, duplicating workflows and notifications. If both dispatches fail, the rollback race leaves the build appearing successful even though signing never started.

Atomically claim completion before dispatching side effects, and make rollback conditional on that claim.
</issue_to_address>

### Comment 2
<location path="pubgrade/modules/endpoints/builds.py" line_range="1331-1337" />
<code_context>
         raise InternalServerError from None
+    # GitHub accepts a dispatch with 204; anything else (e.g., a 401 for a
+    # wrong token, a 404 for a wrong `gh_action_path`) triggers no workflow
+    if response.status_code != 204:
+        logger.error(
+            "Triggering the signing of %s failed: GitHub answered %s",
+            push_tag,
+            response.status_code,
+        )
+        raise InternalServerError
</code_context>
<issue_to_address>
**Rejected dispatches retry without backoff**

When gitHub continues rejecting dispatches, for example because the token or action path is invalid, `build_completed` restores the build's previous status after this rejection, and the updater reports the still-succeeded pod again every five seconds. A persistent GitHub rejection therefore generates repeated dispatch requests and error logs for every affected build until the setting is fixed or the build is canceled.

Add a bounded or backoff-based retry policy for persistently rejected dispatches.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 2 findings to address first, and a non-204 GitHub response puts the build back into a state that causes another signing dispatch, so a dispatch that took effect despite an error response could launch duplicate external workflows; reverting cannot undo workflows already launched. The new repository ID also determines where a build report is sent, so a propagation error could update the wrong repository’s build record.

Blocking findings: pubgrade/modules/endpoints/builds.py:1337, pubgrade/modules/endpoints/builds.py:1337


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

Comment thread pubgrade/modules/endpoints/builds.py Resolved
Comment thread pubgrade/modules/endpoints/builds.py Resolved
@uniqueg
uniqueg merged commit 953d24e into dev Nov 9, 2026
56 of 59 checks passed
@uniqueg
uniqueg deleted the fix/94-build-steps branch November 9, 2026 21:38
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.

fix: check the steps of builds

2 participants