mirror of
https://github.com/Swatinem/rust-cache
synced 2026-09-07 20:03:24 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f0d9c38877 | ||
|
|
ccd9742ce3 | ||
|
|
258712b0b7 | ||
|
|
a45951ff88 | ||
|
|
b882611972 | ||
|
|
6323deb102 | ||
|
|
b16e8d71b2 | ||
|
|
3bf42ac996 | ||
|
|
6e5b278ead | ||
|
|
5adc05f6aa | ||
|
|
66b1e95261 | ||
|
|
72d126e709 | ||
|
|
48968d2131 | ||
|
|
9f151aca7c | ||
|
|
0e24e5dcec | ||
|
|
7e35be21c2 | ||
|
|
0b5b468d98 | ||
|
|
a31add9f17 | ||
|
|
6dfd3c5062 | ||
|
|
b88d7b9a78 | ||
|
|
cb96ac76d8 | ||
|
|
3cd715cd54 | ||
|
|
2903027c68 | ||
|
|
7e2fe4383b | ||
|
|
baf1a810e9 | ||
|
|
f27557af97 | ||
|
|
c106961fee | ||
|
|
1fe0a60026 | ||
|
|
be9aa033ee | ||
|
|
874b06e0d3 | ||
|
|
8ba370a790 | ||
|
|
65012b4902 | ||
|
|
faada81aeb | ||
|
|
77fc9855f4 | ||
|
|
919333daf4 | ||
|
|
455db766b8 | ||
|
|
174de315c6 | ||
|
|
91cad52c87 | ||
|
|
3d9a6aef83 | ||
|
|
13b62626e8 | ||
|
|
bd17f4a47e | ||
|
|
469cb0e247 | ||
|
|
3a556350bd | ||
|
|
22de9d98ab | ||
|
|
ed5e89b8ff | ||
|
|
f51f967e15 | ||
|
|
85fb4247b7 | ||
|
|
5084d130b2 | ||
|
|
bc1860267c | ||
|
|
d7ac6f694d | ||
|
|
e18b497796 |
@@ -0,0 +1,34 @@
|
||||
name: binstall
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
permissions: {}
|
||||
|
||||
jobs:
|
||||
binstall:
|
||||
if: github.repository == 'Swatinem/rust-cache'
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
|
||||
name: Test `cargo binstall` on ${{ matrix.os }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- run: rustup toolchain install stable --profile minimal --no-self-update
|
||||
|
||||
- uses: cargo-bins/cargo-binstall@e00d2c94cc0067b77737821097a62d91c0301baa # v1.21.1
|
||||
|
||||
- uses: ./
|
||||
|
||||
- run: cargo binstall -y cargo-deny
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -18,12 +18,12 @@ jobs:
|
||||
if: github.repository == 'Swatinem/rust-cache'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Setup Node.js 24.x
|
||||
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
|
||||
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
|
||||
with:
|
||||
node-version: 24.x
|
||||
cache: npm
|
||||
@@ -43,7 +43,7 @@ jobs:
|
||||
fi
|
||||
id: diff
|
||||
|
||||
- uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
|
||||
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
|
||||
with:
|
||||
name: dist
|
||||
|
||||
@@ -19,13 +19,13 @@ jobs:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- run: rustup toolchain install stable --profile minimal --component llvm-tools-preview --no-self-update
|
||||
|
||||
- uses: taiki-e/install-action@64c5c20c872907b6f7cd50994ac189e7274160f2 # v2.68.26
|
||||
- uses: taiki-e/install-action@82cd3e7658a6f96c86c0234aeeda1748937cb0a1 # v2.85.13
|
||||
with:
|
||||
tool: cargo-llvm-cov
|
||||
|
||||
|
||||
@@ -15,10 +15,10 @@ jobs:
|
||||
steps:
|
||||
- name: Fetch metadata
|
||||
id: metadata
|
||||
uses: dependabot/fetch-metadata@21025c705c08248db411dc16f3619e6b5f9ea21a # v2.5.0
|
||||
uses: dependabot/fetch-metadata@25dd0e34f4fe68f24cc83900b1fe3fe149efef98 # v3.1.0
|
||||
with:
|
||||
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
fetch-depth: 2
|
||||
persist-credentials: false
|
||||
@@ -37,7 +37,7 @@ jobs:
|
||||
fi
|
||||
- name: Setup node if necessary
|
||||
if: steps.npm.outputs.changed != ''
|
||||
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
|
||||
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
|
||||
with:
|
||||
node-version: 24.x
|
||||
cache: npm
|
||||
|
||||
@@ -20,7 +20,7 @@ jobs:
|
||||
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: git
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ jobs:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
@@ -54,7 +54,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
|
||||
@@ -16,11 +16,11 @@ jobs:
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- uses: cachix/install-nix-action@1ca7d21a94afc7c957383a2d217460d980de4934 # v31.10.1
|
||||
- uses: cachix/install-nix-action@13d8dd58da0234aa297dedd986986ccb8e7f3e24 # v31.11.1
|
||||
|
||||
- uses: ./
|
||||
with:
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
name: save-restore
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
permissions: {}
|
||||
|
||||
jobs:
|
||||
save:
|
||||
if: github.repository == 'Swatinem/rust-cache'
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
|
||||
name: Save a new cache on ${{ matrix.os }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- run: rustup toolchain install stable --profile minimal --no-self-update
|
||||
|
||||
# Use a per-run key so this job always exercises the post-step save path.
|
||||
- uses: ./
|
||||
with:
|
||||
workspaces: tests
|
||||
shared-key: save-restore-${{ matrix.os }}-${{ github.run_id }}-${{ github.run_attempt }}
|
||||
|
||||
- run: cargo check
|
||||
working-directory: tests
|
||||
|
||||
restore:
|
||||
if: github.repository == 'Swatinem/rust-cache'
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
|
||||
name: Restore the newly saved cache on ${{ matrix.os }}
|
||||
needs: save
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- run: rustup toolchain install stable --profile minimal --no-self-update
|
||||
|
||||
- id: cache
|
||||
uses: ./
|
||||
with:
|
||||
workspaces: tests
|
||||
shared-key: save-restore-${{ matrix.os }}-${{ github.run_id }}-${{ github.run_attempt }}
|
||||
save-if: "false"
|
||||
|
||||
- name: Verify exact cache hit
|
||||
if: steps.cache.outputs.cache-hit != 'true'
|
||||
shell: bash
|
||||
run: |
|
||||
echo "The cache created by the save job could not be restored." >&2
|
||||
exit 1
|
||||
@@ -19,7 +19,7 @@ jobs:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ jobs:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
name: buildjet
|
||||
name: warpbuild
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
permissions: {}
|
||||
|
||||
jobs:
|
||||
buildjet:
|
||||
warpbuild:
|
||||
if: github.repository == 'Swatinem/rust-cache'
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
|
||||
name: Test buildjet provider on ${{ matrix.os }}
|
||||
name: Test warpbuild provider on ${{ matrix.os }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
@@ -28,7 +28,7 @@ jobs:
|
||||
- uses: ./
|
||||
with:
|
||||
workspaces: tests
|
||||
cache-provider: buildjet
|
||||
cache-provider: warpbuild
|
||||
|
||||
- run: |
|
||||
cargo check
|
||||
@@ -19,7 +19,7 @@ jobs:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@ jobs:
|
||||
security-events: write # for uploading results to the Security tab
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Run zizmor 🌈
|
||||
uses: zizmorcore/zizmor-action@71321a20a9ded102f6e9ce5718a2fcec2c4f70d8 # v0.5.2
|
||||
uses: zizmorcore/zizmor-action@3dc1ecc9bcb9e94e9b2c709687979e1298497054 # v0.6.2
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
node_modules/
|
||||
target/
|
||||
src/*.js
|
||||
.build
|
||||
|
||||
# Editors
|
||||
.idea/
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
# Changelog
|
||||
|
||||
## 2.9.2
|
||||
|
||||
- Fix `credentials.toml` cleanup
|
||||
- Improvements to cleanup, preserving more valid targets
|
||||
- Improvements to `cargo install` handling
|
||||
- Correctly sort/dedupe Rust versions
|
||||
|
||||
## 2.9.1
|
||||
|
||||
- Fix regression in hash calculation
|
||||
|
||||
## 2.9.0
|
||||
|
||||
- Update to `node24`
|
||||
|
||||
@@ -6,7 +6,7 @@ sensible defaults.
|
||||
## Example usage
|
||||
|
||||
```yaml
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
# 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
|
||||
@@ -32,7 +32,7 @@ sensible defaults.
|
||||
# default: "true"
|
||||
add-job-id-key: ""
|
||||
|
||||
# Weather the a hash of the rust environment should be included in the cache key.
|
||||
# Whether the a hash of the rust environment should be included in the cache key.
|
||||
# This includes a hash of all Cargo.toml/Cargo.lock files, rust-toolchain files,
|
||||
# and .cargo/config.toml files (if present), as well as the specified 'env-vars'.
|
||||
# default: "true"
|
||||
@@ -92,7 +92,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 "github", or "warpbuild"
|
||||
# default: "github"
|
||||
cache-provider: ""
|
||||
|
||||
@@ -142,7 +142,7 @@ This action currently caches the following files/directories:
|
||||
This cache is automatically keyed by:
|
||||
|
||||
- the github [`job_id`](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_id)
|
||||
(if `add-job-id-key` is `"true"`),
|
||||
(if `add-job-id-key` is `"true"`),
|
||||
- the rustc release / host / hash (for all installed toolchains when
|
||||
available),
|
||||
- the following values, if `add-rust-environment-hash-key` is `"true"`:
|
||||
@@ -210,5 +210,5 @@ to see those details as well as further details related to caching operations.
|
||||
- The cache cleaning process currently removes all the files from `~/.cargo/bin`
|
||||
that were present before the action ran (for example `rustc`), by default.
|
||||
This can be an issue on long-running self-hosted runners, where such state
|
||||
is expected to be preserved across runs. You can work around this by setting
|
||||
is expected to be preserved across runs. You can work around this by setting
|
||||
`cache-bin: "false"`.
|
||||
|
||||
+3
-3
@@ -49,7 +49,7 @@ inputs:
|
||||
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 warpbuild. Defaults to github."
|
||||
required: false
|
||||
default: "github"
|
||||
cache-bin:
|
||||
@@ -69,8 +69,8 @@ outputs:
|
||||
description: "A boolean value that indicates an exact match was found."
|
||||
runs:
|
||||
using: "node24"
|
||||
main: "dist/restore/index.js"
|
||||
post: "dist/save/index.js"
|
||||
main: "dist/restore.js"
|
||||
post: "dist/save.js"
|
||||
post-if: "success() || env.CACHE_ON_FAILURE == 'true'"
|
||||
branding:
|
||||
icon: "archive"
|
||||
|
||||
Vendored
+48677
File diff suppressed because it is too large
Load Diff
Vendored
+247742
File diff suppressed because one or more lines are too long
Vendored
+35164
File diff suppressed because one or more lines are too long
Vendored
+101
@@ -0,0 +1,101 @@
|
||||
import { e as error, g as getCacheProvider, a as getInput, b as exportVariable, C as CacheConfig, i as info, c as cleanTargetDir, r as reportError, s as setOutput } from './cleanup-BPghO_DY.js';
|
||||
import 'os';
|
||||
import 'crypto';
|
||||
import 'fs';
|
||||
import 'path';
|
||||
import 'http';
|
||||
import 'https';
|
||||
import 'net';
|
||||
import 'tls';
|
||||
import 'events';
|
||||
import 'assert';
|
||||
import 'util';
|
||||
import 'node:assert';
|
||||
import 'node:net';
|
||||
import 'node:http';
|
||||
import 'node:stream';
|
||||
import 'node:buffer';
|
||||
import 'node:util';
|
||||
import 'node:querystring';
|
||||
import 'node:events';
|
||||
import 'node:diagnostics_channel';
|
||||
import 'node:tls';
|
||||
import 'node:zlib';
|
||||
import 'node:perf_hooks';
|
||||
import 'node:util/types';
|
||||
import 'node:worker_threads';
|
||||
import 'node:url';
|
||||
import 'node:async_hooks';
|
||||
import 'node:console';
|
||||
import 'node:dns';
|
||||
import 'string_decoder';
|
||||
import 'child_process';
|
||||
import 'timers';
|
||||
import 'stream';
|
||||
import 'fs/promises';
|
||||
|
||||
process.on("uncaughtException", (e) => {
|
||||
error(e.message);
|
||||
if (e.stack) {
|
||||
error(e.stack);
|
||||
}
|
||||
});
|
||||
async function run() {
|
||||
const cacheProvider = await getCacheProvider();
|
||||
if (!cacheProvider.cache.isFeatureAvailable()) {
|
||||
setCacheHitOutput(false);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
var cacheOnFailure = getInput("cache-on-failure").toLowerCase();
|
||||
if (cacheOnFailure !== "true") {
|
||||
cacheOnFailure = "false";
|
||||
}
|
||||
var lookupOnly = getInput("lookup-only").toLowerCase() === "true";
|
||||
exportVariable("CACHE_ON_FAILURE", cacheOnFailure);
|
||||
exportVariable("CARGO_INCREMENTAL", 0);
|
||||
const config = await CacheConfig.new();
|
||||
config.printInfo(cacheProvider);
|
||||
info("");
|
||||
info(`... ${lookupOnly ? "Checking" : "Restoring"} cache ...`);
|
||||
const key = config.cacheKey;
|
||||
// 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,
|
||||
});
|
||||
if (restoreKey) {
|
||||
const match = restoreKey.localeCompare(key, undefined, {
|
||||
sensitivity: "accent",
|
||||
}) === 0;
|
||||
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) {
|
||||
try {
|
||||
await cleanTargetDir(workspace.target, [], true);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
// We restored the cache but it is not a full match.
|
||||
config.saveState();
|
||||
}
|
||||
setCacheHitOutput(match);
|
||||
}
|
||||
else {
|
||||
info("No cache found.");
|
||||
config.saveState();
|
||||
setCacheHitOutput(false);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
setCacheHitOutput(false);
|
||||
reportError(e);
|
||||
}
|
||||
process.exit();
|
||||
}
|
||||
function setCacheHitOutput(cacheHit) {
|
||||
setOutput("cache-hit", cacheHit.toString());
|
||||
}
|
||||
run();
|
||||
Vendored
-250488
File diff suppressed because one or more lines are too long
Vendored
+121
@@ -0,0 +1,121 @@
|
||||
import { e as error, g as getCacheProvider, a as getInput, d as isCacheUpToDate, i as info, C as CacheConfig, c as cleanTargetDir, f as debug, h as cleanRegistry, j as cleanBin, k as cleanGit, r as reportError, l as exec } from './cleanup-BPghO_DY.js';
|
||||
import 'os';
|
||||
import 'crypto';
|
||||
import 'fs';
|
||||
import 'path';
|
||||
import 'http';
|
||||
import 'https';
|
||||
import 'net';
|
||||
import 'tls';
|
||||
import 'events';
|
||||
import 'assert';
|
||||
import 'util';
|
||||
import 'node:assert';
|
||||
import 'node:net';
|
||||
import 'node:http';
|
||||
import 'node:stream';
|
||||
import 'node:buffer';
|
||||
import 'node:util';
|
||||
import 'node:querystring';
|
||||
import 'node:events';
|
||||
import 'node:diagnostics_channel';
|
||||
import 'node:tls';
|
||||
import 'node:zlib';
|
||||
import 'node:perf_hooks';
|
||||
import 'node:util/types';
|
||||
import 'node:worker_threads';
|
||||
import 'node:url';
|
||||
import 'node:async_hooks';
|
||||
import 'node:console';
|
||||
import 'node:dns';
|
||||
import 'string_decoder';
|
||||
import 'child_process';
|
||||
import 'timers';
|
||||
import 'stream';
|
||||
import 'fs/promises';
|
||||
|
||||
process.on("uncaughtException", (e) => {
|
||||
error(e.message);
|
||||
if (e.stack) {
|
||||
error(e.stack);
|
||||
}
|
||||
});
|
||||
async function run() {
|
||||
const cacheProvider = await getCacheProvider();
|
||||
const save = getInput("save-if").toLowerCase() || "true";
|
||||
if (!(cacheProvider.cache.isFeatureAvailable() && save === "true")) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (isCacheUpToDate()) {
|
||||
info(`Cache up-to-date.`);
|
||||
return;
|
||||
}
|
||||
const config = CacheConfig.fromState();
|
||||
config.printInfo(cacheProvider);
|
||||
info("");
|
||||
// TODO: remove this once https://github.com/actions/toolkit/pull/553 lands
|
||||
if (process.env["RUNNER_OS"] == "macOS") {
|
||||
await macOsWorkaround();
|
||||
}
|
||||
const workspaceCrates = getInput("cache-workspace-crates").toLowerCase() || "false";
|
||||
const allPackages = [];
|
||||
for (const workspace of config.workspaces) {
|
||||
const packages = await workspace.getPackagesOutsideWorkspaceRoot(config.cmdFormat);
|
||||
if (workspaceCrates === "true") {
|
||||
const wsMembers = await workspace.getWorkspaceMembers(config.cmdFormat);
|
||||
packages.push(...wsMembers);
|
||||
}
|
||||
allPackages.push(...packages);
|
||||
try {
|
||||
info(`... Cleaning ${workspace.target} ...`);
|
||||
await cleanTargetDir(workspace.target, packages);
|
||||
}
|
||||
catch (e) {
|
||||
debug(`${e.stack}`);
|
||||
}
|
||||
}
|
||||
try {
|
||||
const crates = getInput("cache-all-crates").toLowerCase() || "false";
|
||||
info(`... Cleaning cargo registry (cache-all-crates: ${crates}) ...`);
|
||||
await cleanRegistry(allPackages, crates !== "true");
|
||||
}
|
||||
catch (e) {
|
||||
debug(`${e.stack}`);
|
||||
}
|
||||
if (config.cacheBin) {
|
||||
try {
|
||||
info(`... Cleaning cargo/bin ...`);
|
||||
await cleanBin(config.cargoBins);
|
||||
}
|
||||
catch (e) {
|
||||
debug(`${e.stack}`);
|
||||
}
|
||||
}
|
||||
try {
|
||||
info(`... Cleaning cargo git cache ...`);
|
||||
await cleanGit(allPackages);
|
||||
}
|
||||
catch (e) {
|
||||
debug(`${e.stack}`);
|
||||
}
|
||||
info(`... Saving cache ...`);
|
||||
// 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.
|
||||
await cacheProvider.cache.saveCache(config.cachePaths.slice(), config.cacheKey);
|
||||
}
|
||||
catch (e) {
|
||||
reportError(e);
|
||||
}
|
||||
process.exit();
|
||||
}
|
||||
run();
|
||||
async function macOsWorkaround() {
|
||||
try {
|
||||
// Workaround for https://github.com/actions/cache/issues/403
|
||||
// Also see https://github.com/rust-lang/cargo/issues/8603
|
||||
await exec("sudo", ["/usr/sbin/purge"], { silent: true });
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
Vendored
-250509
File diff suppressed because one or more lines are too long
Vendored
+1825
File diff suppressed because it is too large
Load Diff
Generated
+1478
-329
File diff suppressed because it is too large
Load Diff
+23
-11
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "rust-cache",
|
||||
"version": "2.9.1",
|
||||
"version": "2.9.2",
|
||||
"description": "A GitHub Action that implements smart caching for rust/cargo projects with sensible defaults.",
|
||||
"keywords": [
|
||||
"actions",
|
||||
@@ -21,23 +21,35 @@
|
||||
"url": "https://github.com/sponsors/Swatinem"
|
||||
},
|
||||
"homepage": "https://github.com/Swatinem/rust-cache#readme",
|
||||
"type": "module",
|
||||
"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": "^6.0.0",
|
||||
"@actions/core": "^3.0.0",
|
||||
"@actions/cache": "^6.2.0",
|
||||
"@actions/core": "^3.0.1",
|
||||
"@actions/exec": "^3.0.0",
|
||||
"@actions/glob": "^0.6.1",
|
||||
"@actions/glob": "^0.7.0",
|
||||
"@actions/io": "^3.0.2",
|
||||
"smol-toml": "^1.6.0"
|
||||
"@actions/warpbuild-cache": "npm:github-actions.warp-cache@1.4.7",
|
||||
"smol-toml": "^1.7.1"
|
||||
},
|
||||
"overrides": {
|
||||
"@actions/cache": {
|
||||
"@actions/glob": "$@actions/glob"
|
||||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^25.4.0",
|
||||
"@vercel/ncc": "^0.38.4",
|
||||
"@rollup/plugin-commonjs": "^29.0.3",
|
||||
"@rollup/plugin-json": "^6.1.0",
|
||||
"@rollup/plugin-node-resolve": "^16.0.3",
|
||||
"@types/node": "^26.1.2",
|
||||
"linefix": "^0.1.1",
|
||||
"typescript": "5.9.3"
|
||||
"rollup": "^4.62.4",
|
||||
"typescript": "7.0.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"
|
||||
"clean": "node -e \"(async () => { try { await require('fs/promises').rm('dist', { recursive: true }); } catch {} })()\"",
|
||||
"prebuild": "npm run clean",
|
||||
"build": "tsc && rollup --config .build/rollup.config.js",
|
||||
"prepublishOnly": "npm run test",
|
||||
"prepare": "npm run build && linefix dist"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import commonjs from "@rollup/plugin-commonjs";
|
||||
import json from "@rollup/plugin-json";
|
||||
import nodeResolve from "@rollup/plugin-node-resolve";
|
||||
import type { RollupWatchOptions } from "rollup";
|
||||
|
||||
const config: RollupWatchOptions = {
|
||||
input: ["./.build/src/restore.js", "./.build/src/save.js"],
|
||||
output: { dir: "./dist", format: "es" },
|
||||
plugins: [nodeResolve({ preferBuiltins: true }), commonjs(), json()],
|
||||
};
|
||||
export default config;
|
||||
+40
-41
@@ -3,9 +3,9 @@ import * as io from "@actions/io";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
import { CARGO_HOME } from "./config";
|
||||
import { exists } from "./utils";
|
||||
import { Packages } from "./workspace";
|
||||
import { CARGO_HOME } from "./config.js";
|
||||
import { exists } from "./utils.js";
|
||||
import { Packages } from "./workspace.js";
|
||||
|
||||
export async function cleanTargetDir(targetDir: string, packages: Packages, checkTimestamp = false) {
|
||||
core.debug(`cleaning target directory "${targetDir}"`);
|
||||
@@ -15,15 +15,19 @@ export async function cleanTargetDir(targetDir: string, packages: Packages, chec
|
||||
for await (const dirent of dir) {
|
||||
if (dirent.isDirectory()) {
|
||||
let dirName = path.join(dir.path, dirent.name);
|
||||
// is it a profile dir, or a nested target dir?
|
||||
let isNestedTarget =
|
||||
(await exists(path.join(dirName, "CACHEDIR.TAG"))) || (await exists(path.join(dirName, ".rustc_info.json")));
|
||||
// Target-triple directories do not contain Cargo's target directory
|
||||
// markers, so identify profiles by their artifact directories as well.
|
||||
const isProfile =
|
||||
dirent.name === "tests" ||
|
||||
(await exists(path.join(dirName, "build"))) ||
|
||||
(await exists(path.join(dirName, ".fingerprint"))) ||
|
||||
(await exists(path.join(dirName, "deps")));
|
||||
|
||||
try {
|
||||
if (isNestedTarget) {
|
||||
await cleanTargetDir(dirName, packages, checkTimestamp);
|
||||
} else {
|
||||
if (isProfile) {
|
||||
await cleanProfileTarget(dirName, packages, checkTimestamp);
|
||||
} else {
|
||||
await cleanTargetDir(dirName, packages, checkTimestamp);
|
||||
}
|
||||
} catch {}
|
||||
} else if (dirent.name !== "CACHEDIR.TAG") {
|
||||
@@ -58,7 +62,7 @@ async function cleanProfileTarget(profileDir: string, packages: Packages, checkT
|
||||
let keepProfile = new Set(["build", ".fingerprint", "deps"]);
|
||||
await rmExcept(profileDir, keepProfile);
|
||||
|
||||
const keepPkg = new Set(packages.map((p) => p.name));
|
||||
const keepPkg = new Set(packages.flatMap((p) => [p.name, ...p.targets.map((t) => t.replace(/-/g, "_"))]));
|
||||
await rmExcept(path.join(profileDir, "build"), keepPkg, checkTimestamp);
|
||||
await rmExcept(path.join(profileDir, ".fingerprint"), keepPkg, checkTimestamp);
|
||||
|
||||
@@ -75,21 +79,6 @@ async function cleanProfileTarget(profileDir: string, packages: Packages, checkT
|
||||
await rmExcept(path.join(profileDir, "deps"), keepDeps, checkTimestamp);
|
||||
}
|
||||
|
||||
export async function getCargoBins(): Promise<Set<string>> {
|
||||
const bins = new Set<string>();
|
||||
try {
|
||||
const { installs }: { installs: { [key: string]: { bins: Array<string> } } } = JSON.parse(
|
||||
await fs.promises.readFile(path.join(CARGO_HOME, ".crates2.json"), "utf8"),
|
||||
);
|
||||
for (const pkg of Object.values(installs)) {
|
||||
for (const bin of pkg.bins) {
|
||||
bins.add(bin);
|
||||
}
|
||||
}
|
||||
} catch {}
|
||||
return bins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean the cargo bin directory, removing the binaries that existed
|
||||
* when the action started, as they were not created by the build.
|
||||
@@ -97,15 +86,11 @@ export async function getCargoBins(): Promise<Set<string>> {
|
||||
* @param oldBins The binaries that existed when the action started.
|
||||
*/
|
||||
export async function cleanBin(oldBins: Array<string>) {
|
||||
const bins = await getCargoBins();
|
||||
|
||||
for (const bin of oldBins) {
|
||||
bins.delete(bin);
|
||||
}
|
||||
const binsToRemove = new Set<string>(oldBins);
|
||||
|
||||
const dir = await fs.promises.opendir(path.join(CARGO_HOME, "bin"));
|
||||
for await (const dirent of dir) {
|
||||
if (dirent.isFile() && !bins.has(dirent.name)) {
|
||||
if (dirent.isFile() && binsToRemove.has(dirent.name)) {
|
||||
await rm(dir.path, dirent);
|
||||
}
|
||||
}
|
||||
@@ -114,7 +99,7 @@ export async function cleanBin(oldBins: Array<string>) {
|
||||
export async function cleanRegistry(packages: Packages, crates = true) {
|
||||
// remove `.cargo/credentials.toml`
|
||||
try {
|
||||
const credentials = path.join(CARGO_HOME, ".cargo", "credentials.toml");
|
||||
const credentials = path.join(CARGO_HOME, "credentials.toml");
|
||||
core.debug(`deleting "${credentials}"`);
|
||||
await fs.promises.unlink(credentials);
|
||||
} catch {}
|
||||
@@ -258,12 +243,19 @@ const ONE_WEEK = 7 * 24 * 3600 * 1000;
|
||||
/**
|
||||
* Removes all files or directories in `dirName` matching some criteria.
|
||||
*
|
||||
* When the `checkTimestamp` flag is set, this will also remove anything older
|
||||
* than one week.
|
||||
* These two modes are mutually exclusive. When the `checkTimestamp` flag is
|
||||
* set, this will remove anything older than one week and `keepPrefix` is
|
||||
* ignored.
|
||||
*
|
||||
* Otherwise, it will remove everything that does not match any string in the
|
||||
* `keepPrefix` set.
|
||||
* The matching strips and trailing `-$hash` suffix.
|
||||
*
|
||||
* Cargo's newer `build-dir` layout (rust-lang/cargo#17258) nests the hash as
|
||||
* a subdirectory instead of appending it, so entries there are bare package
|
||||
* names with no suffix to strip. Check for an exact match first so those
|
||||
* names (which may themselves contain hyphens) aren't mistaken for a
|
||||
* `<name>-<hash>` entry from the old layout and truncated incorrectly.
|
||||
*/
|
||||
async function rmExcept(dirName: string, keepPrefix: Set<string>, checkTimestamp = false) {
|
||||
const dir = await fs.promises.opendir(dirName);
|
||||
@@ -276,19 +268,26 @@ async function rmExcept(dirName: string, keepPrefix: Set<string>, checkTimestamp
|
||||
if (isOutdated) {
|
||||
await rm(dir.path, dirent);
|
||||
}
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
let name = dirent.name;
|
||||
|
||||
// strip the trailing hash
|
||||
const idx = name.lastIndexOf("-");
|
||||
if (idx !== -1) {
|
||||
name = name.slice(0, idx);
|
||||
}
|
||||
// in Cargo's V1 layout, all packages are suffixed by their hash.
|
||||
// in V2, all package hashes are subdirectories instead.
|
||||
// Check both possible naming standards for packages and accept either.
|
||||
|
||||
// v2 package format
|
||||
if (!keepPrefix.has(name)) {
|
||||
await rm(dir.path, dirent);
|
||||
// now check for v1 package format
|
||||
// strip the trailing hash
|
||||
const idx = name.lastIndexOf("-");
|
||||
if (idx !== -1) {
|
||||
name = name.slice(0, idx);
|
||||
}
|
||||
if (!keepPrefix.has(name)) {
|
||||
await rm(dir.path, dirent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+31
-20
@@ -7,9 +7,8 @@ import os from "os";
|
||||
import path from "path";
|
||||
import * as toml from "smol-toml";
|
||||
|
||||
import { getCargoBins } from "./cleanup";
|
||||
import { CacheProvider, exists, getCmdOutput } from "./utils";
|
||||
import { Workspace } from "./workspace";
|
||||
import { CacheProvider, exists, getCmdOutput } from "./utils.js";
|
||||
import { Workspace } from "./workspace.js";
|
||||
|
||||
const HOME = os.homedir();
|
||||
export const CARGO_HOME = process.env.CARGO_HOME || path.join(HOME, ".cargo");
|
||||
@@ -103,15 +102,9 @@ export class CacheConfig {
|
||||
// resulting environment hash.
|
||||
|
||||
let hasher = crypto.createHash("sha1");
|
||||
const rustVersions = Array.from(await getRustVersions(cmdFormat));
|
||||
// Doesn't matter how they're sorted, just as long as it's deterministic.
|
||||
rustVersions.sort();
|
||||
|
||||
const rustVersions = (self.keyRust = await getRustVersions(cmdFormat));
|
||||
for (const rustVersion of rustVersions) {
|
||||
const { release, host, "commit-hash": commitHash } = rustVersion;
|
||||
const keyRust = `${release} ${host} ${commitHash}`;
|
||||
hasher.update(keyRust);
|
||||
self.keyRust.push(keyRust);
|
||||
hasher.update(rustVersion);
|
||||
}
|
||||
|
||||
// these prefixes should cover most of the compiler / rust / cargo keys
|
||||
@@ -379,14 +372,23 @@ function digest(hasher: crypto.Hash): string {
|
||||
return hasher.digest("hex").substring(0, HASH_LENGTH);
|
||||
}
|
||||
|
||||
interface RustVersion {
|
||||
host: string;
|
||||
release: string;
|
||||
"commit-hash": string;
|
||||
export async function getCargoBins(): Promise<Set<string>> {
|
||||
const bins = new Set<string>();
|
||||
|
||||
try {
|
||||
const dir = await fs.opendir(path.join(CARGO_HOME, "bin"));
|
||||
for await (const dirent of dir) {
|
||||
if (dirent.isFile()) {
|
||||
bins.add(dirent.name);
|
||||
}
|
||||
}
|
||||
} catch {}
|
||||
|
||||
return bins;
|
||||
}
|
||||
|
||||
async function getRustVersions(cmdFormat: string): Promise<Set<RustVersion>> {
|
||||
const versions = new Set<RustVersion>();
|
||||
async function getRustVersions(cmdFormat: string): Promise<Array<string>> {
|
||||
const versions = new Set<string>();
|
||||
|
||||
versions.add(parseRustVersion(await getCmdOutput(cmdFormat, "rustc -vV")));
|
||||
|
||||
@@ -407,16 +409,25 @@ async function getRustVersions(cmdFormat: string): Promise<Set<RustVersion>> {
|
||||
versions.add(parseRustVersion(await getCmdOutput(cmdFormat, `rustup run ${toolchain} rustc -vV`)));
|
||||
}
|
||||
}
|
||||
return versions;
|
||||
const rustVersions = Array.from(versions);
|
||||
// Doesn't matter how they're sorted, just as long as it's deterministic.
|
||||
rustVersions.sort();
|
||||
return rustVersions;
|
||||
}
|
||||
|
||||
function parseRustVersion(stdout: string): RustVersion {
|
||||
interface RustVersion {
|
||||
host: string;
|
||||
release: string;
|
||||
"commit-hash": string;
|
||||
}
|
||||
function parseRustVersion(stdout: string): string {
|
||||
const splits = stdout
|
||||
.split(/[\n\r]+/)
|
||||
.filter(Boolean)
|
||||
.map((s) => s.split(":").map((s) => s.trim()))
|
||||
.filter((s) => s.length === 2);
|
||||
return Object.fromEntries(splits);
|
||||
const { release, host, "commit-hash": commitHash } = Object.fromEntries(splits) as RustVersion;
|
||||
return `${release} ${host} ${commitHash}`;
|
||||
}
|
||||
|
||||
async function globFiles(pattern: string): Promise<string[]> {
|
||||
|
||||
+8
-7
@@ -1,8 +1,8 @@
|
||||
import * as core from "@actions/core";
|
||||
|
||||
import { cleanTargetDir } from "./cleanup";
|
||||
import { CacheConfig } from "./config";
|
||||
import { getCacheProvider, reportError } from "./utils";
|
||||
import { cleanTargetDir } from "./cleanup.js";
|
||||
import { CacheConfig } from "./config.js";
|
||||
import { getCacheProvider, reportError } from "./utils.js";
|
||||
|
||||
process.on("uncaughtException", (e) => {
|
||||
core.error(e.message);
|
||||
@@ -12,7 +12,7 @@ process.on("uncaughtException", (e) => {
|
||||
});
|
||||
|
||||
async function run() {
|
||||
const cacheProvider = getCacheProvider();
|
||||
const cacheProvider = await getCacheProvider();
|
||||
|
||||
if (!cacheProvider.cache.isFeatureAvailable()) {
|
||||
setCacheHitOutput(false);
|
||||
@@ -42,9 +42,10 @@ async function run() {
|
||||
lookupOnly,
|
||||
});
|
||||
if (restoreKey) {
|
||||
const match = restoreKey.localeCompare(key, undefined, {
|
||||
sensitivity: "accent"
|
||||
}) === 0;
|
||||
const match =
|
||||
restoreKey.localeCompare(key, undefined, {
|
||||
sensitivity: "accent",
|
||||
}) === 0;
|
||||
core.info(`${lookupOnly ? "Found" : "Restored from"} cache key "${restoreKey}" full match: ${match}.`);
|
||||
if (!match) {
|
||||
// pre-clean the target directory on cache mismatch
|
||||
|
||||
+4
-4
@@ -1,9 +1,9 @@
|
||||
import * as core from "@actions/core";
|
||||
import * as exec from "@actions/exec";
|
||||
|
||||
import { cleanBin, cleanGit, cleanRegistry, cleanTargetDir } from "./cleanup";
|
||||
import { CacheConfig, isCacheUpToDate } from "./config";
|
||||
import { getCacheProvider, reportError } from "./utils";
|
||||
import { cleanBin, cleanGit, cleanRegistry, cleanTargetDir } from "./cleanup.js";
|
||||
import { CacheConfig, isCacheUpToDate } from "./config.js";
|
||||
import { getCacheProvider, reportError } from "./utils.js";
|
||||
|
||||
process.on("uncaughtException", (e) => {
|
||||
core.error(e.message);
|
||||
@@ -13,7 +13,7 @@ process.on("uncaughtException", (e) => {
|
||||
});
|
||||
|
||||
async function run() {
|
||||
const cacheProvider = getCacheProvider();
|
||||
const cacheProvider = await getCacheProvider();
|
||||
|
||||
const save = core.getInput("save-if").toLowerCase() || "true";
|
||||
|
||||
|
||||
+6
-16
@@ -1,8 +1,5 @@
|
||||
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";
|
||||
|
||||
export function reportError(e: any) {
|
||||
@@ -15,11 +12,7 @@ export function reportError(e: any) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function getCmdOutput(
|
||||
cmdFormat: string,
|
||||
cmd: string,
|
||||
options: exec.ExecOptions = {},
|
||||
): Promise<string> {
|
||||
export async function getCmdOutput(cmdFormat: string, cmd: string, options: exec.ExecOptions = {}): Promise<string> {
|
||||
cmd = cmdFormat.replace("{0}", cmd);
|
||||
let stdout = "";
|
||||
let stderr = "";
|
||||
@@ -47,8 +40,8 @@ export async function getCmdOutput(
|
||||
}
|
||||
|
||||
export interface GhCache {
|
||||
isFeatureAvailable: typeof ghCache.isFeatureAvailable;
|
||||
restoreCache: typeof ghCache.restoreCache;
|
||||
isFeatureAvailable: typeof import("@actions/cache").isFeatureAvailable;
|
||||
restoreCache: typeof import("@actions/cache").restoreCache;
|
||||
saveCache: (paths: string[], key: string) => Promise<string | number>;
|
||||
}
|
||||
|
||||
@@ -57,18 +50,15 @@ export interface CacheProvider {
|
||||
cache: GhCache;
|
||||
}
|
||||
|
||||
export function getCacheProvider(): CacheProvider {
|
||||
export async function getCacheProvider(): Promise<CacheProvider> {
|
||||
const cacheProvider = core.getInput("cache-provider");
|
||||
let cache: GhCache;
|
||||
switch (cacheProvider) {
|
||||
case "github":
|
||||
cache = ghCache;
|
||||
break;
|
||||
case "buildjet":
|
||||
cache = buildjetCache;
|
||||
cache = await import("@actions/cache");
|
||||
break;
|
||||
case "warpbuild":
|
||||
cache = warpbuildCache;
|
||||
cache = await import("@actions/warpbuild-cache");
|
||||
break;
|
||||
default:
|
||||
throw new Error(`The \`cache-provider\` \`${cacheProvider}\` is not valid.`);
|
||||
|
||||
+12
-5
@@ -1,14 +1,21 @@
|
||||
import * as core from "@actions/core";
|
||||
import path from "path";
|
||||
|
||||
import { getCmdOutput } from "./utils";
|
||||
import { getCmdOutput } from "./utils.js";
|
||||
|
||||
const SAVE_TARGETS = new Set(["lib", "proc-macro"]);
|
||||
const SAVE_TARGETS = new Set(["lib", "cdylib", "dylib", "rlib", "staticlib", "proc-macro"]);
|
||||
|
||||
export class Workspace {
|
||||
constructor(public root: string, public target: string) {}
|
||||
constructor(
|
||||
public root: string,
|
||||
public target: string,
|
||||
) {}
|
||||
|
||||
async getPackages(cmdFormat: string, filter: (p: Meta["packages"][0]) => boolean, extraArgs?: string): Promise<Packages> {
|
||||
async getPackages(
|
||||
cmdFormat: string,
|
||||
filter: (p: Meta["packages"][0]) => boolean,
|
||||
extraArgs?: string,
|
||||
): Promise<Packages> {
|
||||
const cmd = "cargo metadata --all-features --format-version 1" + (extraArgs ? ` ${extraArgs}` : "");
|
||||
let packages: Packages = [];
|
||||
try {
|
||||
@@ -16,7 +23,7 @@ export class Workspace {
|
||||
const meta: Meta = JSON.parse(
|
||||
await getCmdOutput(cmdFormat, cmd, {
|
||||
cwd: this.root,
|
||||
env: { ...process.env, "CARGO_ENCODED_RUSTFLAGS": "" },
|
||||
env: { ...process.env, CARGO_ENCODED_RUSTFLAGS: "" },
|
||||
}),
|
||||
);
|
||||
core.debug(`workspace "${this.root}" has ${meta.packages.length} packages`);
|
||||
|
||||
+10
-5
@@ -2,20 +2,25 @@
|
||||
"compilerOptions": {
|
||||
"noEmitOnError": false,
|
||||
"diagnostics": true,
|
||||
"lib": ["esnext"],
|
||||
"lib": ["es2024"],
|
||||
"types": ["node"],
|
||||
|
||||
"target": "es2020",
|
||||
"target": "es2024",
|
||||
|
||||
"resolveJsonModule": true,
|
||||
"moduleResolution": "node",
|
||||
"module": "esnext",
|
||||
"esModuleInterop": true,
|
||||
|
||||
"incremental": true,
|
||||
"tsBuildInfoFile": ".build/tsconfig.build.tsbuildinfo",
|
||||
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noImplicitReturns": true
|
||||
"noImplicitReturns": true,
|
||||
|
||||
"outDir": ".build"
|
||||
},
|
||||
"include": ["src", "rollup.config.ts"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user