-
Notifications
You must be signed in to change notification settings - Fork 9
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
new: Add cache base warmup strategy. #16
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
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 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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# 1.1.0 | ||
|
||
- Updated dependencies. | ||
|
||
# 1.0.3 | ||
|
||
- Include `GITHUB_WORKFLOW` in cache key. | ||
|
This file contains 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 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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,77 @@ | ||
import crypto from 'node:crypto'; | ||
import os from 'node:os'; | ||
import path from 'node:path'; | ||
import * as cache from '@actions/cache'; | ||
import * as core from '@actions/core'; | ||
import * as glob from '@actions/glob'; | ||
import { RUST_HASH, RUST_VERSION } from './rust'; | ||
|
||
export const CARGO_HOME = process.env.CARGO_HOME ?? path.join(os.homedir(), '.cargo'); | ||
|
||
export const WORKSPACE_ROOT = process.env.GITHUB_WORKSPACE ?? process.cwd(); | ||
|
||
export function isCacheEnabled(): boolean { | ||
return core.getBooleanInput('cache') && cache.isFeatureAvailable(); | ||
} | ||
|
||
export function getCacheTarget(): string { | ||
return core.getInput('cache-target') || 'debug'; | ||
} | ||
|
||
export function getCachePaths(): string[] { | ||
return [ | ||
// ~/.cargo/registry | ||
path.join(CARGO_HOME, 'registry'), | ||
// /workspace/target/debug | ||
path.join(WORKSPACE_ROOT, 'target', getCacheTarget()), | ||
]; | ||
} | ||
|
||
export function getCachePrefixes(): string[] { | ||
return [`setup-rustcargo-v1-${process.platform}`, 'setup-rustcargo-v1']; | ||
} | ||
|
||
export async function getPrimaryCacheKey() { | ||
const hasher = crypto.createHash('sha1'); | ||
|
||
core.info('Generating cache key'); | ||
|
||
core.debug(`Hashing Rust version = ${RUST_VERSION}`); | ||
hasher.update(RUST_VERSION); | ||
|
||
core.debug(`Hashing Rust commit hash = ${RUST_HASH}`); | ||
hasher.update(RUST_HASH); | ||
|
||
const cacheTarget = getCacheTarget(); | ||
|
||
core.debug(`Hashing target profile = ${cacheTarget}`); | ||
hasher.update(cacheTarget); | ||
|
||
if (core.getInput('cache-base')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Big change here to the cache key |
||
core.debug('Using warmup strategy, not hashing Cargo.lock, GITHUB_WORKFLOW, or GITHUB_JOB'); | ||
} | ||
|
||
// When warming up, these add far too much granularity to the cache key | ||
else { | ||
const lockHash = await glob.hashFiles('Cargo.lock'); | ||
|
||
core.debug(`Hashing Cargo.lock = ${lockHash}`); | ||
hasher.update(lockHash); | ||
|
||
const workflow = process.env.GITHUB_WORKFLOW; | ||
|
||
if (workflow) { | ||
core.debug(`Hashing GITHUB_WORKFLOW = ${workflow}`); | ||
hasher.update(workflow); | ||
} | ||
|
||
const job = process.env.GITHUB_JOB; | ||
|
||
if (job) { | ||
core.debug(`Hashing GITHUB_JOB = ${job}`); | ||
hasher.update(job); | ||
} | ||
} | ||
|
||
return `${getCachePrefixes()[0]}-${hasher.digest('hex')}`; | ||
} |
This file contains 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
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.
moved cache stuff to its own file