Skip to content

CI: check out private legs with SHAPE_LEGS_TOKEN, degrade clearly without it - #7

Merged
brettheap merged 1 commit into
mainfrom
fix/private-leg-checkout
Sep 3, 2026
Merged

brettheap merged 1 commit into
mainfrom
fix/private-leg-checkout

Conversation

@brettheap

@brettheap brettheap commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Observed failure

On the first real adoption (MedxSoft/MedxEHR #7), the assembly root's
.github/workflows/validate.yml — materialized from
templates/assembly-root/.github/workflows/validate.yml and digest-pinned
as a copied shape file in contracts/shape-pin.yaml — does actions/checkout
with submodules: true. MedxEHR-spec/MedxEHR-code are private sibling
repositories; the default GITHUB_TOKEN cannot clone them, so checkout
itself fails and the required validate check is red on every pull request
of a project with private legs.

Mechanism of the fix

  1. actions/checkout now passes
    token: ${{ secrets.SHAPE_LEGS_TOKEN || github.token }} and never fetches
    submodules itself (submodules: false) — a fine-grained PAT or GitHub App
    installation token with contents:read on the legs, falling back to the
    default token for public-legs projects.
  2. A new fetch the legs (submodules) step attempts
    git submodule update --init --recursive (reusing the credential
    actions/checkout persisted), with its failure captured rather than let
    through as a step failure. It sets legs_available and, on failure,
    prints a clear notice naming SHAPE_LEGS_TOKEN and the leg URLs.
  3. The naming and manifest validators always run (neither reads a leg's
    working tree). The lockstep pin validator — which recomputes each leg's
    tree digest and needs the legs actually checked out — runs only when
    legs_available == 'true'; otherwise a warning annotation explains the
    skip.
  4. The job fails only when SHAPE_LEGS_TOKEN is set and the fetch still
    failed — an absent secret degrades quietly on a private-legs project that
    hasn't configured one yet; a present, misconfigured one must not.

The secret

SHAPE_LEGS_TOKEN — a repository or organisation secret, a fine-grained
PAT or GitHub App installation token with contents:read on the legs.
Documented in both README.md and templates/assembly-root/README.md;
scaffold-project.py and adopt-project.py execute now print a one-line
reminder when they create a private or internal leg.

Tests

Added a template-render test asserting the exact token expression and every
guarded step exist (string/YAML-structure assertions, no live run), and
updated the pre-existing submodule-checkout assertion for the new structure.

231 passed in 53.22s

Nothing else was bumped — the workflow's actions stay pinned exactly as they
were (actions/checkout@v4, actions/setup-python@v5).

🤖 Generated with Claude Code

https://claude.ai/code/session_01HGKwdQsmvRZx4fGQESdFGZ

Summary by Sourcery

Make validation workflows handle private or internal leg repositories gracefully while requiring configured credentials to work correctly.

New Features:

  • Support authenticated checkout of private or internal leg repositories through the optional SHAPE_LEGS_TOKEN secret.
  • Allow validation workflows to continue with naming and manifest checks when leg submodules are unavailable, while clearly reporting skipped pin validation.

Bug Fixes:

  • Prevent private-leg projects from failing immediately during actions/checkout because the default GITHUB_TOKEN cannot access sibling repositories.
  • Fail explicitly when a configured SHAPE_LEGS_TOKEN cannot fetch the legs, avoiding silent misconfiguration.

Enhancements:

  • Document SHAPE_LEGS_TOKEN requirements and emit setup reminders when creating private or internal legs.

CI:

  • Update template workflow tests to verify token handling, best-effort submodule fetching, validation guards, and failure behavior.

Documentation:

  • Document private and internal leg authentication and workflow degradation behavior in the root and assembly-root READMEs.

Tests:

  • Add structural assertions covering the authenticated checkout and guarded validation workflow steps.

…hout it

The assembly root's validate.yml did `actions/checkout` with
`submodules: true`, so a private-legs project's required check hard-fails
in checkout itself the instant a leg cannot be cloned with the default
GITHUB_TOKEN — observed on the first real adoption (MedxSoft/MedxEHR #7),
where `MedxEHR-spec`/`MedxEHR-code` are private siblings.

Checkout now passes `token: ${{ secrets.SHAPE_LEGS_TOKEN || github.token }}`
and never fetches submodules itself. A new failure-capturing step attempts
`git submodule update --init --recursive`, sets `legs_available`, and
prints a clear notice naming the secret and the leg URLs on failure. The
naming and manifest validators always run; the lockstep pin validator
(which needs the legs' trees) runs only when legs_available=true, otherwise
a warning annotation explains the skip. The job fails only when
SHAPE_LEGS_TOKEN is set and the fetch still failed — misconfiguration must
not be silent.

Documents the SHAPE_LEGS_TOKEN requirement in both READMEs, and has
scaffold-project.py / adopt-project.py execute print a one-line reminder
when they create private or internal legs. Adds a template-render test
asserting the token expression and every guarded step, updates the
pre-existing submodule-checkout test for the new structure, and bumps the
README line cap (245 -> 265) for the added section.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HGKwdQsmvRZx4fGQESdFGZ
Copilot AI lite review requested due to automatic review settings September 3, 2026 04:32

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

Sorry @brettheap, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 12 hours and 32 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Sep 3, 2026

Copy link
Copy Markdown

Reviewer's Guide

Updates the generated validation workflow to use SHAPE_LEGS_TOKEN for private submodules, capture fetch failures, preserve checks that do not require leg working trees, and clearly distinguish absent-secret degradation from misconfigured-secret failure; documentation, project-creation reminders, and structural tests are updated accordingly.

Sequence diagram for validation with private leg checkout

sequenceDiagram
    participant GitHub as GitHub Actions
    participant Checkout as actions/checkout
    participant Git as Git submodules
    participant Checks as Naming and manifest validators
    participant Pins as Lockstep pin validator

    GitHub->>Checkout: checkout(token: SHAPE_LEGS_TOKEN || github.token, submodules: false)
    Checkout-->>GitHub: Persist resolved credential
    GitHub->>Git: git submodule update --init --recursive
    alt legs fetched
        Git-->>GitHub: legs_available=true
        GitHub->>Checks: Run naming policy and project manifest
        GitHub->>Pins: Run validate-pins.py
    else legs unavailable
        Git-->>GitHub: legs_available=false and warning with leg URLs
        GitHub->>Checks: Run naming policy and project manifest
        GitHub->>GitHub: Warn and skip lockstep pins
        alt SHAPE_LEGS_TOKEN is set
            GitHub-->>GitHub: Fail job for token misconfiguration
        else SHAPE_LEGS_TOKEN is absent
            GitHub-->>GitHub: Degrade without failing
        end
    end
Loading

Flow diagram for validation failure handling

flowchart TD
    A[Checkout repository without submodules] --> B[Fetch submodules with persisted credential]
    B -->|Success| C[Run naming and manifest checks]
    C --> D[Run lockstep pin validator]
    B -->|Failure| E[Emit warning with SHAPE_LEGS_TOKEN guidance and leg URLs]
    E --> C
    C --> F[Skip lockstep pin validator with warning]
    F --> G{SHAPE_LEGS_TOKEN is set?}
    G -->|No| H[Pass with degraded validation]
    G -->|Yes| I[Fail for misconfigured token]
Loading

File-Level Changes

Change Details Files
Make assembly-root validation authenticate and fetch submodules separately, with explicit degradation and failure behavior for unavailable private legs.
  • Pass SHAPE_LEGS_TOKEN to checkout with the default token as a public-legs fallback, while disabling checkout-managed submodules.
  • Add a failure-capturing recursive submodule fetch that records leg availability and emits token guidance plus leg URLs.
  • Always run naming and manifest validation; condition lockstep pin validation on successful leg availability and warn when skipped.
  • Fail only when a configured SHAPE_LEGS_TOKEN cannot fetch the legs.
templates/assembly-root/.github/workflows/validate.yml
Document the SHAPE_LEGS_TOKEN requirement and degraded validation behavior for private or internal legs.
  • Describe the required secret type and contents:read permissions.
  • Explain the absent-secret degradation path and configured-secret failure path.
  • Add the guidance to both repository and generated assembly-root documentation.
README.md
templates/assembly-root/README.md
Surface the credential requirement during project creation when private or internal leg repositories are created.
  • Print a one-line SHAPE_LEGS_TOKEN reminder after creating private or internal legs.
  • Avoid the reminder for local projects and public legs.
scaffold-project.py
adopt-project.py
Extend template and hygiene tests to verify the new workflow structure and documentation size.
  • Assert the exact checkout token expression, separate submodule fetch, availability guards, warning step, and configured-token failure condition.
  • Update the existing submodule checkout expectation to reject checkout-managed submodules and require the manual fetch.
  • Increase the README line cap to accommodate the new documentation.
tests/test_scaffold_e2e.py
tests/test_repo_hygiene.py

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

@sonarqubecloud

sonarqubecloud Bot commented Sep 3, 2026

Copy link
Copy Markdown

@brettheap
brettheap merged commit c2622e1 into main Sep 3, 2026
4 checks passed

Copilot AI 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.

🟡 Changes recommended

The new workflow’s “best-effort” submodule failure path can still fail the job under default runner bash -o pipefail, and one of the updated workflow assertions in tests is currently ineffective due to indentation mismatches.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Updates the assembly-root validation workflow template to handle projects whose “leg” repositories (spec/code) are private/internal by authenticating submodule fetches via an optional SHAPE_LEGS_TOKEN, and by degrading gracefully when that secret is absent.

Changes:

  • Update templates/assembly-root/.github/workflows/validate.yml to (a) pass token: ${{ secrets.SHAPE_LEGS_TOKEN || github.token }} to checkout, (b) fetch submodules in a best-effort step, and (c) guard pin validation / fail only on misconfigured secrets.
  • Add/adjust tests to assert the rendered workflow structure (token expression, guarded steps, and new submodule-fetch step).
  • Document SHAPE_LEGS_TOKEN in both root and assembly-root READMEs, and print a reminder from scaffold/adopt flows when creating private/internal legs.
File summaries
File Description
tests/test_scaffold_e2e.py Updates and adds assertions that the rendered validate workflow uses the token fallback and guarded pin checks.
tests/test_repo_hygiene.py Increases the README line cap with a dated rationale tied to the new documentation.
templates/assembly-root/README.md Documents why/when SHAPE_LEGS_TOKEN is needed and how validation degrades without it.
templates/assembly-root/.github/workflows/validate.yml Implements token fallback checkout, best-effort submodule fetch, guarded pin validation, and conditional failure on misconfigured secrets.
scaffold-project.py Prints a reminder about configuring SHAPE_LEGS_TOKEN when legs are created private/internal.
README.md Adds project-level documentation for SHAPE_LEGS_TOKEN and validation workflow behavior.
adopt-project.py Prints a reminder about configuring SHAPE_LEGS_TOKEN when adoption creates private/internal legs.
Review details
  • Files reviewed: 7/7 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +53 to +56
echo "::warning::submodule checkout failed (git exit $status). If the legs are PRIVATE or internal sibling repositories, the default GITHUB_TOKEN cannot read them. Set SHAPE_LEGS_TOKEN — a fine-grained PAT or GitHub App installation token with contents:read on the legs — as a repository or organisation secret. Leg URLs:"
git config --file .gitmodules --get-regexp '\.url$' | while read -r _ url; do
echo "::warning:: $url"
done
# defect: it hard-fails the whole job the instant a private leg cannot
# be cloned. The fetch is now a separate, failure-capturing step; only
# the checkout step itself must not carry the old setting.
assert "with:\n submodules: true" not in workflow
Comment on lines +329 to +337
lines = workflow.splitlines()
start = next(i for i, line in enumerate(lines) if marker in line)
# walk back to the start of this step (` - ` at 6-space indent)
while not lines[start].startswith(" - "):
start -= 1
end = start + 1
while end < len(lines) and not lines[end].startswith(" - "):
end += 1
return "\n".join(lines[start:end])
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.

2 participants