@htekdev/actions-debugger 1.0.104 → 1.0.105
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/errors/caching-artifacts/cache-primary-key-prefix-matching-undocumented.yml +104 -0
- package/errors/concurrency-timing/batch-workflow-dispatch-static-concurrency-silent-cancel.yml +137 -0
- package/errors/runner-environment/sparse-checkout-persists-self-hosted-cross-run.yml +99 -0
- package/errors/yaml-syntax/hashfiles-newline-delimiter-returns-empty.yml +99 -0
- package/package.json +1 -1
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
id: caching-artifacts-060
|
|
2
|
+
title: 'actions/cache Primary key Uses Undocumented Prefix Matching — Stale Cache Restored on Partial Hit'
|
|
3
|
+
category: caching-artifacts
|
|
4
|
+
severity: silent-failure
|
|
5
|
+
tags:
|
|
6
|
+
- cache
|
|
7
|
+
- actions/cache
|
|
8
|
+
- key
|
|
9
|
+
- prefix-match
|
|
10
|
+
- stale-cache
|
|
11
|
+
- cache-hit
|
|
12
|
+
- restore-keys
|
|
13
|
+
patterns:
|
|
14
|
+
- regex: 'Cache restored from key:'
|
|
15
|
+
flags: 'i'
|
|
16
|
+
- regex: 'cache-hit.*true'
|
|
17
|
+
flags: 'i'
|
|
18
|
+
- regex: 'uses:\s*actions/cache@v[34]'
|
|
19
|
+
flags: 'i'
|
|
20
|
+
error_messages:
|
|
21
|
+
- "Cache restored from key: npm-cache-linux"
|
|
22
|
+
- "cache-hit: true"
|
|
23
|
+
- "Restored cache from key"
|
|
24
|
+
root_cause: |
|
|
25
|
+
GitHub Actions documentation states that `actions/cache`'s primary `key:`
|
|
26
|
+
parameter requires an **exact match** to trigger a cache hit. In practice,
|
|
27
|
+
the cache service backend uses **prefix matching** for primary keys, identical
|
|
28
|
+
to how `restore-keys:` works. This undocumented behavior was confirmed by the
|
|
29
|
+
GitHub Actions team in actions/cache#1433:
|
|
30
|
+
|
|
31
|
+
> "I've checked the internal service implementation and it appears that our
|
|
32
|
+
> documentation is incorrect. `key` uses prefix-matching similar to how
|
|
33
|
+
> `restore-keys` works."
|
|
34
|
+
|
|
35
|
+
**What this means in practice:**
|
|
36
|
+
- If an existing cached entry has key `npm-cache-linux` and the current run
|
|
37
|
+
uses key `npm-cache-linux-abc123`, the primary `key` lookup returns a hit on
|
|
38
|
+
`npm-cache-linux` (the existing key is a prefix of the requested key).
|
|
39
|
+
- The cache is restored silently with `cache-hit: true`, even though the
|
|
40
|
+
actual content may be outdated or from a completely different run.
|
|
41
|
+
- Downstream jobs that check `cache-hit == 'true'` to skip install steps will
|
|
42
|
+
skip them, causing builds to use stale dependencies.
|
|
43
|
+
|
|
44
|
+
This is especially problematic when:
|
|
45
|
+
1. A broad, short key (e.g., `linux-npm`) was saved long ago and a new, more
|
|
46
|
+
specific key (e.g., `linux-npm-${{ hashFiles('package-lock.json') }}`)
|
|
47
|
+
happens to have the old key as a prefix.
|
|
48
|
+
2. CI changes add a version suffix to cache keys, but old caches from before
|
|
49
|
+
the change are still present and match as prefixes.
|
|
50
|
+
fix: |
|
|
51
|
+
**Option 1 (recommended): Use unique, non-colliding key prefixes**
|
|
52
|
+
Design your cache key so that no broader key from a previous run can be a prefix
|
|
53
|
+
of your current key. Include the hash of lock files or use a version token that
|
|
54
|
+
changes with major dependency updates.
|
|
55
|
+
|
|
56
|
+
**Option 2: Rotate keys by appending a version token**
|
|
57
|
+
Prefix with a cache version that you bump whenever you want to guarantee a cold
|
|
58
|
+
start, preventing old keys from matching.
|
|
59
|
+
|
|
60
|
+
**Option 3: Use `restore-keys:` intentionally**
|
|
61
|
+
If you want prefix fallback, make it explicit with `restore-keys:` and verify
|
|
62
|
+
what you're getting. Check `cache-hit` output and run install even on partial
|
|
63
|
+
hits when correctness matters.
|
|
64
|
+
|
|
65
|
+
**Option 4: Delete stale caches via API**
|
|
66
|
+
Use `gh extension install actions/gh-actions-cache` or the REST API to delete
|
|
67
|
+
old broad-key caches that would match as prefixes, preventing unexpected hits.
|
|
68
|
+
fix_code:
|
|
69
|
+
- language: yaml
|
|
70
|
+
label: 'Use versioned prefix to prevent stale prefix matches'
|
|
71
|
+
code: |
|
|
72
|
+
- uses: actions/cache@v4
|
|
73
|
+
with:
|
|
74
|
+
path: ~/.npm
|
|
75
|
+
# v2 prefix ensures old "v1" caches never match as prefixes
|
|
76
|
+
key: v2-npm-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
|
|
77
|
+
restore-keys: |
|
|
78
|
+
v2-npm-${{ runner.os }}-
|
|
79
|
+
- language: yaml
|
|
80
|
+
label: 'Re-install deps on partial cache hit to avoid stale cache'
|
|
81
|
+
code: |
|
|
82
|
+
- uses: actions/cache@v4
|
|
83
|
+
id: npm-cache
|
|
84
|
+
with:
|
|
85
|
+
path: ~/.npm
|
|
86
|
+
key: npm-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
|
|
87
|
+
restore-keys: npm-${{ runner.os }}-
|
|
88
|
+
|
|
89
|
+
- name: Install dependencies
|
|
90
|
+
# Always install when not an exact hit to avoid stale partial cache
|
|
91
|
+
if: steps.npm-cache.outputs.cache-hit != 'true'
|
|
92
|
+
run: npm ci
|
|
93
|
+
prevention:
|
|
94
|
+
- 'Always include a lockfile hash in cache keys: `key: npm-${{ runner.os }}-${{ hashFiles(''**/package-lock.json'') }}`'
|
|
95
|
+
- 'Prefix cache keys with a version token (e.g., `v1-`, `v2-`) so you can easily invalidate all old caches by bumping the version.'
|
|
96
|
+
- 'Do not rely solely on `cache-hit == true` to skip install steps; consider re-running `npm install --prefer-offline` even on hits to handle partial prefix matches.'
|
|
97
|
+
- 'Periodically audit and delete stale cache entries via the GitHub REST API or `gh actions-cache` extension.'
|
|
98
|
+
docs:
|
|
99
|
+
- url: 'https://github.com/actions/cache/issues/1433'
|
|
100
|
+
label: 'actions/cache#1433: Cache key uses prefix matching — documentation is incorrect'
|
|
101
|
+
- url: 'https://github.com/actions/cache/issues/1385'
|
|
102
|
+
label: 'actions/cache#1385: Unexpected cache hit from prefix match'
|
|
103
|
+
- url: 'https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows'
|
|
104
|
+
label: 'GitHub Docs: Caching dependencies to speed up workflows'
|
package/errors/concurrency-timing/batch-workflow-dispatch-static-concurrency-silent-cancel.yml
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
id: concurrency-timing-049
|
|
2
|
+
title: 'Batch workflow_dispatch Runs Silently Cancel Each Other via Static Concurrency Group'
|
|
3
|
+
category: concurrency-timing
|
|
4
|
+
severity: silent-failure
|
|
5
|
+
tags:
|
|
6
|
+
- concurrency
|
|
7
|
+
- workflow-dispatch
|
|
8
|
+
- batch
|
|
9
|
+
- cancel
|
|
10
|
+
- static-group
|
|
11
|
+
- lost-run
|
|
12
|
+
- dispatch-api
|
|
13
|
+
patterns:
|
|
14
|
+
- regex: 'This run was cancelled'
|
|
15
|
+
flags: 'i'
|
|
16
|
+
- regex: 'concurrency:\s*\n\s*group:\s*[''"]?\$\{\{\s*github\.workflow\s*\}\}'
|
|
17
|
+
flags: 'im'
|
|
18
|
+
- regex: 'workflow_dispatch.*concurrency|concurrency.*workflow_dispatch'
|
|
19
|
+
flags: 'ims'
|
|
20
|
+
error_messages:
|
|
21
|
+
- "This run was cancelled."
|
|
22
|
+
- "Run has been cancelled because it is in a concurrency group with a newer run."
|
|
23
|
+
- "Canceling since a more recent run was started"
|
|
24
|
+
root_cause: |
|
|
25
|
+
When a workflow uses a **static concurrency group** — one that does not
|
|
26
|
+
incorporate any per-run unique value like `github.run_id` or a user-supplied
|
|
27
|
+
input — and multiple `workflow_dispatch` runs are triggered in rapid succession
|
|
28
|
+
(e.g., from a batch API script, a label webhook fan-out, or automation), GitHub
|
|
29
|
+
Actions cancels all but the last run.
|
|
30
|
+
|
|
31
|
+
GitHub Actions enforces a limit of **1 running + 1 pending** run per concurrency
|
|
32
|
+
group. Each new dispatch replaces the existing pending run:
|
|
33
|
+
|
|
34
|
+
1. Run A starts → becomes "running"
|
|
35
|
+
2. Run B dispatched → becomes "pending" (waits for A)
|
|
36
|
+
3. Run C dispatched → **cancels Run B** (B was pending), C becomes "pending"
|
|
37
|
+
4. Run D dispatched → **cancels Run C**, D becomes "pending"
|
|
38
|
+
5. Only Run D eventually runs after Run A finishes.
|
|
39
|
+
|
|
40
|
+
This produces silent data loss when each dispatch carries different `inputs:`
|
|
41
|
+
(e.g., different artifact IDs, tenant IDs, or tags to process). All runs except
|
|
42
|
+
the last are silently discarded with "This run was cancelled."
|
|
43
|
+
|
|
44
|
+
Commonly triggered by:
|
|
45
|
+
- A webhook handler that dispatches one workflow run per event, with bursts of
|
|
46
|
+
events arriving simultaneously.
|
|
47
|
+
- Automation scripts that loop over a list and call `gh workflow run` for each item.
|
|
48
|
+
- A cron job that fans out to per-repo dispatches sharing the same workflow name.
|
|
49
|
+
|
|
50
|
+
Note: this is distinct from `concurrency-timing-040` (push + workflow_dispatch
|
|
51
|
+
sharing a group) — this issue occurs with ONLY workflow_dispatch runs sharing a
|
|
52
|
+
static group with no event-name differentiation.
|
|
53
|
+
fix: |
|
|
54
|
+
**Option 1 (recommended): Include a unique input value in the concurrency group**
|
|
55
|
+
If each dispatch has a unique identifier as an input (e.g., a tenant ID, artifact
|
|
56
|
+
ID, or item key), include it in the concurrency group so different dispatches
|
|
57
|
+
get independent groups.
|
|
58
|
+
|
|
59
|
+
**Option 2: Include github.run_id in the concurrency group**
|
|
60
|
+
Using `github.run_id` makes every run its own concurrency group — effectively
|
|
61
|
+
disabling concurrency entirely. Use only if all runs are important and must
|
|
62
|
+
complete.
|
|
63
|
+
|
|
64
|
+
**Option 3: Use cancel-in-progress: false (no-queue mode)**
|
|
65
|
+
With `cancel-in-progress: false`, new pending runs do not cancel existing pending
|
|
66
|
+
ones. The 1-running + 1-pending limit still applies, but the *last* queued run
|
|
67
|
+
(not the most recent dispatch) survives. This still means high-burst dispatches
|
|
68
|
+
lose most runs.
|
|
69
|
+
|
|
70
|
+
**Option 4: Use a queue-based architecture**
|
|
71
|
+
For high-volume fan-out, avoid workflow_dispatch entirely. Instead, push items to
|
|
72
|
+
a queue (SQS, GitHub Issues, database) and have a single polling workflow process
|
|
73
|
+
items from the queue sequentially or in bounded parallel batches.
|
|
74
|
+
fix_code:
|
|
75
|
+
- language: yaml
|
|
76
|
+
label: 'Include unique input in concurrency group to isolate per-dispatch runs'
|
|
77
|
+
code: |
|
|
78
|
+
on:
|
|
79
|
+
workflow_dispatch:
|
|
80
|
+
inputs:
|
|
81
|
+
item_id:
|
|
82
|
+
description: 'Unique identifier for this dispatch'
|
|
83
|
+
required: true
|
|
84
|
+
type: string
|
|
85
|
+
|
|
86
|
+
concurrency:
|
|
87
|
+
# Each unique item_id gets its own concurrency slot — no cross-dispatch cancellation
|
|
88
|
+
group: ${{ github.workflow }}-${{ inputs.item_id }}
|
|
89
|
+
cancel-in-progress: true
|
|
90
|
+
- language: yaml
|
|
91
|
+
label: 'Use github.run_id to guarantee all dispatches run independently'
|
|
92
|
+
code: |
|
|
93
|
+
on:
|
|
94
|
+
workflow_dispatch:
|
|
95
|
+
|
|
96
|
+
concurrency:
|
|
97
|
+
# Every run is its own group — effectively disables concurrency queueing
|
|
98
|
+
group: ${{ github.workflow }}-${{ github.run_id }}
|
|
99
|
+
cancel-in-progress: false
|
|
100
|
+
- language: yaml
|
|
101
|
+
label: 'Fan-out batch dispatch via matrix instead of separate workflow runs'
|
|
102
|
+
code: |
|
|
103
|
+
# Instead of dispatching N separate workflow runs (which cancel each other),
|
|
104
|
+
# dispatch ONE run with a matrix input to process all items in parallel.
|
|
105
|
+
on:
|
|
106
|
+
workflow_dispatch:
|
|
107
|
+
inputs:
|
|
108
|
+
item_ids:
|
|
109
|
+
description: 'JSON array of item IDs to process'
|
|
110
|
+
required: true
|
|
111
|
+
type: string
|
|
112
|
+
|
|
113
|
+
concurrency:
|
|
114
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
115
|
+
cancel-in-progress: false
|
|
116
|
+
|
|
117
|
+
jobs:
|
|
118
|
+
process-items:
|
|
119
|
+
strategy:
|
|
120
|
+
matrix:
|
|
121
|
+
item_id: ${{ fromJSON(inputs.item_ids) }}
|
|
122
|
+
runs-on: ubuntu-latest
|
|
123
|
+
steps:
|
|
124
|
+
- name: Process item
|
|
125
|
+
run: echo "Processing ${{ matrix.item_id }}"
|
|
126
|
+
prevention:
|
|
127
|
+
- 'Never use a static concurrency group (e.g., `group: ${{ github.workflow }}`) for workflows dispatched in batch — include a unique per-dispatch key.'
|
|
128
|
+
- 'When dispatching multiple runs from a script, add a unique ID as an input and include it in the concurrency group.'
|
|
129
|
+
- 'For high-volume fan-out workloads, use a single matrix job instead of N separate workflow_dispatch runs.'
|
|
130
|
+
- 'Monitor workflow cancellation counts in the Actions UI — unexpected "This run was cancelled" on dispatch events signals a concurrency group collision.'
|
|
131
|
+
docs:
|
|
132
|
+
- url: 'https://github.com/github/gh-aw/issues/19467'
|
|
133
|
+
label: 'github/gh-aw#19467: Batch workflow_dispatch runs cancel each other via static concurrency group'
|
|
134
|
+
- url: 'https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/using-concurrency'
|
|
135
|
+
label: 'GitHub Docs: Using concurrency — 1 running + 1 pending limit per group'
|
|
136
|
+
- url: 'https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-workflow-runs/manually-running-a-workflow'
|
|
137
|
+
label: 'GitHub Docs: Manually running a workflow'
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
id: runner-environment-174
|
|
2
|
+
title: 'Sparse Checkout Config Persists Across Workflow Runs on Self-Hosted Runners'
|
|
3
|
+
category: runner-environment
|
|
4
|
+
severity: silent-failure
|
|
5
|
+
tags:
|
|
6
|
+
- sparse-checkout
|
|
7
|
+
- self-hosted
|
|
8
|
+
- git-config
|
|
9
|
+
- workspace-reuse
|
|
10
|
+
- checkout
|
|
11
|
+
- non-ephemeral
|
|
12
|
+
patterns:
|
|
13
|
+
- regex: 'core\.sparseCheckout\s*=\s*true'
|
|
14
|
+
flags: 'i'
|
|
15
|
+
- regex: 'sparse.checkout.*persist|persist.*sparse.checkout'
|
|
16
|
+
flags: 'i'
|
|
17
|
+
- regex: 'git sparse-checkout disable'
|
|
18
|
+
flags: 'i'
|
|
19
|
+
error_messages:
|
|
20
|
+
- "Run actions/checkout@v4"
|
|
21
|
+
- "Checkout was successful but expected files are missing from working directory"
|
|
22
|
+
- "sparse-checkout: /run/git/config: sparseCheckout = true"
|
|
23
|
+
root_cause: |
|
|
24
|
+
On non-ephemeral self-hosted runners, the workspace directory (e.g.
|
|
25
|
+
`/home/runner/work/my-repo/my-repo`) is reused across multiple workflow runs
|
|
26
|
+
on the same runner machine. When `actions/checkout` runs with `sparse-checkout:`
|
|
27
|
+
options, it sets `core.sparseCheckout = true` in the repository's `.git/config`
|
|
28
|
+
file.
|
|
29
|
+
|
|
30
|
+
In older versions of `actions/checkout` (before the fix in commit aadec89,
|
|
31
|
+
merged ~2025), the `disableSparseCheckout()` method reset `core.sparseCheckout`
|
|
32
|
+
only in `.git/config.worktree` (used in git worktrees), but NOT in the main
|
|
33
|
+
`.git/config`. As a result:
|
|
34
|
+
|
|
35
|
+
- **Workflow run N** uses `sparse-checkout:` → sets `core.sparseCheckout = true`
|
|
36
|
+
in `.git/config`.
|
|
37
|
+
- **Workflow run N+1** on the same runner does NOT use `sparse-checkout:`, but
|
|
38
|
+
inherits the stale `core.sparseCheckout = true` setting from the reused workspace.
|
|
39
|
+
- `actions/checkout` reports success, but the working directory contains only
|
|
40
|
+
the files that matched the previous run's sparse-checkout patterns. All other
|
|
41
|
+
files silently absent.
|
|
42
|
+
|
|
43
|
+
This is distinct from the same-job sticky cone mode issue (sf-008), which covers
|
|
44
|
+
two `actions/checkout` calls within a single job sharing sparse state. This issue
|
|
45
|
+
manifests across entirely separate workflow runs on a shared workspace.
|
|
46
|
+
|
|
47
|
+
Confirmed in actions/checkout#2249 (published Aug 2025) and actions/checkout#1992.
|
|
48
|
+
fix: |
|
|
49
|
+
**Option 1 (recommended): Upgrade to actions/checkout v4.2.0+**
|
|
50
|
+
The bug was fixed in commit aadec89. Pinning to a patched release ensures
|
|
51
|
+
`disableSparseCheckout()` explicitly sets `core.sparseCheckout = false` in
|
|
52
|
+
`.git/config` when no `sparse-checkout:` input is provided.
|
|
53
|
+
|
|
54
|
+
**Option 2: Add an explicit `git sparse-checkout disable` step**
|
|
55
|
+
Add this step at the beginning of workflows that do NOT use sparse-checkout
|
|
56
|
+
on a runner that may previously have run sparse-checkout workflows:
|
|
57
|
+
|
|
58
|
+
**Option 3: Use ephemeral self-hosted runners**
|
|
59
|
+
Configure runners so each job gets a fresh workspace (e.g., ARC ephemeral mode,
|
|
60
|
+
EC2 runners with fresh AMIs). Ephemeral runners eliminate all cross-run workspace
|
|
61
|
+
contamination.
|
|
62
|
+
|
|
63
|
+
**Option 4: Configure runner to clean workspace between runs**
|
|
64
|
+
Set `ACTIONS_RUNNER_CLEAN_WORKSPACE=true` in the runner environment (where
|
|
65
|
+
supported) to force workspace cleanup between job runs.
|
|
66
|
+
fix_code:
|
|
67
|
+
- language: yaml
|
|
68
|
+
label: 'Upgrade to patched actions/checkout version'
|
|
69
|
+
code: |
|
|
70
|
+
steps:
|
|
71
|
+
- uses: actions/checkout@v4 # Use v4.2.0+ for the sparse-checkout fix
|
|
72
|
+
# No sparse-checkout options — will correctly restore full tree
|
|
73
|
+
- language: yaml
|
|
74
|
+
label: 'Explicit sparse-checkout reset before checkout on shared runners'
|
|
75
|
+
code: |
|
|
76
|
+
steps:
|
|
77
|
+
- name: Reset sparse-checkout (safety guard for shared self-hosted runners)
|
|
78
|
+
shell: bash
|
|
79
|
+
run: |
|
|
80
|
+
if git -C "${{ github.workspace }}" rev-parse --git-dir > /dev/null 2>&1; then
|
|
81
|
+
git -C "${{ github.workspace }}" sparse-checkout disable 2>/dev/null || true
|
|
82
|
+
git -C "${{ github.workspace }}" config --unset core.sparseCheckout 2>/dev/null || true
|
|
83
|
+
fi
|
|
84
|
+
|
|
85
|
+
- uses: actions/checkout@v4
|
|
86
|
+
prevention:
|
|
87
|
+
- 'On self-hosted runners, always pin `actions/checkout` to v4.2.0+ which fixes the sparse-checkout persistence bug.'
|
|
88
|
+
- 'Add a `git sparse-checkout disable` guard step at the start of any workflow that runs on a non-ephemeral self-hosted runner.'
|
|
89
|
+
- 'Use ephemeral runners (fresh environment per job) to eliminate all cross-run workspace contamination.'
|
|
90
|
+
- 'Do not mix sparse-checkout and full-checkout workflows on the same non-ephemeral runner without resetting `.git/config` between runs.'
|
|
91
|
+
docs:
|
|
92
|
+
- url: 'https://github.com/actions/checkout/issues/2249'
|
|
93
|
+
label: 'actions/checkout#2249: Sparse-checkout configuration persists across workflows on self-hosted runners'
|
|
94
|
+
- url: 'https://github.com/actions/checkout/issues/1992'
|
|
95
|
+
label: 'actions/checkout#1992: Sparscheckout breaks cached repository on self-hosted runners'
|
|
96
|
+
- url: 'https://github.com/actions/checkout/commit/aadec899646c8e0f34c52d9219c2faac36626b55'
|
|
97
|
+
label: 'Fix commit aadec89: Explicitly disable sparseCheckout in .git/config when not using sparse-checkout'
|
|
98
|
+
- url: 'https://docs.github.com/en/actions/using-github-hosted-runners/using-github-hosted-runners/about-github-hosted-runners'
|
|
99
|
+
label: 'GitHub Docs: About GitHub-hosted runners (ephemeral vs self-hosted)'
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
id: yaml-syntax-066
|
|
2
|
+
title: 'hashFiles() Newline Delimiter in Single String Returns Empty — Use Multiple Arguments'
|
|
3
|
+
category: yaml-syntax
|
|
4
|
+
severity: silent-failure
|
|
5
|
+
tags:
|
|
6
|
+
- hashfiles
|
|
7
|
+
- expression
|
|
8
|
+
- cache-key
|
|
9
|
+
- empty-string
|
|
10
|
+
- multifile
|
|
11
|
+
- glob
|
|
12
|
+
- newline-delimiter
|
|
13
|
+
patterns:
|
|
14
|
+
- regex: 'hashFiles\([''"].*\\n.*[''"]'
|
|
15
|
+
flags: 'i'
|
|
16
|
+
- regex: 'hashFiles\s*\(\s*[''"][^''",]+\\n[^''",]+[''"]'
|
|
17
|
+
flags: 'i'
|
|
18
|
+
error_messages:
|
|
19
|
+
- "${{ hashFiles('src/**\npackage.json') }}"
|
|
20
|
+
- "${{ hashFiles('**/*.lock\n**/*.toml') }}"
|
|
21
|
+
- "hashFiles result: ''"
|
|
22
|
+
root_cause: |
|
|
23
|
+
The `@actions/glob` internal implementation documents that file patterns can be
|
|
24
|
+
separated by newline (`\n`) characters when passed as a single string. This causes
|
|
25
|
+
developers to write `hashFiles('file.ts\nfile.tsx')` expecting it to hash both
|
|
26
|
+
files.
|
|
27
|
+
|
|
28
|
+
However, inside a GitHub Actions expression (`${{ ... }}`), string literals do
|
|
29
|
+
NOT interpret escape sequences. The `\n` in `'file.ts\nfile.tsx'` is a literal
|
|
30
|
+
two-character sequence: backslash + "n". The glob function then looks for a file
|
|
31
|
+
literally named `file.ts\nfile.tsx` — which does not exist — and returns an empty
|
|
32
|
+
string `''`.
|
|
33
|
+
|
|
34
|
+
**Result:**
|
|
35
|
+
- `cache-key: ${{ hashFiles('package.json\nyarn.lock') }}` → cache key ends with
|
|
36
|
+
an empty string, causing ALL runs to collide on the same constant prefix key.
|
|
37
|
+
- `if: hashFiles('src/**\ntest/**') != ''` → always false (no hash returned), so
|
|
38
|
+
cache/condition logic silently skips.
|
|
39
|
+
- No error is raised; the expression just evaluates to `''` silently.
|
|
40
|
+
|
|
41
|
+
Confirmed in actions/runner#3467 and actions/runner#4049.
|
|
42
|
+
|
|
43
|
+
Note: `hashFiles()` DOES accept multiple comma-separated string arguments, and
|
|
44
|
+
each argument is a full glob pattern. The variadic call form works correctly.
|
|
45
|
+
fix: |
|
|
46
|
+
Use multiple comma-separated arguments to `hashFiles()` instead of a
|
|
47
|
+
newline-delimited single string.
|
|
48
|
+
|
|
49
|
+
`hashFiles('pattern1', 'pattern2', ...)` correctly hashes all files matching
|
|
50
|
+
any of the provided glob patterns.
|
|
51
|
+
|
|
52
|
+
If you are building a dynamic list of patterns from a context value or step
|
|
53
|
+
output, write the patterns to a file and hash that file, or hash each pattern
|
|
54
|
+
in separate expressions and combine.
|
|
55
|
+
fix_code:
|
|
56
|
+
- language: yaml
|
|
57
|
+
label: 'Use multiple arguments (correct) instead of newline-delimited string (broken)'
|
|
58
|
+
code: |
|
|
59
|
+
# BROKEN — \n is a literal backslash-n, not a newline; returns empty string
|
|
60
|
+
# key: npm-${{ hashFiles('package.json\npackage-lock.json') }}
|
|
61
|
+
|
|
62
|
+
# CORRECT — comma-separated arguments, hashes both files
|
|
63
|
+
- uses: actions/cache@v4
|
|
64
|
+
with:
|
|
65
|
+
path: ~/.npm
|
|
66
|
+
key: npm-${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json') }}
|
|
67
|
+
- language: yaml
|
|
68
|
+
label: 'Multiple lock files hashed with variadic hashFiles()'
|
|
69
|
+
code: |
|
|
70
|
+
- uses: actions/cache@v4
|
|
71
|
+
with:
|
|
72
|
+
path: |
|
|
73
|
+
~/.npm
|
|
74
|
+
~/.cache/pip
|
|
75
|
+
key: multi-${{ runner.os }}-${{ hashFiles('**/package-lock.json', '**/requirements*.txt', '**/Pipfile.lock') }}
|
|
76
|
+
restore-keys: |
|
|
77
|
+
multi-${{ runner.os }}-
|
|
78
|
+
- language: yaml
|
|
79
|
+
label: 'Conditional step using hashFiles() with multiple arguments'
|
|
80
|
+
code: |
|
|
81
|
+
# BROKEN — always evaluates to '' because \n is not a newline escape
|
|
82
|
+
# if: ${{ hashFiles('src/**\ntest/**') != '' }}
|
|
83
|
+
|
|
84
|
+
# CORRECT
|
|
85
|
+
- name: Check if source files changed
|
|
86
|
+
if: ${{ hashFiles('src/**', 'test/**') != '' }}
|
|
87
|
+
run: echo "Source files found"
|
|
88
|
+
prevention:
|
|
89
|
+
- 'Never use `\n` as a pattern delimiter inside a `hashFiles()` call in a workflow expression — it is a literal backslash-n, not a newline.'
|
|
90
|
+
- 'Use multiple comma-separated arguments: `hashFiles(''pattern1'', ''pattern2'')` to hash files from multiple glob patterns.'
|
|
91
|
+
- 'When a `hashFiles()` result is used as a cache key suffix, validate it is non-empty by running the workflow once and checking the logged cache key.'
|
|
92
|
+
- 'If you suspect an empty hash, add a debug step: `run: echo "hash=${{ hashFiles(''**/*.lock'') }}"` to verify the value before using it in a key.'
|
|
93
|
+
docs:
|
|
94
|
+
- url: 'https://github.com/actions/runner/issues/3467'
|
|
95
|
+
label: 'actions/runner#3467: hashFiles does not follow docs — newline delimiter in string returns empty'
|
|
96
|
+
- url: 'https://github.com/actions/runner/issues/4049'
|
|
97
|
+
label: 'actions/runner#4049: hashFiles newline pattern delimiter not interpreted in expressions'
|
|
98
|
+
- url: 'https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/evaluate-expressions-in-workflows-and-actions#hashfiles'
|
|
99
|
+
label: 'GitHub Docs: hashFiles function — variadic arguments'
|
package/package.json
CHANGED