small code style improvements, README and CHANGELOG updates
This commit is contained in:
parent
ccdddcc049
commit
e78327dd9e
|
@ -1,8 +1,13 @@
|
|||
# Changelog
|
||||
|
||||
## 2.1.0
|
||||
|
||||
- Only hash `Cargo.{lock,toml}` files in the configured workspace directories.
|
||||
|
||||
## 2.0.2
|
||||
|
||||
- Avoid calling `cargo metadata` on pre-cleanup.
|
||||
- Added `prefix-key`, `cache-directories` and `cache-targets` options.
|
||||
|
||||
## 2.0.1
|
||||
|
||||
|
|
|
@ -14,11 +14,12 @@ sensible defaults.
|
|||
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
with:
|
||||
# The prefix cache key, this can be changed to start a new cache manually
|
||||
# The prefix cache key, this can be changed to start a new cache manually.
|
||||
# default: "v0-rust"
|
||||
prefix-key: ""
|
||||
|
||||
# An additional cache key that is stable over multiple jobs
|
||||
# A cache key that is used instead of the automatic `job`-based key,
|
||||
# and is stable over multiple jobs.
|
||||
# default: empty
|
||||
shared-key: ""
|
||||
|
||||
|
@ -41,10 +42,11 @@ sensible defaults.
|
|||
# default: ". -> target"
|
||||
workspaces: ""
|
||||
|
||||
# Additional non workspace directories, separated by newlines
|
||||
# Additional non workspace directories to be cached, separated by newlines.
|
||||
cache-directories: ""
|
||||
|
||||
# Determines whether workspace `target` directories are cached.
|
||||
# If `false`, only the cargo registry will be cached.
|
||||
# default: "true"
|
||||
cache-targets: ""
|
||||
|
||||
|
|
18
action.yml
18
action.yml
|
@ -3,34 +3,34 @@ description: "A GitHub Action that implements smart caching for rust/cargo proje
|
|||
author: "Arpad Borsos <swatinem@swatinem.de>"
|
||||
inputs:
|
||||
prefix-key:
|
||||
description: "The prefix cache key, this can be changed to start a new cache manually"
|
||||
description: "The prefix cache key, this can be changed to start a new cache manually."
|
||||
required: false
|
||||
default: "v0-rust"
|
||||
shared-key:
|
||||
description: "An additional cache key that is stable over multiple jobs"
|
||||
description: "A cache key that is used instead of the automatic `job`-based key, and is stable over multiple jobs."
|
||||
required: false
|
||||
key:
|
||||
description: "An additional key for the cache"
|
||||
description: "An additional cache key that is added alongside the automatic `job`-based cache key and can be used to further differentiate jobs."
|
||||
required: false
|
||||
env-vars:
|
||||
description: "Additional environment variables to include in the cache key, separated by spaces"
|
||||
description: "Additional environment variables to include in the cache key, separated by spaces."
|
||||
required: false
|
||||
workspaces:
|
||||
description: "Paths to multiple Cargo workspaces and their target directories, separated by newlines"
|
||||
description: "Paths to multiple Cargo workspaces and their target directories, separated by newlines."
|
||||
required: false
|
||||
cache-directories:
|
||||
description: "Additional non workspace directories, separated by newlines"
|
||||
description: "Additional non workspace directories to be cached, separated by newlines."
|
||||
required: false
|
||||
cache-targets:
|
||||
description: "Determines whether workspace targets are cached"
|
||||
description: "Determines whether workspace targets are cached. If `false`, only the cargo registry will be cached."
|
||||
required: false
|
||||
default: "true"
|
||||
cache-on-failure:
|
||||
description: "Cache even if the build fails. Defaults to false"
|
||||
description: "Cache even if the build fails. Defaults to false."
|
||||
required: false
|
||||
outputs:
|
||||
cache-hit:
|
||||
description: "A boolean value that indicates an exact match was found"
|
||||
description: "A boolean value that indicates an exact match was found."
|
||||
runs:
|
||||
using: "node16"
|
||||
main: "dist/restore/index.js"
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -5,7 +5,6 @@
|
|||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "rust-cache",
|
||||
"version": "2.0.2",
|
||||
"license": "LGPL-3.0",
|
||||
"dependencies": {
|
||||
|
|
|
@ -50,7 +50,7 @@ export class CacheConfig {
|
|||
// This uses either the `shared-key` input,
|
||||
// or the `key` input combined with the `job` key.
|
||||
|
||||
let key = core.getInput("prefix-key");
|
||||
let key = core.getInput("prefix-key") || "v0-rust";
|
||||
|
||||
const sharedKey = core.getInput("shared-key");
|
||||
if (sharedKey) {
|
||||
|
@ -132,29 +132,23 @@ export class CacheConfig {
|
|||
self.workspaces = workspaces;
|
||||
|
||||
if (!lockHash) {
|
||||
hasher = crypto.createHash("sha1");
|
||||
|
||||
async function globHash(pattern: string): Promise<string[]> {
|
||||
const globber = await glob.create(pattern, {
|
||||
followSymbolicLinks: false,
|
||||
});
|
||||
return await globber.glob();
|
||||
}
|
||||
|
||||
keyFiles = keyFiles.concat(await globHash("rust-toolchain\nrust-toolchain.toml"));
|
||||
keyFiles = keyFiles.concat(await globFiles("rust-toolchain\nrust-toolchain.toml"));
|
||||
for (const workspace of workspaces) {
|
||||
const root = workspace.root;
|
||||
keyFiles = keyFiles.concat(await globHash(`${root}/**/Cargo.toml\n${root}/**/Cargo.lock\n${root}/**/rust-toolchain\n${root}/**/rust-toolchain.toml`));
|
||||
keyFiles.push(
|
||||
...(await globFiles(
|
||||
`${root}/**/Cargo.toml\n${root}/**/Cargo.lock\n${root}/**/rust-toolchain\n${root}/**/rust-toolchain.toml`,
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
keyFiles.sort((a, b) => a.localeCompare(b));
|
||||
|
||||
hasher = crypto.createHash("sha1");
|
||||
for (const file of keyFiles) {
|
||||
for await (const chunk of fs.createReadStream(file)) {
|
||||
hasher.update(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
lockHash = hasher.digest("hex");
|
||||
|
||||
core.saveState(STATE_LOCKFILE_HASH, lockHash);
|
||||
|
@ -167,13 +161,13 @@ export class CacheConfig {
|
|||
self.cacheKey = key;
|
||||
|
||||
self.cachePaths = [CARGO_HOME];
|
||||
const cacheTargets = core.getInput("cache-targets").toLowerCase();
|
||||
const cacheTargets = core.getInput("cache-targets").toLowerCase() || "true";
|
||||
if (cacheTargets === "true") {
|
||||
self.cachePaths.push(...workspaces.map((ws) => ws.target));
|
||||
}
|
||||
|
||||
const cacheDirectories = core.getInput("cache-directories");
|
||||
for (const dir of cacheDirectories.trim().split("\n")) {
|
||||
for (const dir of cacheDirectories.trim().split(/\s+/).filter(Boolean)) {
|
||||
self.cachePaths.push(dir);
|
||||
}
|
||||
|
||||
|
@ -224,3 +218,10 @@ async function getRustVersion(): Promise<RustVersion> {
|
|||
.filter((s) => s.length === 2);
|
||||
return Object.fromEntries(splits);
|
||||
}
|
||||
|
||||
async function globFiles(pattern: string): Promise<string[]> {
|
||||
const globber = await glob.create(pattern, {
|
||||
followSymbolicLinks: false,
|
||||
});
|
||||
return await globber.glob();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue