Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
98c8021b55 | ||
|
|
14d3bc39c4 | ||
|
|
52ea1434f8 | ||
|
|
eaa85be6b1 | ||
|
|
901019c0f8 | ||
|
|
9d47c6ad4b | ||
|
|
27b8ea9368 | ||
|
|
f0deed1e0e | ||
|
|
008623fb83 |
24
CHANGELOG.md
24
CHANGELOG.md
@@ -1,5 +1,29 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2.8.0
|
||||||
|
|
||||||
|
- Add support for `warpbuild` cache provider
|
||||||
|
- Add new `cache-workspace-crates` feature
|
||||||
|
|
||||||
|
## 2.7.8
|
||||||
|
|
||||||
|
- Include CPU arch in the cache key
|
||||||
|
|
||||||
|
## 2.7.7
|
||||||
|
|
||||||
|
- Also cache `cargo install` metadata
|
||||||
|
|
||||||
|
## 2.7.6
|
||||||
|
|
||||||
|
- Allow opting out of caching $CARGO_HOME/bin
|
||||||
|
- Add runner OS in cache key
|
||||||
|
- Adds an option to do lookup-only of the cache
|
||||||
|
|
||||||
|
## 2.7.5
|
||||||
|
|
||||||
|
- Support Cargo.lock format cargo-lock v4
|
||||||
|
- Only run macOsWorkaround() on macOS
|
||||||
|
|
||||||
## 2.7.3
|
## 2.7.3
|
||||||
|
|
||||||
- Work around upstream problem that causes cache saving to hang for minutes.
|
- Work around upstream problem that causes cache saving to hang for minutes.
|
||||||
|
|||||||
@@ -60,6 +60,12 @@ sensible defaults.
|
|||||||
# default: "false"
|
# default: "false"
|
||||||
cache-all-crates: ""
|
cache-all-crates: ""
|
||||||
|
|
||||||
|
# Similar to cache-all-crates.
|
||||||
|
# If `true` the workspace crates will be cached.
|
||||||
|
# Useful if the workspace contains libraries that are only updated sporadically.
|
||||||
|
# default: "false"
|
||||||
|
cache-workspace-crates: ""
|
||||||
|
|
||||||
# Determines whether the cache should be saved.
|
# Determines whether the cache should be saved.
|
||||||
# If `false`, the cache is only restored.
|
# If `false`, the cache is only restored.
|
||||||
# Useful for jobs where the matrix is additive e.g. additional Cargo features,
|
# Useful for jobs where the matrix is additive e.g. additional Cargo features,
|
||||||
@@ -76,7 +82,7 @@ sensible defaults.
|
|||||||
lookup-only: ""
|
lookup-only: ""
|
||||||
|
|
||||||
# Specifies what to use as the backend providing cache
|
# Specifies what to use as the backend providing cache
|
||||||
# Can be set to either "github" or "buildjet"
|
# Can be set to "github", "buildjet", or "warpbuild"
|
||||||
# default: "github"
|
# default: "github"
|
||||||
cache-provider: ""
|
cache-provider: ""
|
||||||
|
|
||||||
|
|||||||
@@ -32,12 +32,16 @@ inputs:
|
|||||||
description: "Determines which crates are cached. If `true` all crates will be cached, otherwise only dependent crates will be cached."
|
description: "Determines which crates are cached. If `true` all crates will be cached, otherwise only dependent crates will be cached."
|
||||||
required: false
|
required: false
|
||||||
default: "false"
|
default: "false"
|
||||||
|
cache-workspace-crates:
|
||||||
|
description: "Similar to cache-all-crates. If `true` the workspace crates will be cached."
|
||||||
|
required: false
|
||||||
|
default: "false"
|
||||||
save-if:
|
save-if:
|
||||||
description: "Determiners whether the cache should be saved. If `false`, the cache is only restored."
|
description: "Determiners whether the cache should be saved. If `false`, the cache is only restored."
|
||||||
required: false
|
required: false
|
||||||
default: "true"
|
default: "true"
|
||||||
cache-provider:
|
cache-provider:
|
||||||
description: "Determines which provider to use for caching. Options are github or buildjet, defaults to github."
|
description: "Determines which provider to use for caching. Options are github, buildjet, or warpbuild. Defaults to github."
|
||||||
required: false
|
required: false
|
||||||
default: "github"
|
default: "github"
|
||||||
cache-bin:
|
cache-bin:
|
||||||
|
|||||||
60555
dist/restore/index.js
vendored
60555
dist/restore/index.js
vendored
File diff suppressed because one or more lines are too long
60556
dist/save/index.js
vendored
60556
dist/save/index.js
vendored
File diff suppressed because one or more lines are too long
902
package-lock.json
generated
902
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"name": "rust-cache",
|
"name": "rust-cache",
|
||||||
"version": "2.7.6",
|
"version": "2.8.0",
|
||||||
"description": "A GitHub Action that implements smart caching for rust/cargo projects with sensible defaults.",
|
"description": "A GitHub Action that implements smart caching for rust/cargo projects with sensible defaults.",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"actions",
|
"actions",
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
"homepage": "https://github.com/Swatinem/rust-cache#readme",
|
"homepage": "https://github.com/Swatinem/rust-cache#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/buildjet-cache": "npm:github-actions.cache-buildjet@0.2.0",
|
"@actions/buildjet-cache": "npm:github-actions.cache-buildjet@0.2.0",
|
||||||
|
"@actions/warpbuild-cache": "npm:github-actions.warp-cache@1.4.5",
|
||||||
"@actions/cache": "^4.0.0",
|
"@actions/cache": "^4.0.0",
|
||||||
"@actions/core": "^1.11.1",
|
"@actions/core": "^1.11.1",
|
||||||
"@actions/exec": "^1.1.1",
|
"@actions/exec": "^1.1.1",
|
||||||
|
|||||||
@@ -43,16 +43,16 @@ async function cleanProfileTarget(profileDir: string, packages: Packages, checkT
|
|||||||
// https://github.com/vertexclique/kaos/blob/9876f6c890339741cc5be4b7cb9df72baa5a6d79/src/cargo.rs#L25
|
// https://github.com/vertexclique/kaos/blob/9876f6c890339741cc5be4b7cb9df72baa5a6d79/src/cargo.rs#L25
|
||||||
// https://github.com/eupn/macrotest/blob/c4151a5f9f545942f4971980b5d264ebcd0b1d11/src/cargo.rs#L27
|
// https://github.com/eupn/macrotest/blob/c4151a5f9f545942f4971980b5d264ebcd0b1d11/src/cargo.rs#L27
|
||||||
cleanTargetDir(path.join(profileDir, "target"), packages, checkTimestamp);
|
cleanTargetDir(path.join(profileDir, "target"), packages, checkTimestamp);
|
||||||
} catch { }
|
} catch {}
|
||||||
try {
|
try {
|
||||||
// https://github.com/dtolnay/trybuild/blob/eec8ca6cb9b8f53d0caf1aa499d99df52cae8b40/src/cargo.rs#L50
|
// https://github.com/dtolnay/trybuild/blob/eec8ca6cb9b8f53d0caf1aa499d99df52cae8b40/src/cargo.rs#L50
|
||||||
cleanTargetDir(path.join(profileDir, "trybuild"), packages, checkTimestamp);
|
cleanTargetDir(path.join(profileDir, "trybuild"), packages, checkTimestamp);
|
||||||
} catch { }
|
} catch {}
|
||||||
|
|
||||||
// Delete everything else.
|
// Delete everything else.
|
||||||
await rmExcept(profileDir, new Set(["target", "trybuild"]), checkTimestamp);
|
await rmExcept(profileDir, new Set(["target", "trybuild"]), checkTimestamp);
|
||||||
|
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let keepProfile = new Set(["build", ".fingerprint", "deps"]);
|
let keepProfile = new Set(["build", ".fingerprint", "deps"]);
|
||||||
|
|||||||
@@ -74,9 +74,10 @@ export class CacheConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add runner OS to the key to avoid cross-contamination of cache
|
// Add runner OS and CPU architecture to the key to avoid cross-contamination of cache
|
||||||
const runnerOS = os.type();
|
const runnerOS = os.type();
|
||||||
key += `-${runnerOS}`;
|
const runnerArch = os.arch();
|
||||||
|
key += `-${runnerOS}-${runnerArch}`;
|
||||||
|
|
||||||
self.keyPrefix = key;
|
self.keyPrefix = key;
|
||||||
|
|
||||||
@@ -153,7 +154,7 @@ export class CacheConfig {
|
|||||||
|
|
||||||
const workspaceMembers = await workspace.getWorkspaceMembers();
|
const workspaceMembers = await workspace.getWorkspaceMembers();
|
||||||
|
|
||||||
const cargo_manifests = sort_and_uniq(workspaceMembers.map(member => path.join(member.path, "Cargo.toml")));
|
const cargo_manifests = sort_and_uniq(workspaceMembers.map((member) => path.join(member.path, "Cargo.toml")));
|
||||||
|
|
||||||
for (const cargo_manifest of cargo_manifests) {
|
for (const cargo_manifest of cargo_manifests) {
|
||||||
try {
|
try {
|
||||||
@@ -194,7 +195,8 @@ export class CacheConfig {
|
|||||||
hasher.update(JSON.stringify(parsed));
|
hasher.update(JSON.stringify(parsed));
|
||||||
|
|
||||||
parsedKeyFiles.push(cargo_manifest);
|
parsedKeyFiles.push(cargo_manifest);
|
||||||
} catch (e) { // Fallback to caching them as regular file
|
} catch (e) {
|
||||||
|
// Fallback to caching them as regular file
|
||||||
core.warning(`Error parsing Cargo.toml manifest, fallback to caching entire file: ${e}`);
|
core.warning(`Error parsing Cargo.toml manifest, fallback to caching entire file: ${e}`);
|
||||||
keyFiles.push(cargo_manifest);
|
keyFiles.push(cargo_manifest);
|
||||||
}
|
}
|
||||||
@@ -209,7 +211,7 @@ export class CacheConfig {
|
|||||||
if ((parsed.version !== 3 && parsed.version !== 4) || !("package" in parsed)) {
|
if ((parsed.version !== 3 && parsed.version !== 4) || !("package" in parsed)) {
|
||||||
// Fallback to caching them as regular file since this action
|
// Fallback to caching them as regular file since this action
|
||||||
// can only handle Cargo.lock format version 3
|
// can only handle Cargo.lock format version 3
|
||||||
core.warning('Unsupported Cargo.lock format, fallback to caching entire file');
|
core.warning("Unsupported Cargo.lock format, fallback to caching entire file");
|
||||||
keyFiles.push(cargo_lock);
|
keyFiles.push(cargo_lock);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -221,7 +223,8 @@ export class CacheConfig {
|
|||||||
hasher.update(JSON.stringify(packages));
|
hasher.update(JSON.stringify(packages));
|
||||||
|
|
||||||
parsedKeyFiles.push(cargo_lock);
|
parsedKeyFiles.push(cargo_lock);
|
||||||
} catch (e) { // Fallback to caching them as regular file
|
} catch (e) {
|
||||||
|
// Fallback to caching them as regular file
|
||||||
core.warning(`Error parsing Cargo.lock manifest, fallback to caching entire file: ${e}`);
|
core.warning(`Error parsing Cargo.lock manifest, fallback to caching entire file: ${e}`);
|
||||||
keyFiles.push(cargo_lock);
|
keyFiles.push(cargo_lock);
|
||||||
}
|
}
|
||||||
@@ -243,12 +246,14 @@ export class CacheConfig {
|
|||||||
key += `-${lockHash}`;
|
key += `-${lockHash}`;
|
||||||
self.cacheKey = key;
|
self.cacheKey = key;
|
||||||
|
|
||||||
self.cachePaths = [
|
self.cachePaths = [path.join(CARGO_HOME, "registry"), path.join(CARGO_HOME, "git")];
|
||||||
path.join(CARGO_HOME, "registry"),
|
|
||||||
path.join(CARGO_HOME, "git"),
|
|
||||||
];
|
|
||||||
if (self.cacheBin) {
|
if (self.cacheBin) {
|
||||||
self.cachePaths = [path.join(CARGO_HOME, "bin"), ...self.cachePaths];
|
self.cachePaths = [
|
||||||
|
path.join(CARGO_HOME, "bin"),
|
||||||
|
path.join(CARGO_HOME, ".crates.toml"),
|
||||||
|
path.join(CARGO_HOME, ".crates2.json"),
|
||||||
|
...self.cachePaths,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
const cacheTargets = core.getInput("cache-targets").toLowerCase() || "true";
|
const cacheTargets = core.getInput("cache-targets").toLowerCase() || "true";
|
||||||
if (cacheTargets === "true") {
|
if (cacheTargets === "true") {
|
||||||
|
|||||||
@@ -38,19 +38,12 @@ async function run() {
|
|||||||
// Pass a copy of cachePaths to avoid mutating the original array as reported by:
|
// Pass a copy of cachePaths to avoid mutating the original array as reported by:
|
||||||
// https://github.com/actions/toolkit/pull/1378
|
// https://github.com/actions/toolkit/pull/1378
|
||||||
// TODO: remove this once the underlying bug is fixed.
|
// TODO: remove this once the underlying bug is fixed.
|
||||||
const restoreKey = await cacheProvider.cache.restoreCache(
|
const restoreKey = await cacheProvider.cache.restoreCache(config.cachePaths.slice(), key, [config.restoreKey], {
|
||||||
config.cachePaths.slice(),
|
lookupOnly,
|
||||||
key,
|
});
|
||||||
[config.restoreKey],
|
|
||||||
{ lookupOnly }
|
|
||||||
);
|
|
||||||
if (restoreKey) {
|
if (restoreKey) {
|
||||||
const match = restoreKey === key;
|
const match = restoreKey === key;
|
||||||
core.info(
|
core.info(`${lookupOnly ? "Found" : "Restored from"} cache key "${restoreKey}" full match: ${match}.`);
|
||||||
`${
|
|
||||||
lookupOnly ? "Found" : "Restored from"
|
|
||||||
} cache key "${restoreKey}" full match: ${match}.`
|
|
||||||
);
|
|
||||||
if (!match) {
|
if (!match) {
|
||||||
// pre-clean the target directory on cache mismatch
|
// pre-clean the target directory on cache mismatch
|
||||||
for (const workspace of config.workspaces) {
|
for (const workspace of config.workspaces) {
|
||||||
|
|||||||
@@ -36,9 +36,14 @@ async function run() {
|
|||||||
await macOsWorkaround();
|
await macOsWorkaround();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const workspaceCrates = core.getInput("cache-workspace-crates").toLowerCase() || "false";
|
||||||
const allPackages = [];
|
const allPackages = [];
|
||||||
for (const workspace of config.workspaces) {
|
for (const workspace of config.workspaces) {
|
||||||
const packages = await workspace.getPackagesOutsideWorkspaceRoot();
|
const packages = await workspace.getPackagesOutsideWorkspaceRoot();
|
||||||
|
if (workspaceCrates === "true") {
|
||||||
|
const wsMembers = await workspace.getWorkspaceMembers();
|
||||||
|
packages.push(...wsMembers);
|
||||||
|
}
|
||||||
allPackages.push(...packages);
|
allPackages.push(...packages);
|
||||||
try {
|
try {
|
||||||
core.info(`... Cleaning ${workspace.target} ...`);
|
core.info(`... Cleaning ${workspace.target} ...`);
|
||||||
|
|||||||
26
src/utils.ts
26
src/utils.ts
@@ -1,6 +1,7 @@
|
|||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import * as exec from "@actions/exec";
|
import * as exec from "@actions/exec";
|
||||||
import * as buildjetCache from "@actions/buildjet-cache";
|
import * as buildjetCache from "@actions/buildjet-cache";
|
||||||
|
import * as warpbuildCache from "@actions/warpbuild-cache";
|
||||||
import * as ghCache from "@actions/cache";
|
import * as ghCache from "@actions/cache";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
|
||||||
@@ -44,17 +45,32 @@ export async function getCmdOutput(
|
|||||||
return stdout;
|
return stdout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface GhCache {
|
||||||
|
isFeatureAvailable: typeof ghCache.isFeatureAvailable;
|
||||||
|
restoreCache: typeof ghCache.restoreCache;
|
||||||
|
saveCache: (paths: string[], key: string) => Promise<string | number>;
|
||||||
|
}
|
||||||
|
|
||||||
export interface CacheProvider {
|
export interface CacheProvider {
|
||||||
name: string;
|
name: string;
|
||||||
cache: typeof ghCache;
|
cache: GhCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCacheProvider(): CacheProvider {
|
export function getCacheProvider(): CacheProvider {
|
||||||
const cacheProvider = core.getInput("cache-provider");
|
const cacheProvider = core.getInput("cache-provider");
|
||||||
const cache = cacheProvider === "github" ? ghCache : cacheProvider === "buildjet" ? buildjetCache : undefined;
|
let cache: GhCache;
|
||||||
|
switch (cacheProvider) {
|
||||||
if (!cache) {
|
case "github":
|
||||||
throw new Error(`The \`cache-provider\` \`{cacheProvider}\` is not valid.`);
|
cache = ghCache;
|
||||||
|
break;
|
||||||
|
case "buildjet":
|
||||||
|
cache = buildjetCache;
|
||||||
|
break;
|
||||||
|
case "warpbuild":
|
||||||
|
cache = warpbuildCache;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Error(`The \`cache-provider\` \`${cacheProvider}\` is not valid.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ const SAVE_TARGETS = new Set(["lib", "proc-macro"]);
|
|||||||
export class Workspace {
|
export class Workspace {
|
||||||
constructor(public root: string, public target: string) {}
|
constructor(public root: string, public target: string) {}
|
||||||
|
|
||||||
async getPackages(filter: ((p: Meta['packages'][0]) => boolean), ...extraArgs: string[]): Promise<Packages> {
|
async getPackages(filter: (p: Meta["packages"][0]) => boolean, ...extraArgs: string[]): Promise<Packages> {
|
||||||
let packages: Packages = [];
|
let packages: Packages = [];
|
||||||
try {
|
try {
|
||||||
core.debug(`collecting metadata for "${this.root}"`);
|
core.debug(`collecting metadata for "${this.root}"`);
|
||||||
@@ -29,11 +29,11 @@ export class Workspace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async getPackagesOutsideWorkspaceRoot(): Promise<Packages> {
|
public async getPackagesOutsideWorkspaceRoot(): Promise<Packages> {
|
||||||
return await this.getPackages(pkg => !pkg.manifest_path.startsWith(this.root));
|
return await this.getPackages((pkg) => !pkg.manifest_path.startsWith(this.root));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getWorkspaceMembers(): Promise<Packages> {
|
public async getWorkspaceMembers(): Promise<Packages> {
|
||||||
return await this.getPackages(_ => true, "--no-deps");
|
return await this.getPackages((_) => true, "--no-deps");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
1378
tests/Cargo.lock
generated
1378
tests/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -14,4 +14,4 @@ watto = { git = "https://github.com/getsentry/watto", rev = "d71c8218506bddba102
|
|||||||
trybuild = "1"
|
trybuild = "1"
|
||||||
|
|
||||||
[target.'cfg(not(target_env = "msvc"))'.dependencies]
|
[target.'cfg(not(target_env = "msvc"))'.dependencies]
|
||||||
tikv-jemallocator = "0.5.4"
|
tikv-jemallocator = "0.6.0"
|
||||||
|
|||||||
1570
tests/wasm-workspace/Cargo.lock
generated
1570
tests/wasm-workspace/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,5 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
|
resolver = "2"
|
||||||
members = [
|
members = [
|
||||||
"crates/one",
|
"crates/one",
|
||||||
"crates/two",
|
"crates/two",
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ version = "0.1.0"
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
reqwest = "0.11.0"
|
reqwest = "0.12"
|
||||||
async-std = "1"
|
async-std = "1"
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-futures = "0.2"
|
tracing-futures = "0.2"
|
||||||
|
|||||||
@@ -5,4 +5,4 @@ version = "0.1.0"
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = "3"
|
clap = "4"
|
||||||
|
|||||||
Reference in New Issue
Block a user