Skip to content

pin-github-actions: check pins by parsing YAML, and fail closed on aliases - #4

Merged
caseymanos merged 4 commits into
mainfrom
casey/pin-check-parse-yaml
Nov 13, 2026
Merged

caseymanos merged 4 commits into
mainfrom
casey/pin-check-parse-yaml

Conversation

@caseymanos

@caseymanos caseymanos commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

The bundled check_pins.py matched uses: lines with a regex, so valid YAML could carry an unpinned action past it. This replaces it with check-action-pins.mjs, which parses the YAML.

Expected vs actual

Expected: any uses that GitHub will run, and that isn't a full SHA (or an image digest for docker://), fails the check.

Actual with check_pins.py, each of these passed:

jobs:
  a:
    runs-on: ubuntu-latest
    steps:
      - { uses: actions/checkout@v4 }            # flow-style step
      - "uses": actions/setup-node@v4            # quoted key
      - uses: >-                                 # ref on the next line
          actions/cache@v4
      - &dl { uses: actions/download-artifact@v4 }
  b:
    runs-on: ubuntu-latest
    steps:
      - *dl                                      # step reused by alias
      - <<: { uses: actions/upload-artifact@v4 } # merge key
        with: {}

On this file, check_pins.py reported one finding, >-, as if it were the ref, and caught none of the six. check-action-pins.mjs reports all six. It also stops flagging uses: text inside run: scripts.

The change

  • New checker. scripts/check-action-pins.mjs parses each workflow and action.yml with yaml, and reads uses only where GitHub does: jobs.<id>.uses, jobs.<id>.steps[].uses and runs.steps[].uses.
  • Fails closed. Inside jobs or runs, an alias, a merge key or a non-string uses fails the check instead of being expanded. Expanding them only works if our parser expands them exactly as GitHub's does, and a mismatch is a bypass.
  • Tests. scripts/check-action-pins.test.mjs has 13 tests using node:test, covering each form above plus reusable workflows, docker:// digests and composite actions.
  • SKILL.md.
    • "Keep it pinned" now leads with GitHub's Actions policy that requires full-length SHA pins. GitHub enforces it while reading the workflow, so no YAML form gets past it. The repo check stays for pull-request feedback where no admin can turn the policy on.
    • Copy the checker and its tests and run it in CI. yaml comes from the repo's dev dependencies, or is installed in the CI step when there's no package.json; GitHub-hosted runners include Node.
    • Version bumped 0.1.0 → 0.2.0.
  • This repo's CI. The pin check now runs after the install diff, with yaml@2.9.1 installed using --ignore-scripts, plus the tests.

Trade-off: the checker is no longer standard-library-only. A YAML parser is the minimum needed to read uses the way GitHub does.

Checks

  • On examples/pin-a-workflow.md, the old and new checkers report the same four refs, and both skip the local ./ action.
  • node --test: 13 passed.
  • npx skills@1.7.6 add . --list lists both skills. Installed copies for Claude Code and Codex match the source.
  • The documented example, run in fresh Claude Code and Codex sessions with 0.2.0: both pinned the same SHAs as the earlier replay and added the checker with a CI step that installs yaml. The check failed before pinning and passed after. Recorded in examples/pin-a-workflow.md.

Rollback is a revert of this PR.

…iases

The bundled check_pins.py matched uses: lines, so flow-style steps, quoted keys,
multi-line refs and refs behind YAML aliases or merge keys passed unpinned.
adaptcom[bot]
adaptcom Bot previously approved these changes Nov 13, 2026
GitHub enforces it while reading the workflow itself, so no YAML form gets past it.
The repo check stays for pull-request feedback where no admin can turn the policy on.
Casey Manos added 2 commits November 13, 2026 08:35
A repo without Node fell through to 'use zizmor', which an agent treated as a new
tool and skipped, so no check was added. Runners have Node; install yaml in the step.
@caseymanos
caseymanos merged commit 1f83835 into main Nov 13, 2026
2 checks passed
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.

1 participant