Compare commits

..

No commits in common. "master" and "v2.7.6" have entirely different histories.

30 changed files with 9850 additions and 121885 deletions

View File

@ -1,50 +0,0 @@
# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/optimizing-pr-creation-version-updates#setting-up-a-cooldown-period-for-dependency-updates
version: 2
updates:
- package-ecosystem: cargo
directories:
- tests
- tests/wasm-workspace
schedule:
interval: weekly
# https://docs.github.com/en/code-security/dependabot/working-with-dependabot/dependabot-options-reference#groups--
# 1 PR per week and group
groups:
cargo-major:
update-types: ["major"]
cargo-minor:
update-types: ["minor"]
cargo-patch:
update-types: ["patch"]
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
groups:
actions:
# Combine all images of the last week
patterns: ["*"]
- package-ecosystem: npm
directory: /
schedule:
interval: weekly
groups:
prd-major:
dependency-type: "production"
update-types: ["major"]
prd-minor:
dependency-type: "production"
update-types: ["minor"]
prd-patch:
dependency-type: "production"
update-types: ["patch"]
dev-major:
dependency-type: "development"
update-types: ["major"]
dev-minor:
dependency-type: "development"
update-types: ["minor"]
dev-patch:
dependency-type: "development"
update-types: ["patch"]

View File

@ -4,7 +4,6 @@ on: [push, pull_request]
jobs:
buildjet:
if: github.repository == 'Swatinem/rust-cache'
strategy:
fail-fast: false
matrix:
@ -17,7 +16,7 @@ jobs:
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v4
- run: rustup toolchain install stable --profile minimal --no-self-update

View File

@ -13,10 +13,9 @@ on:
jobs:
check-dist:
if: github.repository == 'Swatinem/rust-cache'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v4
- name: Setup Node.js 20.x
uses: actions/setup-node@v4

View File

@ -4,7 +4,6 @@ on: [push, pull_request]
jobs:
coverage:
if: github.repository == 'Swatinem/rust-cache'
strategy:
fail-fast: false
matrix:
@ -17,7 +16,7 @@ jobs:
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v4
- run: rustup toolchain install stable --profile minimal --component llvm-tools-preview --no-self-update

View File

@ -1,25 +0,0 @@
# https://docs.github.com/en/code-security/dependabot/working-with-dependabot/automating-dependabot-with-github-actions#enabling-automerge-on-a-pull-request
name: Dependabot Automation
on: pull_request
permissions:
contents: write
pull-requests: write
jobs:
automerge:
runs-on: ubuntu-latest
if: github.event.pull_request.user.login == 'dependabot[bot]' && github.repository == 'Swatinem/rust-cache'
steps:
- name: Fetch metadata
id: metadata
uses: dependabot/fetch-metadata@v2
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Auto-merge Patch PRs
if: steps.metadata.outputs.update-type == 'version-update:semver-patch'
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}

View File

@ -4,7 +4,6 @@ on: [push, pull_request]
jobs:
git-registry:
if: github.repository == 'Swatinem/rust-cache'
strategy:
fail-fast: false
matrix:
@ -18,7 +17,7 @@ jobs:
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: git
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v4
- run: rustup toolchain install stable --profile minimal --no-self-update

View File

@ -4,7 +4,6 @@ on: [push, pull_request]
jobs:
install:
if: github.repository == 'Swatinem/rust-cache'
strategy:
fail-fast: false
matrix:
@ -17,7 +16,7 @@ jobs:
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v4
- run: rustup toolchain install stable --profile minimal --no-self-update

View File

@ -4,7 +4,6 @@ on: [push, pull_request]
jobs:
simple:
if: github.repository == 'Swatinem/rust-cache'
strategy:
fail-fast: false
matrix:
@ -17,7 +16,7 @@ jobs:
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v4
- run: rustup toolchain install stable --profile minimal --no-self-update

View File

@ -4,7 +4,6 @@ on: [push, pull_request]
jobs:
target-dir:
if: github.repository == 'Swatinem/rust-cache'
strategy:
fail-fast: false
matrix:
@ -17,7 +16,7 @@ jobs:
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v4
- run: rustup toolchain install stable --profile minimal --no-self-update

View File

@ -4,7 +4,6 @@ on: [push, pull_request]
jobs:
workspaces:
if: github.repository == 'Swatinem/rust-cache'
strategy:
fail-fast: false
matrix:
@ -17,7 +16,7 @@ jobs:
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v4
- run: rustup toolchain install stable --profile minimal --target wasm32-unknown-unknown --no-self-update
@ -27,10 +26,8 @@ jobs:
tests
tests/wasm-workspace
- name: cargo check (tests)
- run: cargo check
working-directory: tests
run: cargo check
- name: cargo check (tests/wasm-workspace)
- run: cargo check
working-directory: tests/wasm-workspace
run: cargo check

View File

@ -1,29 +1,5 @@
# 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
- Work around upstream problem that causes cache saving to hang for minutes.

View File

@ -6,7 +6,7 @@ sensible defaults.
## Example usage
```yaml
- uses: actions/checkout@v5
- uses: actions/checkout@v4
# selecting a toolchain either by action or manual `rustup` calls should happen
# before the plugin, as the cache uses the current rustc version as its cache key
@ -60,12 +60,6 @@ sensible defaults.
# default: "false"
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.
# If `false`, the cache is only restored.
# Useful for jobs where the matrix is additive e.g. additional Cargo features,
@ -82,7 +76,7 @@ sensible defaults.
lookup-only: ""
# Specifies what to use as the backend providing cache
# Can be set to "github", "buildjet", or "warpbuild"
# Can be set to either "github" or "buildjet"
# default: "github"
cache-provider: ""

View File

@ -32,16 +32,12 @@ inputs:
description: "Determines which crates are cached. If `true` all crates will be cached, otherwise only dependent crates will be cached."
required: 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:
description: "Determiners whether the cache should be saved. If `false`, the cache is only restored."
required: false
default: "true"
cache-provider:
description: "Determines which provider to use for caching. Options are github, buildjet, or warpbuild. Defaults to github."
description: "Determines which provider to use for caching. Options are github or buildjet, defaults to github."
required: false
default: "github"
cache-bin:

63611
dist/restore/index.js vendored

File diff suppressed because one or more lines are too long

63612
dist/save/index.js vendored

File diff suppressed because one or more lines are too long

1112
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
{
"private": true,
"name": "rust-cache",
"version": "2.8.0",
"version": "2.7.6",
"description": "A GitHub Action that implements smart caching for rust/cargo projects with sensible defaults.",
"keywords": [
"actions",
@ -23,19 +23,18 @@
"homepage": "https://github.com/Swatinem/rust-cache#readme",
"dependencies": {
"@actions/buildjet-cache": "npm:github-actions.cache-buildjet@0.2.0",
"@actions/warpbuild-cache": "npm:github-actions.warp-cache@1.4.7",
"@actions/cache": "^4.0.5",
"@actions/cache": "^4.0.0",
"@actions/core": "^1.11.1",
"@actions/exec": "^1.1.1",
"@actions/glob": "^0.5.0",
"@actions/io": "^1.1.3",
"smol-toml": "^1.4.2"
"smol-toml": "^1.3.0"
},
"devDependencies": {
"@types/node": "^22.16.0",
"@vercel/ncc": "^0.38.3",
"@types/node": "^22.7.5",
"@vercel/ncc": "^0.38.2",
"linefix": "^0.1.1",
"typescript": "5.8.3"
"typescript": "5.7.2"
},
"scripts": {
"prepare": "ncc build --target es2020 -o dist/restore src/restore.ts && ncc build --target es2020 -o dist/save src/save.ts && linefix dist"

View File

@ -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/eupn/macrotest/blob/c4151a5f9f545942f4971980b5d264ebcd0b1d11/src/cargo.rs#L27
cleanTargetDir(path.join(profileDir, "target"), packages, checkTimestamp);
} catch {}
} catch { }
try {
// https://github.com/dtolnay/trybuild/blob/eec8ca6cb9b8f53d0caf1aa499d99df52cae8b40/src/cargo.rs#L50
cleanTargetDir(path.join(profileDir, "trybuild"), packages, checkTimestamp);
} catch {}
} catch { }
// Delete everything else.
await rmExcept(profileDir, new Set(["target", "trybuild"]), checkTimestamp);
return;
return
}
let keepProfile = new Set(["build", ".fingerprint", "deps"]);

View File

@ -74,10 +74,9 @@ export class CacheConfig {
}
}
// Add runner OS and CPU architecture to the key to avoid cross-contamination of cache
// Add runner OS to the key to avoid cross-contamination of cache
const runnerOS = os.type();
const runnerArch = os.arch();
key += `-${runnerOS}-${runnerArch}`;
key += `-${runnerOS}`;
self.keyPrefix = key;
@ -154,7 +153,7 @@ export class CacheConfig {
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) {
try {
@ -195,8 +194,7 @@ export class CacheConfig {
hasher.update(JSON.stringify(parsed));
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}`);
keyFiles.push(cargo_manifest);
}
@ -211,7 +209,7 @@ export class CacheConfig {
if ((parsed.version !== 3 && parsed.version !== 4) || !("package" in parsed)) {
// Fallback to caching them as regular file since this action
// 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);
continue;
}
@ -223,8 +221,7 @@ export class CacheConfig {
hasher.update(JSON.stringify(packages));
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}`);
keyFiles.push(cargo_lock);
}
@ -246,14 +243,12 @@ export class CacheConfig {
key += `-${lockHash}`;
self.cacheKey = key;
self.cachePaths = [path.join(CARGO_HOME, "registry"), path.join(CARGO_HOME, "git")];
if (self.cacheBin) {
self.cachePaths = [
path.join(CARGO_HOME, "bin"),
path.join(CARGO_HOME, ".crates.toml"),
path.join(CARGO_HOME, ".crates2.json"),
...self.cachePaths,
path.join(CARGO_HOME, "registry"),
path.join(CARGO_HOME, "git"),
];
if (self.cacheBin) {
self.cachePaths = [path.join(CARGO_HOME, "bin"), ...self.cachePaths];
}
const cacheTargets = core.getInput("cache-targets").toLowerCase() || "true";
if (cacheTargets === "true") {

View File

@ -38,12 +38,19 @@ async function run() {
// Pass a copy of cachePaths to avoid mutating the original array as reported by:
// https://github.com/actions/toolkit/pull/1378
// TODO: remove this once the underlying bug is fixed.
const restoreKey = await cacheProvider.cache.restoreCache(config.cachePaths.slice(), key, [config.restoreKey], {
lookupOnly,
});
const restoreKey = await cacheProvider.cache.restoreCache(
config.cachePaths.slice(),
key,
[config.restoreKey],
{ lookupOnly }
);
if (restoreKey) {
const match = restoreKey === key;
core.info(`${lookupOnly ? "Found" : "Restored from"} cache key "${restoreKey}" full match: ${match}.`);
core.info(
`${
lookupOnly ? "Found" : "Restored from"
} cache key "${restoreKey}" full match: ${match}.`
);
if (!match) {
// pre-clean the target directory on cache mismatch
for (const workspace of config.workspaces) {

View File

@ -36,14 +36,9 @@ async function run() {
await macOsWorkaround();
}
const workspaceCrates = core.getInput("cache-workspace-crates").toLowerCase() || "false";
const allPackages = [];
for (const workspace of config.workspaces) {
const packages = await workspace.getPackagesOutsideWorkspaceRoot();
if (workspaceCrates === "true") {
const wsMembers = await workspace.getWorkspaceMembers();
packages.push(...wsMembers);
}
allPackages.push(...packages);
try {
core.info(`... Cleaning ${workspace.target} ...`);

View File

@ -1,7 +1,6 @@
import * as core from "@actions/core";
import * as exec from "@actions/exec";
import * as buildjetCache from "@actions/buildjet-cache";
import * as warpbuildCache from "@actions/warpbuild-cache";
import * as ghCache from "@actions/cache";
import fs from "fs";
@ -45,32 +44,17 @@ export async function getCmdOutput(
return stdout;
}
export interface GhCache {
isFeatureAvailable: typeof ghCache.isFeatureAvailable;
restoreCache: typeof ghCache.restoreCache;
saveCache: (paths: string[], key: string) => Promise<string | number>;
}
export interface CacheProvider {
name: string;
cache: GhCache;
cache: typeof ghCache;
}
export function getCacheProvider(): CacheProvider {
const cacheProvider = core.getInput("cache-provider");
let cache: GhCache;
switch (cacheProvider) {
case "github":
cache = ghCache;
break;
case "buildjet":
cache = buildjetCache;
break;
case "warpbuild":
cache = warpbuildCache;
break;
default:
throw new Error(`The \`cache-provider\` \`${cacheProvider}\` is not valid.`);
const cache = cacheProvider === "github" ? ghCache : cacheProvider === "buildjet" ? buildjetCache : undefined;
if (!cache) {
throw new Error(`The \`cache-provider\` \`{cacheProvider}\` is not valid.`);
}
return {

View File

@ -8,14 +8,13 @@ const SAVE_TARGETS = new Set(["lib", "proc-macro"]);
export class Workspace {
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 = [];
try {
core.debug(`collecting metadata for "${this.root}"`);
const meta: Meta = JSON.parse(
await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1", ...extraArgs], {
cwd: this.root,
env: { "CARGO_ENCODED_RUSTFLAGS": "" },
}),
);
core.debug(`workspace "${this.root}" has ${meta.packages.length} packages`);
@ -30,11 +29,11 @@ export class Workspace {
}
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> {
return await this.getPackages((_) => true, "--no-deps");
return await this.getPackages(_ => true, "--no-deps");
}
}

1435
tests/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -8,10 +8,10 @@ edition = "2021"
[dependencies]
reqwest = "0.12.1"
jsonpath_lib_polars_vendor = "0.0.1"
watto = { git = "https://github.com/getsentry/watto", rev = "39ccb9add289c1f23c89f40506f4a80b2f4011b9", features = ["strings"] }
watto = { git = "https://github.com/getsentry/watto", rev = "d71c8218506bddba102a124a460d64da25e303dc", features = ["strings"] }
[dev-dependencies]
trybuild = "1"
[target.'cfg(not(target_env = "msvc"))'.dependencies]
tikv-jemallocator = "0.6.0"
tikv-jemallocator = "0.5.4"

View File

@ -2,4 +2,4 @@ error[E0599]: no method named `foobar` found for reference `&'static str` in the
--> tests/trybuild/fail_to_compile.rs:2:14
|
2 | "foobar".foobar();
| ^^^^^^ method not found in `&'static str`
| ^^^^^^ method not found in `&str`

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,4 @@
[workspace]
resolver = "2"
members = [
"crates/one",
"crates/two",

View File

@ -5,7 +5,7 @@ version = "0.1.0"
edition = "2021"
[dependencies]
reqwest = "0.12"
reqwest = "0.11.0"
async-std = "1"
tracing = "0.1"
tracing-futures = "0.2"

View File

@ -5,4 +5,4 @@ version = "0.1.0"
edition = "2021"
[dependencies]
clap = "4"
clap = "3"