Skip to content

Scope ${GITHUB_*} → ${{github.*}} rewrite to non-run: contexts#384

Merged
ydesgagn merged 2 commits into
masterfrom
update-20260515-010519
May 15, 2026
Merged

Scope ${GITHUB_*} → ${{github.*}} rewrite to non-run: contexts#384
ydesgagn merged 2 commits into
masterfrom
update-20260515-010519

Conversation

@ydesgagn
Copy link
Copy Markdown
Contributor

@ydesgagn ydesgagn commented May 15, 2026

Summary

The workflow writer was running a blanket regex substitution across the entire rendered YAML, rewriting every ${GITHUB_*} into the GitHub expression form ${{github.*}}. That rewrite is correct for env:, if:, with:, concurrency:, run-name:, etc. (where ${GITHUB_*} is not shell-expanded and the canonical expression form is required), but wrong inside shell run: blocks: there ${GITHUB_*} is the env-var syntax the runner actually exports, while ${{github.*}} is opaque to shellcheck and trips SC2193.

Instead of removing the translation outright (the first attempt — which broke env: values that have no other way to interpolate github.* context), this scopes it: we walk the parsed YAML tree before serialization and skip values whose enclosing key is run. Every other context still gets the canonical ${{github.*}} form.

Key changes:

  • Replace the blanket-string gsub! in Workflow#write with a recursive rewrite_github_refs helper that walks the hash/array structure and applies the regex only to non-run: string values
  • Extract the regex to a private_constant (GITHUB_ENV_VAR_REGEX)
  • Update the existing ${GITHUB_*}${{github.*}} spec (env: context, still translated) and add a new spec verifying ${GITHUB_*} inside step run: bodies is preserved verbatim

Types of changes

  • Bugfix (fixes an issue)
  • New feature (adds functionality)
  • Refactoring (improves code without changing functionality)
  • Breaking change (incompatible changes)
  • Build or security update (updates dependencies, libraries, or security patches)
  • Code style or documentation update (formatting, renaming, or documentation changes)
  • Other (please describe):

Checklist

  • Unit tests added to validate my fix/feature
  • I have manually tested my change
  • I did not add automation test. Why ?:
  • Database changes requiring migration with downtime or reprocessing of existing data
  • The SOUP file lists the risk Level, requirements and verification reasoning associated with each library
  • `readme.md` includes sections on introduction, installation, usage, and contributing
  • `docs/architecture.md` includes sections on the architecture diagram, software units, software of unknown provenance, critical algorithms and risk controls related to PII and security
  • Impact on PII, privacy regulations (CCPA/GDPR/PIPEDA), CIS benchmarks or security (availability/confidentiality/integrity); management must be notified

@ydesgagn ydesgagn requested a review from a team as a code owner May 15, 2026 01:06
@ydesgagn ydesgagn enabled auto-merge (squash) May 15, 2026 01:06
Previously the workflow writer applied a blanket regex substitution
across the rendered YAML, which:

- Translated ${GITHUB_*} in shell `run:` bodies, where the env-var form
  is the runner-exported syntax shellcheck expects (the ${{github.*}}
  form is opaque to shellcheck and trips SC2193), and
- Was still needed for env:/if:/with:/concurrency:/run-name: values,
  where ${GITHUB_*} is *not* shell-expanded and the canonical
  expression form is required.

Walk the parsed YAML tree before serialization and only rewrite values
whose enclosing key is not `run`. Shell bodies stay verbatim; every
other context still gets the canonical ${{github.*}} form.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ydesgagn ydesgagn changed the title Stop rewriting ${GITHUB_*} env vars to ${{github.*}} in workflows Scope ${GITHUB_*} → ${{github.*}} rewrite to non-run: contexts May 15, 2026
@ydesgagn ydesgagn merged commit 603ba91 into master May 15, 2026
27 checks passed
@ydesgagn ydesgagn deleted the update-20260515-010519 branch May 15, 2026 01:18
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