-
Notifications
You must be signed in to change notification settings - Fork 15
fix: restore cache before installing runtime #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6d14020
fix: restore cache before installing runtime
Stanzilla df5ed32
fix: key runtime caches by resolved version
Stanzilla 724811f
fix: list direct global runtime dependency
Stanzilla f2a2ac8
fix: never save the cache under the provisional restore key
zkochan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import assert from 'node:assert/strict' | ||
| import test from 'node:test' | ||
| import { getCacheKeyPrefix, getPrimaryCacheKey } from './keys.ts' | ||
|
|
||
| test('moving runtime selectors use the resolved version in the primary key', () => { | ||
| const prefix = getCacheKeyPrefix('Linux', 'x64', { name: 'node', version: 'lts' }) | ||
| const previousKey = getPrimaryCacheKey(prefix, 'lockfile-hash', '22.22.0') | ||
| const currentKey = getPrimaryCacheKey(prefix, 'lockfile-hash', '24.13.0') | ||
|
|
||
| assert.notEqual(previousKey, currentKey) | ||
| assert.ok(previousKey.startsWith(prefix)) | ||
| assert.ok(currentKey.startsWith(prefix)) | ||
| }) | ||
|
|
||
| test('the provisional restore key is never a key a runtime run saves under', () => { | ||
| const prefix = getCacheKeyPrefix('Linux', 'x64', { name: 'node', version: '24.19.0' }) | ||
| const provisional = getPrimaryCacheKey(prefix, 'lockfile-hash') | ||
| const final = getPrimaryCacheKey(prefix, 'lockfile-hash', '24.19.0') | ||
|
|
||
| // An exact hit on the provisional key would stop the restore falling back | ||
| // to the prefix search that finds the versioned caches. | ||
| assert.notEqual(provisional, final) | ||
| }) | ||
|
|
||
| test('without a runtime the provisional key is the final key', () => { | ||
| const prefix = getCacheKeyPrefix('Linux', 'x64', undefined) | ||
|
|
||
| assert.equal( | ||
| getPrimaryCacheKey(prefix, 'lockfile-hash'), | ||
| getPrimaryCacheKey(prefix, 'lockfile-hash', undefined), | ||
| ) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { createHash } from 'crypto' | ||
| import type { RuntimeRequest } from '../install-runtime' | ||
|
|
||
| export function getCacheKeyPrefix( | ||
| runnerOs: string | undefined, | ||
| architecture: string, | ||
| runtime: RuntimeRequest | undefined, | ||
| ): string { | ||
| const runtimeKey = runtime | ||
| ? hashCacheKeyPart(`${runtime.name}@${runtime.version}`) | ||
| : 'no-runtime' | ||
| return `pnpm-cache-${runnerOs}-${architecture}-${runtimeKey}-` | ||
| } | ||
|
|
||
| export function getPrimaryCacheKey( | ||
| keyPrefix: string, | ||
| fileHash: string, | ||
| resolvedRuntimeVersion?: string, | ||
| ): string { | ||
| const runtimeVersionKey = resolvedRuntimeVersion | ||
| ? `${hashCacheKeyPart(resolvedRuntimeVersion)}-` | ||
| : '' | ||
| return `${keyPrefix}${runtimeVersionKey}${fileHash}` | ||
| } | ||
|
|
||
| function hashCacheKeyPart(value: string): string { | ||
| return createHash('sha256').update(value).digest('hex') | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Do not treat a final cache hit as proof of restore ordering.
CACHE_HIT=trueandnode --versiononly describe the final state. If the action installs Node first and restores the cache afterward, this job can still produce the same values. The test can pass while the regression in Issue#31remains. Add an install-boundary assertion or a controlled download probe that fails when the runtime archive is fetched before cache restoration.🧰 Tools
🪛 zizmor (1.29.0)
[warning] 147-154: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false
(artipacked)
🤖 Prompt for AI Agents