Repository navigation
CI: the secrets context is not allowed in a step if; test for it - #8
Conversation
The copied `.github/workflows/validate.yml` was REJECTED by GitHub on the first real projects (MedxSoft/MedxEHR PR #8, MedxSoft/MedxGlass PR #1): "This run likely failed because of a workflow file issue", a push-event run with zero jobs. Cause: the step `fail — SHAPE_LEGS_TOKEN is set but the legs still could not be fetched` had `if: ... && secrets.SHAPE_LEGS_TOKEN != ''` — the `secrets` context is not available in a step-level `if:` expression ("unrecognized named-value 'secrets'"), so GitHub cannot parse the workflow file at all. Fix: add a job-level `env: SHAPE_LEGS_TOKEN_SET: ${{ secrets.SHAPE_LEGS_TOKEN != '' }}` (the `secrets` context IS allowed in `env:`) and change the step condition to `if: ... && env.SHAPE_LEGS_TOKEN_SET == 'true'`. The checkout step's `token: ${{ secrets.SHAPE_LEGS_TOKEN || github.token }}` is unchanged (allowed in `with:`). - Updated the existing rendered-workflow assertion in tests/test_scaffold_e2e.py for the new step condition, and added test_no_if_expression_reads_the_secrets_context, which walks every `if:` line in the rendered workflow (not just the one step) asserting none contains `secrets.`, and that the job `env` carries `SHAPE_LEGS_TOKEN_SET`. - Added an actionlint step to .github/workflows/tests.yml (pinned release binary v1.7.12, sha256-verified, no pip/go required) that lints templates/assembly-root/.github/workflows/validate.yml — confirmed locally that it flags exactly this defect on the pre-fix file and passes clean on the fix. - Noted in both the aggregation README and the scaffolded-project template README that the SHAPE_LEGS_TOKEN presence check reads a job-level `env` value rather than the `secrets` context directly; bumped the README line cap 265 -> 267 (test_readme_is_short_enough_to_be_read) for the added sentence. python3 -m pytest tests -q: 232 passed. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01HGKwdQsmvRZx4fGQESdFGZ
There was a problem hiding this comment.
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 3 minutes by commenting @sourcery-ai review. Upgrade to get a review now.
Reviewer's GuideFixes the invalid use of the secrets context in a step-level GitHub Actions if expression by exposing a boolean through job-level env, adds broad regression tests and actionlint validation, and documents the constraint and workaround. Sequence diagram for the safe secret-presence check in workflow validationsequenceDiagram
participant GitHub as GitHub Actions
participant Job as validate job
participant Submodules as submodules step
participant Guard as failure guard
GitHub->>Job: Evaluate job env
Job->>Job: Read secrets.SHAPE_LEGS_TOKEN
Job-->>Job: Set env.SHAPE_LEGS_TOKEN_SET
Job->>Submodules: Fetch submodules
Submodules-->>Job: Set legs_available
Job->>Guard: Evaluate if using env.SHAPE_LEGS_TOKEN_SET
alt legs unavailable and token is set
Guard->>Guard: exit 1
end
Flow diagram for validating secrets usage in the rendered workflowflowchart TD
A[Render validate workflow] --> B[Walk every if expression]
B --> C{Contains secrets. context?}
C -- Yes --> D[Test fails]
C -- No --> E[Check job env has SHAPE_LEGS_TOKEN_SET]
E --> F{actionlint validates workflow}
F -- Pass --> G[Workflow is accepted by GitHub]
F -- Fail --> D
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
There was a problem hiding this comment.
🟢 Approval recommended
The workflow fix is targeted and regression-protected (tests + actionlint), with only minor follow-up nits identified.
Pull request overview
Fixes a GitHub Actions parsing failure in the scaffolded validate.yml by removing direct secrets.* access from step-level if: expressions, replacing it with a job-level env boolean, and adds regression checks + CI linting to prevent reintroduction.
Changes:
- Update the validate workflow template to compute
SHAPE_LEGS_TOKEN_SETat jobenv:scope and referenceenv.SHAPE_LEGS_TOKEN_SETin the guarded failure step. - Add end-to-end regression coverage ensuring rendered workflow
if:expressions don’t readsecrets.*, and adjust existing assertions accordingly. - Add checksum-verified
actionlintlinting in CI and update READMEs / hygiene caps to reflect the new rule.
File summaries
| File | Description |
|---|---|
templates/assembly-root/.github/workflows/validate.yml |
Moves the secret presence check to job-level env and updates the failing-step if: to use env.* instead of secrets.*. |
tests/test_scaffold_e2e.py |
Updates the token-guard assertion and adds a regression test scanning rendered workflow if: expressions for forbidden secrets.*. |
.github/workflows/tests.yml |
Adds an actionlint install + lint step to catch workflow-expression/context issues in CI. |
templates/assembly-root/README.md |
Documents the job-level env presence check and why step-level secrets in if: breaks parsing. |
README.md |
Updates the SHAPE_LEGS_TOKEN section to note the env-based presence check and the zero-job symptom. |
tests/test_repo_hygiene.py |
Updates the README line cap to accommodate the additional explanation. |
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| workflow = (project / ".github" / "workflows" / "validate.yml").read_text() | ||
|
|
||
| if_lines = [line for line in workflow.splitlines() | ||
| if line.lstrip().startswith("if:")] | ||
| assert if_lines, "expected at least one `if:` step condition" | ||
| for line in if_lines: | ||
| assert "secrets." not in line, ( | ||
| f"step-level `if:` must not read the `secrets` context: {line!r}") | ||
|
|
||
| assert "SHAPE_LEGS_TOKEN_SET" in workflow | ||
| # The job-level `env:` sits above `steps:` in the job block. | ||
| env_block = workflow.split("steps:", 1)[0] | ||
| assert "env:" in env_block | ||
| assert ("SHAPE_LEGS_TOKEN_SET: ${{ secrets.SHAPE_LEGS_TOKEN != '' }}" | ||
| in env_block) |
| # PINNED, checksum-verified, no `go install`/`pip` package exists for | ||
| # this: a static release binary downloaded straight from the tag this | ||
| # repository pins. This is what would have caught the `secrets`-in-a- | ||
| # step-`if:` defect (a rendered workflow file GitHub itself rejects as | ||
| # unparseable) before it ever reached a real project's pull request. |
Main gained the `secrets`-in-a-step-`if:` fix (#8) and the actionlint download hardening (#9) while this branch was written. The only conflict is the README line cap in tests/test_repo_hygiene.py, where both changes move it: 265 -> 267 for the SHAPE_LEGS_TOKEN paragraph's `env:` note, then 267 -> 324 for "Keeping a project's shape current". Both rationales are kept, because a cap whose reasons are dropped as it moves is not a cap. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01HGKwdQsmvRZx4fGQESdFGZ




Observed
The copied
.github/workflows/validate.ymlwas REJECTED by GitHub on thefirst real projects: MedxSoft/MedxEHR PR #8 and MedxSoft/MedxGlass PR #1.
GitHub reported "This run likely failed because of a workflow file issue"
and the check appears as a push-event run with zero jobs — the workflow
file could not be parsed at all, not merely one failing step.
Cause
In
templates/assembly-root/.github/workflows/validate.yml, the stepfail — SHAPE_LEGS_TOKEN is set but the legs still could not be fetchedhad:The
secretscontext is not available in a step-levelif:expression("unrecognized named-value 'secrets'"). GitHub's response to that is not a
red step — it is a workflow file GitHub cannot parse, so it never runs any
job for the event, which surfaces as a required check that never appears
rather than one that fails.
Fix
env: SHAPE_LEGS_TOKEN_SET: ${{ secrets.SHAPE_LEGS_TOKEN != '' }}— the
secretscontext is allowed inenv:.if: steps.submodules.outputs.legs_available != 'true' && env.SHAPE_LEGS_TOKEN_SET == 'true'.token: ${{ secrets.SHAPE_LEGS_TOKEN || github.token }}unchanged —
secretsis allowed inwith:.Tests
test_the_ci_workflow_checkout_uses_shape_legs_tokenfor the newstep condition.
test_no_if_expression_reads_the_secrets_context, which walksevery
if:line in the rendered workflow (not just the one step thatbroke) asserting none contains
secrets., and that the jobenvcarriesSHAPE_LEGS_TOKEN_SET.actionlintstep to.github/workflows/tests.yml(pinnedrelease binary v1.7.12, sha256-verified — no
pip/goneeded) that lintstemplates/assembly-root/.github/workflows/validate.yml. Verified locallythat it flags exactly this defect on the pre-fix file and passes clean on
the fix.
template) that the presence check is a job-level
envvalue, not thesecretscontext directly.python3 -m pytest tests -q: 232 passed.🤖 Generated with Claude Code
https://claude.ai/code/session_01HGKwdQsmvRZx4fGQESdFGZ
Summary by Sourcery
Prevent GitHub from rejecting generated validation workflows by moving secret presence checks out of step-level conditions and linting the workflow in CI.
Bug Fixes:
Enhancements:
CI:
Documentation:
Tests: