Skip to content

Fix: Scope cache to path_prefix and use actions/attest - #277

Merged
ModeSevenIndustrialSolutions merged 2 commits into
lfreleng-actions:mainfrom
modeseven-lfreleng-actions:fix/cache-path-prefix-and-attest
Oct 1, 2026
Merged

ModeSevenIndustrialSolutions merged 2 commits into
lfreleng-actions:mainfrom
modeseven-lfreleng-actions:fix/cache-path-prefix-and-attest

Conversation

@ModeSevenIndustrialSolutions

@ModeSevenIndustrialSolutions ModeSevenIndustrialSolutions commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Closes #273
Closes #249

Commits

Commit Subject Issue
7c1bb31 Fix(cache): Scope key and paths to path_prefix #273
7f819cb Chore: Migrate to actions/attest #249

The two commits are independent: each closes one issue, and they change
different steps of action.yaml.

#273: Cache key and paths ignore path_prefix

Problem

The Cache Python dependencies step was the only step in the action that
ignored path_prefix:

  • Key: **/ patterns hashed dependency files across the whole
    workspace, so unrelated projects, fixtures, and even files inside the
    cached .tox directory changed it. tox.ini, which governs the .tox
    contents, was missing.
  • Paths: .tox and .venv were relative to the workspace root, but
    tox --root "$path_prefix" creates .tox under path_prefix. For any
    project in a subdirectory, the tox environments were never saved or
    restored.

I confirmed the key problem with the runner's own hashFiles() matching
(@actions/glob 0.7.0, the version actions/runner bundles), against a
fixture workspace with project sub/ beside an unrelated other/:

Patterns Files hashed
Before other/pyproject.toml, other/setup.py, pyproject.toml, sub/.tox/build/pyproject.toml, sub/docs/requirements.txt, sub/pyproject.toml, sub/requirements*.txt, sub/setup.cfg
After sub/pyproject.toml, sub/requirements-dev.txt, sub/requirements.txt, sub/setup.cfg, sub/tox.ini

Fix

A new script, scripts/cache-paths.sh, runs as the
Derive cache locations from path_prefix step and emits both cache
inputs:

  • tox_path, the project's .tox as an actions/cache path.
    actions/cache reads path as @actions/glob patterns
    (resolvePaths()), so the path has to match that directory and nothing
    else. It is:
    • canonical and relative to the workspace. sub, sub/, ./sub,
      x/../sub, an absolute path and a path through a symlink all become
      ./sub/.tox. No . or .. segment reaches @actions/glob, which
      rejects those outright. Each directory also gets one cache version,
      because actions/cache versions entries by the literal path strings
      (getCacheVersion()).
    • anchored with ./, so a leading ! or # is not read as a
      negation or a comment.
    • escaped as @actions/glob's own Pattern.globEscape() does it
      (\, [, ?, *), so glob[1] cannot match glob1.
  • deps_hash, a SHA-256 over the project's pyproject.toml,
    setup.py, setup.cfg, requirements*.txt and tox.ini, computed in
    the script. hashFiles() doesn't fit here: it reads its arguments as
    glob patterns too, and it skips every file outside GITHUB_WORKSPACE.
    For a project there, the key would never change.

The script resolves directories with cd -P and reads $PWD, not
$(pwd). That way a symlink on either side cannot defeat the workspace
comparison, and command substitution cannot strip a trailing newline,
which would turn a directory named project\n into the unrelated
project. A path containing CR or LF fails the step, because either
would split the pattern list and the step's output file. Outputs are
written with printf, not echo: under an inherited xpg_echo shell
option (BASHOPTS=xpg_echo), echo would expand the backslashes the
escaping adds.

Also:

  • Cache paths are now ~/.cache/pip and the project's .tox. .venv,
    ~/.cache/pypoetry and ~/.cache/pipenv are gone: nothing in the
    action creates them.
  • runner.arch is now in the key and the restore keys, so x64 and arm64
    runners on the same OS no longer share architecture-specific tox
    environments. (python-audit-action already does this.)

Tests

tests/test_cache_paths.sh (plain bash, in the style of
nexus-publish-action/tests/test_publish.sh) has 13 tests. A new
Test cache path derivation job runs it; it needs no repository
variables, so it also runs on fork PRs. It covers:

  • root and equivalent spellings: one path and one hash
  • resolution relative to the working directory
  • a workspace and a project given through symlinks
  • glob[1], a*b, a?b and a backslash beside their decoys, for both
    path and hash
  • leading ! and #
  • hash sensitivity: each dependency file counts; unrelated projects,
    nested files and .tox contents don't
  • a project with no dependency files
  • a project outside the workspace, whose hash still changes with its
    files
  • line breaks (project\n, pro\nject, project\r): rejected, with
    nothing written to the step output
  • an inherited CDPATH
  • the escaping checks repeated under an inherited xpg_echo

Impact

The changed paths give the cache a new version, so existing entries will
not restore. The first run on each branch repopulates them. The key
format also changes, from python-<os>-<py>-… to
python-<os>-<arch>-<py>-…. That matters only to anyone filtering on it
with the Clear Action Cache 🧹 workflow's key_pattern input.

#249: Migrate from attest-build-provenance to attest

A like-for-like swap of the uses: line:

-      uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
+      uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2
  • I read the wrapper's action.yml at the old pin. It forwards every
    input to actions/attest unchanged. With no predicate-type or
    predicate, actions/attest emits SLSA build provenance by default, so
    the output does not change.
  • The wrapper also sets NODE_OPTIONS: --max-http-header-size=32768, as
    this issue's follow-up comment notes. That only matters for
    push-to-registry, which this action never sets, so nothing needs
    carrying across.
  • subject-path and the caller's id-token: write and
    attestations: write permissions are unchanged.
  • I checked that 1e69f48 is a commit SHA, not a tag object
    (GET /repos/actions/attest/git/ref/tags/v4.2.2 → type: commit). It
    is the same pin lfreleng-actions/node-workflows#57 adopted.

SBOM attestation (sbom-path), which the issue mentions as optional, is
left for its own issue to keep this change atomic.

Validation

  • bash tests/test_cache_paths.sh: all 13 tests pass, under bash 5.3
    and under bash 3.2 (the macOS system shell).
  • Mutation check. I broke scripts/cache-paths.sh 12 ways in a
    scratch copy, one at a time: dropping the escaping (all of it, or [
    or * alone), the ./ anchor, the line-break check, -P, the CDPATH
    guard, or the workspace-root case; capturing the path with $(pwd);
    leaving tox.ini or requirements*.txt out of the hash; and hashing
    from the workspace. The suite caught all 12. Separately, the
    xpg_echo test fails against the earlier echo version of the
    script, on exactly the back\slash assertion.
  • Fed every tox_path string the tests assert through @actions/glob
    0.7.0, in a workspace with decoys (glob1, axb, bang,
    backslash). Each matched exactly its own .tox.
  • Read @actions/cache getCacheVersion() and resolvePaths(), and the
    runner's hashFiles.ts, to confirm literal-path versioning, glob
    handling of path, and that hashFiles() skips files outside the
    workspace.
  • prek run --files on each commit's files: passed, including
    shellcheck and reuse on the new scripts.
  • zizmor --persona auditor action.yaml .github/workflows/testing.yaml:
    no findings.
  • aislop-gate.sh upstream/main: clean (5 files gated).

Not covered by CI on this PR: attestation needs id-token: write and a
real artefact build, which the fork-PR test job does not have.

Copilot AI balanced review requested due to automatic review settings October 1, 2026 10:21
@github-actions github-actions Bot added the bug Something isn't working label Oct 1, 2026

This comment was marked as resolved.

Copilot AI balanced review requested due to automatic review settings October 1, 2026 10:40
@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions force-pushed the fix/cache-path-prefix-and-attest branch from 853aad1 to 2515ce4 Compare October 1, 2026 10:40

This comment was marked as resolved.

Copilot AI balanced review requested due to automatic review settings October 1, 2026 10:46
@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions force-pushed the fix/cache-path-prefix-and-attest branch from 2515ce4 to 918f801 Compare October 1, 2026 10:46

This comment was marked as resolved.

Copilot AI balanced review requested due to automatic review settings October 1, 2026 10:59
@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions force-pushed the fix/cache-path-prefix-and-attest branch from 918f801 to aa74f21 Compare October 1, 2026 10:59

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.

Copilot review overview

🟢 Approval recommended

The cache behavior is comprehensively tested, and the attestation migration preserves the existing inputs and provenance behavior.

Review effort: Balanced
Findings: None

Resolved since last review (2)

@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions marked this pull request as ready for review October 1, 2026 11:04
@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions requested a review from a team October 1, 2026 11:04
@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions marked this pull request as draft October 1, 2026 11:05
@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions marked this pull request as ready for review October 1, 2026 14:35
@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions force-pushed the fix/cache-path-prefix-and-attest branch 2 times, most recently from aa74f21 to b47db11 Compare October 1, 2026 14:39

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.

Copilot review overview

🟡 Changes recommended

Cache output can be corrupted when Bash inherits backslash-expanding echo behavior.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)

Comment thread scripts/cache-paths.sh Resolved
The cache step ignored path_prefix. Its key hashed dependency files
across the whole workspace, so unrelated projects, fixtures and even
files inside the cached .tox directory changed it, while tox.ini, which
governs the .tox contents, was missing. Its .tox and .venv paths were
relative to the workspace root, but tox --root <path_prefix> creates
.tox under path_prefix, so for any project in a subdirectory the tox
environments were never saved or restored.

Add scripts/cache-paths.sh, which derives both cache inputs from
path_prefix:

- tox_path, the project's .tox as an actions/cache path. actions/cache
  reads path as @actions/glob patterns, so it is canonical and relative
  to the workspace (no "." or ".." segment trips the matcher, and each
  directory gets one cache version), anchored with "./" so a leading
  "!" or "#" stays literal, and escaped as globEscape() does so a
  directory named glob[1] cannot match glob1.
- deps_hash, a SHA-256 over the project's pyproject.toml, setup.py,
  setup.cfg, requirements*.txt and tox.ini. hashFiles() does not fit:
  it also reads its arguments as glob patterns, and it skips every
  file outside GITHUB_WORKSPACE, which would freeze the key for a
  project there.

The script resolves directories with cd -P and reads PWD, so a
symlink cannot defeat the workspace comparison and no command
substitution strips a trailing newline from the name. It rejects a
path containing a line break, which would split the pattern list and
the step output, and writes its outputs with printf, because echo
would expand the escaping's backslashes under an inherited xpg_echo.

Drop .venv, ~/.cache/pypoetry and ~/.cache/pipenv, which nothing in the
action creates, and poetry.lock and Pipfile* from the key. Add
runner.arch to the key and restore keys, so x64 and arm64 runners on
the same OS stop sharing architecture-specific tox environments.

tests/test_cache_paths.sh covers equivalent spellings, glob and leading
"!" or "#" names beside decoys, symlinked paths, a project outside the
workspace, line breaks, and an inherited CDPATH or xpg_echo. A new job
in the testing workflow runs it.

The new paths give the cache a new version, so existing entries will
not restore; the first run on each branch repopulates them.

Reported in lfreleng-actions#273.

Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Matthew Watkins <mwatkins@linuxfoundation.org>
As of v4, actions/attest-build-provenance is a thin composite wrapper
around actions/attest, and GitHub advises new implementations to use
actions/attest directly. The wrapper forwards every input unchanged;
with no predicate inputs, actions/attest emits SLSA build provenance,
so the attestations this action produces do not change.

The wrapper also sets NODE_OPTIONS to raise node's HTTP header limit,
which matters only when pushing attestations to an OCI registry. This
action never sets push-to-registry, so nothing needs carrying across.
The subject-path input and the caller's id-token: write and
attestations: write permissions stay as they are.

Pin 1e69f48 is v4.2.2 of actions/attest, verified as a commit object
rather than an annotated tag, matching lfreleng-actions/node-workflows.

Reported in lfreleng-actions#249.

Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Matthew Watkins <mwatkins@linuxfoundation.org>
Copilot AI balanced review requested due to automatic review settings October 1, 2026 14:47
@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions force-pushed the fix/cache-path-prefix-and-attest branch from b47db11 to 7f819cb Compare October 1, 2026 14:47

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.

Copilot review overview

🟢 Approval recommended

The changes satisfy both linked issues with focused implementation, strong edge-case coverage, and verified action pinning.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@zxiiro zxiiro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Auto-approved by agent: reviewed workflow/code change for security and CI/CD impact, found low risk. Scopes pip/.tox cache to path_prefix via a hardened cache-paths.sh (glob-escapes, rejects newlines) and swaps attest-build-provenance for actions/attest at a pinned SHA; no widened permissions.

@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions merged commit 3cdb6f8 into lfreleng-actions:main Oct 1, 2026
12 checks passed
@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions deleted the fix/cache-path-prefix-and-attest branch October 2, 2026 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Cache key and paths ignore path_prefix Chore: Migrate from attest-build-provenance to attest

3 participants