Compare commits

...

7 Commits

Author SHA1 Message Date
Tamir Duberstein
5e4a767433
Consider all installed toolchains in cache key (#293) 2025-12-16 12:30:13 +01:00
dependabot[bot]
0aa729bb7a
Bump @types/node from 24.10.1 to 25.0.2 in the dev-major group (#295)
Bumps the dev-major group with 1 update: [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node).


Updates `@types/node` from 24.10.1 to 25.0.2
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-version: 25.0.2
  dependency-type: direct:development
  update-type: version-update:semver-major
  dependency-group: dev-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-16 11:55:53 +01:00
dependabot[bot]
6cda4ba16e
Bump the prd-major group with 3 updates (#294)
Bumps the prd-major group with 3 updates: [@actions/cache](https://github.com/actions/toolkit/tree/HEAD/packages/cache), [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) and [@actions/exec](https://github.com/actions/toolkit/tree/HEAD/packages/exec).


Updates `@actions/cache` from 4.1.0 to 5.0.1
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/cache/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/cache)

Updates `@actions/core` from 1.11.1 to 2.0.1
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/@actions/artifact@2.0.1/packages/core)

Updates `@actions/exec` from 1.1.1 to 2.0.0
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/exec/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/exec)

---
updated-dependencies:
- dependency-name: "@actions/cache"
  dependency-version: 5.0.1
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: prd-major
- dependency-name: "@actions/core"
  dependency-version: 2.0.1
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: prd-major
- dependency-name: "@actions/exec"
  dependency-version: 2.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: prd-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-16 11:55:34 +01:00
dependabot[bot]
e73b99eeb0
Bump the actions group across 1 directory with 5 updates (#296)
Bumps the actions group with 5 updates in the / directory:

| Package | From | To |
| --- | --- | --- |
| [actions/checkout](https://github.com/actions/checkout) | `6.0.0` | `6.0.1` |
| [actions/setup-node](https://github.com/actions/setup-node) | `6.0.0` | `6.1.0` |
| [actions/upload-artifact](https://github.com/actions/upload-artifact) | `5.0.0` | `6.0.0` |
| [taiki-e/install-action](https://github.com/taiki-e/install-action) | `2.62.60` | `2.63.3` |
| [cachix/install-nix-action](https://github.com/cachix/install-nix-action) | `31.8.4` | `31.9.0` |



Updates `actions/checkout` from 6.0.0 to 6.0.1
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](1af3b93b68...8e8c483db8)

Updates `actions/setup-node` from 6.0.0 to 6.1.0
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](2028fbc5c2...395ad32622)

Updates `actions/upload-artifact` from 5.0.0 to 6.0.0
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](330a01c490...b7c566a772)

Updates `taiki-e/install-action` from 2.62.60 to 2.63.3
- [Release notes](https://github.com/taiki-e/install-action/releases)
- [Changelog](https://github.com/taiki-e/install-action/blob/main/CHANGELOG.md)
- [Commits](3575e53270...d850aa8169)

Updates `cachix/install-nix-action` from 31.8.4 to 31.9.0
- [Release notes](https://github.com/cachix/install-nix-action/releases)
- [Changelog](https://github.com/cachix/install-nix-action/blob/master/RELEASE.md)
- [Commits](0b0e072294...4e002c8ec8)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: 6.0.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: actions
- dependency-name: actions/setup-node
  dependency-version: 6.1.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: actions
- dependency-name: actions/upload-artifact
  dependency-version: 6.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
- dependency-name: taiki-e/install-action
  dependency-version: 2.63.3
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: actions
- dependency-name: cachix/install-nix-action
  dependency-version: 31.9.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: actions
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-16 11:54:57 +01:00
github-actions[bot]
42c55942cf
Merge pull request #291 from Swatinem/dependabot/github_actions/actions-d37c78095a
Bump taiki-e/install-action from 2.62.57 to 2.62.60 in the actions group
2025-12-02 01:11:03 +00:00
dependabot[bot]
73cfdf196a
Bump taiki-e/install-action from 2.62.57 to 2.62.60 in the actions group
Bumps the actions group with 1 update: [taiki-e/install-action](https://github.com/taiki-e/install-action).


Updates `taiki-e/install-action` from 2.62.57 to 2.62.60
- [Release notes](https://github.com/taiki-e/install-action/releases)
- [Changelog](https://github.com/taiki-e/install-action/blob/main/CHANGELOG.md)
- [Commits](763e3324d4...3575e53270)

---
updated-dependencies:
- dependency-name: taiki-e/install-action
  dependency-version: 2.62.60
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-12-02 01:08:31 +00:00
marc0246
151eeee51b
Add support for running rust-cache commands from within a Nix shell (#290) 2025-12-01 19:56:12 +01:00
23 changed files with 463 additions and 159 deletions

View File

@ -19,7 +19,7 @@ jobs:
CARGO_TERM_COLOR: always CARGO_TERM_COLOR: always
steps: steps:
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with: with:
persist-credentials: false persist-credentials: false

View File

@ -18,12 +18,12 @@ jobs:
if: github.repository == 'Swatinem/rust-cache' if: github.repository == 'Swatinem/rust-cache'
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with: with:
persist-credentials: false persist-credentials: false
- name: Setup Node.js 20.x - name: Setup Node.js 20.x
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0
with: with:
node-version: 20.x node-version: 20.x
cache: npm cache: npm
@ -43,7 +43,7 @@ jobs:
fi fi
id: diff id: diff
- uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 - uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
if: ${{ failure() && steps.diff.conclusion == 'failure' }} if: ${{ failure() && steps.diff.conclusion == 'failure' }}
with: with:
name: dist name: dist

View File

@ -19,13 +19,13 @@ jobs:
CARGO_TERM_COLOR: always CARGO_TERM_COLOR: always
steps: steps:
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with: with:
persist-credentials: false persist-credentials: false
- run: rustup toolchain install stable --profile minimal --component llvm-tools-preview --no-self-update - run: rustup toolchain install stable --profile minimal --component llvm-tools-preview --no-self-update
- uses: taiki-e/install-action@763e3324d4fd026c9bd284c504378585777a87d5 # v2.62.57 - uses: taiki-e/install-action@d850aa816998e5cf15f67a78c7b933f2a5033f8a # v2.63.3
with: with:
tool: cargo-llvm-cov tool: cargo-llvm-cov

View File

@ -18,7 +18,7 @@ jobs:
uses: dependabot/fetch-metadata@08eff52bf64351f401fb50d4972fa95b9f2c2d1b # v2.4.0 uses: dependabot/fetch-metadata@08eff52bf64351f401fb50d4972fa95b9f2c2d1b # v2.4.0
with: with:
github-token: "${{ secrets.GITHUB_TOKEN }}" github-token: "${{ secrets.GITHUB_TOKEN }}"
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with: with:
fetch-depth: 2 fetch-depth: 2
persist-credentials: false persist-credentials: false
@ -37,7 +37,7 @@ jobs:
fi fi
- name: Setup node if necessary - name: Setup node if necessary
if: steps.npm.outputs.changed != '' if: steps.npm.outputs.changed != ''
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0
with: with:
node-version: 20.x node-version: 20.x
cache: npm cache: npm

View File

@ -20,7 +20,7 @@ jobs:
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: git CARGO_REGISTRIES_CRATES_IO_PROTOCOL: git
steps: steps:
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with: with:
persist-credentials: false persist-credentials: false

View File

@ -19,7 +19,7 @@ jobs:
CARGO_TERM_COLOR: always CARGO_TERM_COLOR: always
steps: steps:
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with: with:
persist-credentials: false persist-credentials: false

View File

@ -20,7 +20,7 @@ jobs:
steps: steps:
- name: checkout - name: checkout
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with: with:
persist-credentials: false persist-credentials: false
@ -54,7 +54,7 @@ jobs:
steps: steps:
- name: checkout - name: checkout
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with: with:
persist-credentials: false persist-credentials: false

33
.github/workflows/nix.yml vendored Normal file
View File

@ -0,0 +1,33 @@
name: nix
on: [push, pull_request]
permissions: {}
jobs:
nix:
if: github.repository == 'Swatinem/rust-cache'
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
name: Test Nix on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
persist-credentials: false
- uses: cachix/install-nix-action@4e002c8ec80594ecd40e759629461e26c8abed15 # v31.9.0
- uses: ./
with:
workspaces: tests
cmd-format: nix develop ./tests -c {0}
- run: |
nix develop -c cargo check
nix develop -c cargo test
working-directory: tests

View File

@ -19,7 +19,7 @@ jobs:
CARGO_TERM_COLOR: always CARGO_TERM_COLOR: always
steps: steps:
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with: with:
persist-credentials: false persist-credentials: false

View File

@ -19,7 +19,7 @@ jobs:
CARGO_TERM_COLOR: always CARGO_TERM_COLOR: always
steps: steps:
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with: with:
persist-credentials: false persist-credentials: false

View File

@ -19,7 +19,7 @@ jobs:
CARGO_TERM_COLOR: always CARGO_TERM_COLOR: always
steps: steps:
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with: with:
persist-credentials: false persist-credentials: false

View File

@ -16,7 +16,7 @@ jobs:
security-events: write # for uploading results to the Security tab security-events: write # for uploading results to the Security tab
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with: with:
persist-credentials: false persist-credentials: false

View File

@ -99,6 +99,16 @@ sensible defaults.
# Determines whether to cache the ~/.cargo/bin directory. # Determines whether to cache the ~/.cargo/bin directory.
# default: "true" # default: "true"
cache-bin: "" cache-bin: ""
# A format string used to format commands to be run, i.e. `rustc` and `cargo`.
# Must contain exactly one occurance of `{0}`, which is the formatting fragment
# that will be replaced with the `rustc` or `cargo` command. This is necessary
# when using Nix or other setup that requires running these commands within a
# specific shell, otherwise the system `rustc` and `cargo` will be run.
# default: "{0}"
cmd-format: ""
# To run within a Nix shell (using the default dev shell of a flake in the repo root):
cmd-format: nix develop -c {0}
``` ```
Further examples are available in the [.github/workflows](./.github/workflows/) directory. Further examples are available in the [.github/workflows](./.github/workflows/) directory.
@ -133,7 +143,8 @@ 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) - 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, - the rustc release / host / hash (for all installed toolchains when
available),
- the following values, if `add-rust-environment-hash-key` is `"true"`: - the following values, if `add-rust-environment-hash-key` is `"true"`:
- the value of some compiler-specific environment variables (eg. RUSTFLAGS, etc), and - the value of some compiler-specific environment variables (eg. RUSTFLAGS, etc), and
- a hash of all `Cargo.lock` / `Cargo.toml` files found anywhere in the repository (if present). - a hash of all `Cargo.lock` / `Cargo.toml` files found anywhere in the repository (if present).

View File

@ -60,6 +60,10 @@ inputs:
description: "Check if a cache entry exists without downloading the cache" description: "Check if a cache entry exists without downloading the cache"
required: false required: false
default: "false" default: "false"
cmd-format:
description: "A format string used to format commands to be run, i.e. `rustc` and `cargo`."
required: false
default: "{0}"
outputs: outputs:
cache-hit: cache-hit:
description: "A boolean value that indicates an exact match was found." description: "A boolean value that indicates an exact match was found."

103
dist/restore/index.js vendored
View File

@ -149504,6 +149504,8 @@ var external_crypto_default = /*#__PURE__*/__nccwpck_require__.n(external_crypto
// EXTERNAL MODULE: external "fs/promises" // EXTERNAL MODULE: external "fs/promises"
var promises_ = __nccwpck_require__(91943); var promises_ = __nccwpck_require__(91943);
var promises_default = /*#__PURE__*/__nccwpck_require__.n(promises_); var promises_default = /*#__PURE__*/__nccwpck_require__.n(promises_);
;// CONCATENATED MODULE: external "stream/promises"
const external_stream_promises_namespaceObject = require("stream/promises");
// EXTERNAL MODULE: external "os" // EXTERNAL MODULE: external "os"
var external_os_ = __nccwpck_require__(70857); var external_os_ = __nccwpck_require__(70857);
var external_os_default = /*#__PURE__*/__nccwpck_require__.n(external_os_); var external_os_default = /*#__PURE__*/__nccwpck_require__.n(external_os_);
@ -150675,11 +150677,12 @@ function reportError(e) {
lib_core.error(`${e.stack}`); lib_core.error(`${e.stack}`);
} }
} }
async function getCmdOutput(cmd, args = [], options = {}) { async function getCmdOutput(cmdFormat, cmd, options = {}) {
cmd = cmdFormat.replace("{0}", cmd);
let stdout = ""; let stdout = "";
let stderr = ""; let stderr = "";
try { try {
await exec.exec(cmd, args, { await exec.exec(cmd, [], {
silent: true, silent: true,
listeners: { listeners: {
stdout(data) { stdout(data) {
@ -150694,7 +150697,7 @@ async function getCmdOutput(cmd, args = [], options = {}) {
} }
catch (e) { catch (e) {
e.commandFailed = { e.commandFailed = {
command: `${cmd} ${args.join(" ")}`, command: cmd,
stderr, stderr,
}; };
throw e; throw e;
@ -150742,11 +150745,12 @@ class Workspace {
this.root = root; this.root = root;
this.target = target; this.target = target;
} }
async getPackages(filter, ...extraArgs) { async getPackages(cmdFormat, filter, extraArgs) {
const cmd = "cargo metadata --all-features --format-version 1" + (extraArgs ? ` ${extraArgs}` : "");
let packages = []; let packages = [];
try { try {
lib_core.debug(`collecting metadata for "${this.root}"`); lib_core.debug(`collecting metadata for "${this.root}"`);
const meta = JSON.parse(await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1", ...extraArgs], { const meta = JSON.parse(await getCmdOutput(cmdFormat, cmd, {
cwd: this.root, cwd: this.root,
env: { ...process.env, "CARGO_ENCODED_RUSTFLAGS": "" }, env: { ...process.env, "CARGO_ENCODED_RUSTFLAGS": "" },
})); }));
@ -150761,11 +150765,11 @@ class Workspace {
} }
return packages; return packages;
} }
async getPackagesOutsideWorkspaceRoot() { async getPackagesOutsideWorkspaceRoot(cmdFormat) {
return await this.getPackages((pkg) => !pkg.manifest_path.startsWith(this.root)); return await this.getPackages(cmdFormat, (pkg) => !pkg.manifest_path.startsWith(this.root));
} }
async getWorkspaceMembers() { async getWorkspaceMembers(cmdFormat) {
return await this.getPackages((_) => true, "--no-deps"); return await this.getPackages(cmdFormat, (_) => true, "--no-deps");
} }
} }
@ -150781,12 +150785,15 @@ class Workspace {
const HOME = external_os_default().homedir(); const HOME = external_os_default().homedir();
const config_CARGO_HOME = process.env.CARGO_HOME || external_path_default().join(HOME, ".cargo"); const config_CARGO_HOME = process.env.CARGO_HOME || external_path_default().join(HOME, ".cargo");
const STATE_CONFIG = "RUST_CACHE_CONFIG"; const STATE_CONFIG = "RUST_CACHE_CONFIG";
const HASH_LENGTH = 8; const HASH_LENGTH = 8;
class CacheConfig { class CacheConfig {
constructor() { constructor() {
/** A format string for running commands */
this.cmdFormat = "";
/** All the paths we want to cache */ /** All the paths we want to cache */
this.cachePaths = []; this.cachePaths = [];
/** The primary cache key */ /** The primary cache key */
@ -150802,7 +150809,7 @@ class CacheConfig {
/** The prefix portion of the cache key */ /** The prefix portion of the cache key */
this.keyPrefix = ""; this.keyPrefix = "";
/** The rust version considered for the cache key */ /** The rust version considered for the cache key */
this.keyRust = ""; this.keyRust = [];
/** The environment variables considered for the cache key */ /** The environment variables considered for the cache key */
this.keyEnvs = []; this.keyEnvs = [];
/** The files considered for the cache key */ /** The files considered for the cache key */
@ -150815,6 +150822,17 @@ class CacheConfig {
*/ */
static async new() { static async new() {
const self = new CacheConfig(); const self = new CacheConfig();
let cmdFormat = lib_core.getInput("cmd-format");
if (cmdFormat) {
const placeholderMatches = cmdFormat.match(/\{0\}/g);
if (!placeholderMatches || placeholderMatches.length !== 1) {
cmdFormat = "{0}";
}
}
else {
cmdFormat = "{0}";
}
self.cmdFormat = cmdFormat;
// Construct key prefix: // Construct key prefix:
// This uses either the `shared-key` input, // This uses either the `shared-key` input,
// or the `key` input combined with the `job` key. // or the `key` input combined with the `job` key.
@ -150845,12 +150863,15 @@ class CacheConfig {
// The env vars are sorted, matched by prefix and hashed into the // The env vars are sorted, matched by prefix and hashed into the
// resulting environment hash. // resulting environment hash.
let hasher = external_crypto_default().createHash("sha1"); let hasher = external_crypto_default().createHash("sha1");
const rustVersion = await getRustVersion(); const rustVersions = Array.from(await getRustVersions(cmdFormat));
let keyRust = `${rustVersion.release} ${rustVersion.host}`; // Doesn't matter how they're sorted, just as long as it's deterministic.
hasher.update(keyRust); rustVersions.sort();
hasher.update(rustVersion["commit-hash"]); for (const rustVersion of rustVersions) {
keyRust += ` (${rustVersion["commit-hash"]})`; const { release, host, "commit-hash": commitHash } = rustVersion;
self.keyRust = keyRust; const keyRust = `${release} ${host} ${commitHash}`;
hasher.update(keyRust);
self.keyRust.push(keyRust);
}
// these prefixes should cover most of the compiler / rust / cargo keys // these prefixes should cover most of the compiler / rust / cargo keys
const envPrefixes = ["CARGO", "CC", "CFLAGS", "CXX", "CMAKE", "RUST"]; const envPrefixes = ["CARGO", "CC", "CFLAGS", "CXX", "CMAKE", "RUST"];
envPrefixes.push(...lib_core.getInput("env-vars").split(/\s+/).filter(Boolean)); envPrefixes.push(...lib_core.getInput("env-vars").split(/\s+/).filter(Boolean));
@ -150895,7 +150916,7 @@ class CacheConfig {
for (const workspace of workspaces) { for (const workspace of workspaces) {
const root = workspace.root; const root = workspace.root;
keyFiles.push(...(await globFiles(`${root}/**/.cargo/config.toml\n${root}/**/rust-toolchain\n${root}/**/rust-toolchain.toml`))); keyFiles.push(...(await globFiles(`${root}/**/.cargo/config.toml\n${root}/**/rust-toolchain\n${root}/**/rust-toolchain.toml`)));
const workspaceMembers = await workspace.getWorkspaceMembers(); const workspaceMembers = await workspace.getWorkspaceMembers(cmdFormat);
const cargo_manifests = sort_and_uniq(workspaceMembers.map((member) => external_path_default().join(member.path, "Cargo.toml"))); const cargo_manifests = sort_and_uniq(workspaceMembers.map((member) => external_path_default().join(member.path, "Cargo.toml")));
for (const cargo_manifest of cargo_manifests) { for (const cargo_manifest of cargo_manifests) {
try { try {
@ -150965,9 +150986,7 @@ class CacheConfig {
} }
keyFiles = sort_and_uniq(keyFiles); keyFiles = sort_and_uniq(keyFiles);
for (const file of keyFiles) { for (const file of keyFiles) {
for await (const chunk of external_fs_default().createReadStream(file)) { await (0,external_stream_promises_namespaceObject.pipeline)((0,external_fs_.createReadStream)(file), hasher);
hasher.update(chunk);
}
} }
keyFiles.push(...parsedKeyFiles); keyFiles.push(...parsedKeyFiles);
self.keyFiles = sort_and_uniq(keyFiles); self.keyFiles = sort_and_uniq(keyFiles);
@ -151036,7 +151055,10 @@ class CacheConfig {
lib_core.info(`.. Prefix:`); lib_core.info(`.. Prefix:`);
lib_core.info(` - ${this.keyPrefix}`); lib_core.info(` - ${this.keyPrefix}`);
lib_core.info(`.. Environment considered:`); lib_core.info(`.. Environment considered:`);
lib_core.info(` - Rust Version: ${this.keyRust}`); lib_core.info(` - Rust Versions:`);
for (const rust of this.keyRust) {
lib_core.info(` - ${rust}`);
}
for (const env of this.keyEnvs) { for (const env of this.keyEnvs) {
lib_core.info(` - ${env}`); lib_core.info(` - ${env}`);
} }
@ -151071,9 +151093,31 @@ function isCacheUpToDate() {
function digest(hasher) { function digest(hasher) {
return hasher.digest("hex").substring(0, HASH_LENGTH); return hasher.digest("hex").substring(0, HASH_LENGTH);
} }
async function getRustVersion() { async function getRustVersions(cmdFormat) {
const stdout = await getCmdOutput("rustc", ["-vV"]); const versions = new Set();
let splits = stdout versions.add(parseRustVersion(await getCmdOutput(cmdFormat, "rustc -vV")));
const stdout = await (async () => {
try {
return await getCmdOutput(cmdFormat, "rustup toolchain list --quiet");
}
catch (e) {
lib_core.warning(`Error running rustup toolchain list, falling back to default toolchain only: ${e}`);
return undefined;
}
})();
if (stdout !== undefined) {
for (const toolchain of stdout.split(/[\n\r]+/)) {
const trimmed = toolchain.trim();
if (!trimmed) {
continue;
}
versions.add(parseRustVersion(await getCmdOutput(cmdFormat, `rustup run ${toolchain} rustc -vV`)));
}
}
return versions;
}
function parseRustVersion(stdout) {
const splits = stdout
.split(/[\n\r]+/) .split(/[\n\r]+/)
.filter(Boolean) .filter(Boolean)
.map((s) => s.split(":").map((s) => s.trim())) .map((s) => s.split(":").map((s) => s.trim()))
@ -151084,10 +151128,17 @@ async function globFiles(pattern) {
const globber = await glob.create(pattern, { const globber = await glob.create(pattern, {
followSymbolicLinks: false, followSymbolicLinks: false,
}); });
// fs.statSync resolve the symbolic link and returns stat for the // fs.stat resolve the symbolic link and returns stat for the
// file it pointed to, so isFile would make sure the resolved // file it pointed to, so isFile would make sure the resolved
// file is actually a regular file. // file is actually a regular file.
return (await globber.glob()).filter((file) => external_fs_default().statSync(file).isFile()); const files = [];
for (const file of await globber.glob()) {
const stats = await promises_default().stat(file);
if (stats.isFile()) {
files.push(file);
}
}
return files;
} }
function sort_and_uniq(a) { function sort_and_uniq(a) {
return a return a

107
dist/save/index.js vendored
View File

@ -149506,6 +149506,8 @@ var external_crypto_default = /*#__PURE__*/__nccwpck_require__.n(external_crypto
// EXTERNAL MODULE: external "fs/promises" // EXTERNAL MODULE: external "fs/promises"
var promises_ = __nccwpck_require__(91943); var promises_ = __nccwpck_require__(91943);
var promises_default = /*#__PURE__*/__nccwpck_require__.n(promises_); var promises_default = /*#__PURE__*/__nccwpck_require__.n(promises_);
;// CONCATENATED MODULE: external "stream/promises"
const external_stream_promises_namespaceObject = require("stream/promises");
// EXTERNAL MODULE: external "os" // EXTERNAL MODULE: external "os"
var external_os_ = __nccwpck_require__(70857); var external_os_ = __nccwpck_require__(70857);
var external_os_default = /*#__PURE__*/__nccwpck_require__.n(external_os_); var external_os_default = /*#__PURE__*/__nccwpck_require__.n(external_os_);
@ -150675,11 +150677,12 @@ function reportError(e) {
core.error(`${e.stack}`); core.error(`${e.stack}`);
} }
} }
async function getCmdOutput(cmd, args = [], options = {}) { async function getCmdOutput(cmdFormat, cmd, options = {}) {
cmd = cmdFormat.replace("{0}", cmd);
let stdout = ""; let stdout = "";
let stderr = ""; let stderr = "";
try { try {
await exec.exec(cmd, args, { await exec.exec(cmd, [], {
silent: true, silent: true,
listeners: { listeners: {
stdout(data) { stdout(data) {
@ -150694,7 +150697,7 @@ async function getCmdOutput(cmd, args = [], options = {}) {
} }
catch (e) { catch (e) {
e.commandFailed = { e.commandFailed = {
command: `${cmd} ${args.join(" ")}`, command: cmd,
stderr, stderr,
}; };
throw e; throw e;
@ -150742,11 +150745,12 @@ class Workspace {
this.root = root; this.root = root;
this.target = target; this.target = target;
} }
async getPackages(filter, ...extraArgs) { async getPackages(cmdFormat, filter, extraArgs) {
const cmd = "cargo metadata --all-features --format-version 1" + (extraArgs ? ` ${extraArgs}` : "");
let packages = []; let packages = [];
try { try {
core.debug(`collecting metadata for "${this.root}"`); core.debug(`collecting metadata for "${this.root}"`);
const meta = JSON.parse(await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1", ...extraArgs], { const meta = JSON.parse(await getCmdOutput(cmdFormat, cmd, {
cwd: this.root, cwd: this.root,
env: { ...process.env, "CARGO_ENCODED_RUSTFLAGS": "" }, env: { ...process.env, "CARGO_ENCODED_RUSTFLAGS": "" },
})); }));
@ -150761,11 +150765,11 @@ class Workspace {
} }
return packages; return packages;
} }
async getPackagesOutsideWorkspaceRoot() { async getPackagesOutsideWorkspaceRoot(cmdFormat) {
return await this.getPackages((pkg) => !pkg.manifest_path.startsWith(this.root)); return await this.getPackages(cmdFormat, (pkg) => !pkg.manifest_path.startsWith(this.root));
} }
async getWorkspaceMembers() { async getWorkspaceMembers(cmdFormat) {
return await this.getPackages((_) => true, "--no-deps"); return await this.getPackages(cmdFormat, (_) => true, "--no-deps");
} }
} }
@ -150781,12 +150785,15 @@ class Workspace {
const HOME = external_os_default().homedir(); const HOME = external_os_default().homedir();
const CARGO_HOME = process.env.CARGO_HOME || external_path_default().join(HOME, ".cargo"); const CARGO_HOME = process.env.CARGO_HOME || external_path_default().join(HOME, ".cargo");
const STATE_CONFIG = "RUST_CACHE_CONFIG"; const STATE_CONFIG = "RUST_CACHE_CONFIG";
const HASH_LENGTH = 8; const HASH_LENGTH = 8;
class CacheConfig { class CacheConfig {
constructor() { constructor() {
/** A format string for running commands */
this.cmdFormat = "";
/** All the paths we want to cache */ /** All the paths we want to cache */
this.cachePaths = []; this.cachePaths = [];
/** The primary cache key */ /** The primary cache key */
@ -150802,7 +150809,7 @@ class CacheConfig {
/** The prefix portion of the cache key */ /** The prefix portion of the cache key */
this.keyPrefix = ""; this.keyPrefix = "";
/** The rust version considered for the cache key */ /** The rust version considered for the cache key */
this.keyRust = ""; this.keyRust = [];
/** The environment variables considered for the cache key */ /** The environment variables considered for the cache key */
this.keyEnvs = []; this.keyEnvs = [];
/** The files considered for the cache key */ /** The files considered for the cache key */
@ -150815,6 +150822,17 @@ class CacheConfig {
*/ */
static async new() { static async new() {
const self = new CacheConfig(); const self = new CacheConfig();
let cmdFormat = core.getInput("cmd-format");
if (cmdFormat) {
const placeholderMatches = cmdFormat.match(/\{0\}/g);
if (!placeholderMatches || placeholderMatches.length !== 1) {
cmdFormat = "{0}";
}
}
else {
cmdFormat = "{0}";
}
self.cmdFormat = cmdFormat;
// Construct key prefix: // Construct key prefix:
// This uses either the `shared-key` input, // This uses either the `shared-key` input,
// or the `key` input combined with the `job` key. // or the `key` input combined with the `job` key.
@ -150845,12 +150863,15 @@ class CacheConfig {
// The env vars are sorted, matched by prefix and hashed into the // The env vars are sorted, matched by prefix and hashed into the
// resulting environment hash. // resulting environment hash.
let hasher = external_crypto_default().createHash("sha1"); let hasher = external_crypto_default().createHash("sha1");
const rustVersion = await getRustVersion(); const rustVersions = Array.from(await getRustVersions(cmdFormat));
let keyRust = `${rustVersion.release} ${rustVersion.host}`; // Doesn't matter how they're sorted, just as long as it's deterministic.
hasher.update(keyRust); rustVersions.sort();
hasher.update(rustVersion["commit-hash"]); for (const rustVersion of rustVersions) {
keyRust += ` (${rustVersion["commit-hash"]})`; const { release, host, "commit-hash": commitHash } = rustVersion;
self.keyRust = keyRust; const keyRust = `${release} ${host} ${commitHash}`;
hasher.update(keyRust);
self.keyRust.push(keyRust);
}
// these prefixes should cover most of the compiler / rust / cargo keys // these prefixes should cover most of the compiler / rust / cargo keys
const envPrefixes = ["CARGO", "CC", "CFLAGS", "CXX", "CMAKE", "RUST"]; const envPrefixes = ["CARGO", "CC", "CFLAGS", "CXX", "CMAKE", "RUST"];
envPrefixes.push(...core.getInput("env-vars").split(/\s+/).filter(Boolean)); envPrefixes.push(...core.getInput("env-vars").split(/\s+/).filter(Boolean));
@ -150895,7 +150916,7 @@ class CacheConfig {
for (const workspace of workspaces) { for (const workspace of workspaces) {
const root = workspace.root; const root = workspace.root;
keyFiles.push(...(await globFiles(`${root}/**/.cargo/config.toml\n${root}/**/rust-toolchain\n${root}/**/rust-toolchain.toml`))); keyFiles.push(...(await globFiles(`${root}/**/.cargo/config.toml\n${root}/**/rust-toolchain\n${root}/**/rust-toolchain.toml`)));
const workspaceMembers = await workspace.getWorkspaceMembers(); const workspaceMembers = await workspace.getWorkspaceMembers(cmdFormat);
const cargo_manifests = sort_and_uniq(workspaceMembers.map((member) => external_path_default().join(member.path, "Cargo.toml"))); const cargo_manifests = sort_and_uniq(workspaceMembers.map((member) => external_path_default().join(member.path, "Cargo.toml")));
for (const cargo_manifest of cargo_manifests) { for (const cargo_manifest of cargo_manifests) {
try { try {
@ -150965,9 +150986,7 @@ class CacheConfig {
} }
keyFiles = sort_and_uniq(keyFiles); keyFiles = sort_and_uniq(keyFiles);
for (const file of keyFiles) { for (const file of keyFiles) {
for await (const chunk of external_fs_default().createReadStream(file)) { await (0,external_stream_promises_namespaceObject.pipeline)((0,external_fs_.createReadStream)(file), hasher);
hasher.update(chunk);
}
} }
keyFiles.push(...parsedKeyFiles); keyFiles.push(...parsedKeyFiles);
self.keyFiles = sort_and_uniq(keyFiles); self.keyFiles = sort_and_uniq(keyFiles);
@ -151036,7 +151055,10 @@ class CacheConfig {
core.info(`.. Prefix:`); core.info(`.. Prefix:`);
core.info(` - ${this.keyPrefix}`); core.info(` - ${this.keyPrefix}`);
core.info(`.. Environment considered:`); core.info(`.. Environment considered:`);
core.info(` - Rust Version: ${this.keyRust}`); core.info(` - Rust Versions:`);
for (const rust of this.keyRust) {
core.info(` - ${rust}`);
}
for (const env of this.keyEnvs) { for (const env of this.keyEnvs) {
core.info(` - ${env}`); core.info(` - ${env}`);
} }
@ -151071,9 +151093,31 @@ function isCacheUpToDate() {
function digest(hasher) { function digest(hasher) {
return hasher.digest("hex").substring(0, HASH_LENGTH); return hasher.digest("hex").substring(0, HASH_LENGTH);
} }
async function getRustVersion() { async function getRustVersions(cmdFormat) {
const stdout = await getCmdOutput("rustc", ["-vV"]); const versions = new Set();
let splits = stdout versions.add(parseRustVersion(await getCmdOutput(cmdFormat, "rustc -vV")));
const stdout = await (async () => {
try {
return await getCmdOutput(cmdFormat, "rustup toolchain list --quiet");
}
catch (e) {
core.warning(`Error running rustup toolchain list, falling back to default toolchain only: ${e}`);
return undefined;
}
})();
if (stdout !== undefined) {
for (const toolchain of stdout.split(/[\n\r]+/)) {
const trimmed = toolchain.trim();
if (!trimmed) {
continue;
}
versions.add(parseRustVersion(await getCmdOutput(cmdFormat, `rustup run ${toolchain} rustc -vV`)));
}
}
return versions;
}
function parseRustVersion(stdout) {
const splits = stdout
.split(/[\n\r]+/) .split(/[\n\r]+/)
.filter(Boolean) .filter(Boolean)
.map((s) => s.split(":").map((s) => s.trim())) .map((s) => s.split(":").map((s) => s.trim()))
@ -151084,10 +151128,17 @@ async function globFiles(pattern) {
const globber = await glob.create(pattern, { const globber = await glob.create(pattern, {
followSymbolicLinks: false, followSymbolicLinks: false,
}); });
// fs.statSync resolve the symbolic link and returns stat for the // fs.stat resolve the symbolic link and returns stat for the
// file it pointed to, so isFile would make sure the resolved // file it pointed to, so isFile would make sure the resolved
// file is actually a regular file. // file is actually a regular file.
return (await globber.glob()).filter((file) => external_fs_default().statSync(file).isFile()); const files = [];
for (const file of await globber.glob()) {
const stats = await promises_default().stat(file);
if (stats.isFile()) {
files.push(file);
}
}
return files;
} }
function sort_and_uniq(a) { function sort_and_uniq(a) {
return a return a
@ -151428,9 +151479,9 @@ async function run() {
const workspaceCrates = core.getInput("cache-workspace-crates").toLowerCase() || "false"; 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(config.cmdFormat);
if (workspaceCrates === "true") { if (workspaceCrates === "true") {
const wsMembers = await workspace.getWorkspaceMembers(); const wsMembers = await workspace.getWorkspaceMembers(config.cmdFormat);
packages.push(...wsMembers); packages.push(...wsMembers);
} }
allPackages.push(...packages); allPackages.push(...packages);

174
package-lock.json generated
View File

@ -10,16 +10,16 @@
"license": "LGPL-3.0", "license": "LGPL-3.0",
"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/cache": "^4.1.0", "@actions/cache": "^5.0.1",
"@actions/core": "^1.11.1", "@actions/core": "^2.0.1",
"@actions/exec": "^1.1.1", "@actions/exec": "^2.0.0",
"@actions/glob": "^0.5.0", "@actions/glob": "^0.5.0",
"@actions/io": "^2.0.0", "@actions/io": "^2.0.0",
"@actions/warpbuild-cache": "npm:github-actions.warp-cache@1.4.7", "@actions/warpbuild-cache": "npm:github-actions.warp-cache@1.4.7",
"smol-toml": "^1.5.2" "smol-toml": "^1.5.2"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^24.10.1", "@types/node": "^25.0.2",
"@vercel/ncc": "^0.38.4", "@vercel/ncc": "^0.38.4",
"linefix": "^0.1.1", "linefix": "^0.1.1",
"typescript": "5.9.3" "typescript": "5.9.3"
@ -43,6 +43,25 @@
"uuid": "^3.3.3" "uuid": "^3.3.3"
} }
}, },
"node_modules/@actions/buildjet-cache/node_modules/@actions/core": {
"version": "1.11.1",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.11.1.tgz",
"integrity": "sha512-hXJCSrkwfA46Vd9Z3q4cpEpHB1rL5NG04+/rbqW9d3+CSvtB1tYe8UTpAlixa1vj0m/ULglfEK2UKxMGxCxv5A==",
"license": "MIT",
"dependencies": {
"@actions/exec": "^1.1.1",
"@actions/http-client": "^2.0.1"
}
},
"node_modules/@actions/buildjet-cache/node_modules/@actions/exec": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.1.1.tgz",
"integrity": "sha512-+sCcHHbVdk93a0XT19ECtO/gIXoxvdsgQLzb2fE2/5sIZmWQuluYyjPQtrtTHdU1YzTZ7bAPN4sITq2xi1679w==",
"license": "MIT",
"dependencies": {
"@actions/io": "^1.0.1"
}
},
"node_modules/@actions/buildjet-cache/node_modules/@actions/glob": { "node_modules/@actions/buildjet-cache/node_modules/@actions/glob": {
"version": "0.1.2", "version": "0.1.2",
"resolved": "https://registry.npmjs.org/@actions/glob/-/glob-0.1.2.tgz", "resolved": "https://registry.npmjs.org/@actions/glob/-/glob-0.1.2.tgz",
@ -59,61 +78,62 @@
"license": "MIT" "license": "MIT"
}, },
"node_modules/@actions/cache": { "node_modules/@actions/cache": {
"version": "4.1.0", "version": "5.0.1",
"resolved": "https://registry.npmjs.org/@actions/cache/-/cache-4.1.0.tgz", "resolved": "https://registry.npmjs.org/@actions/cache/-/cache-5.0.1.tgz",
"integrity": "sha512-z3Opg+P4Y7baq+g1dODXgdtsvPLSewr3ZKpp3U0HQR1A/vWCoJFS52XSezjdngo4SIOdR5oHtyK3a3Arar+X9A==", "integrity": "sha512-c+oH047Z2zmXLhjMZfEKjxZfv6Ou7T0sn5fhz6yupICXm5OOR47oZn5zxNO8MP7ttkxv5TOg3WsMrffri5Xhfw==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^1.11.1", "@actions/core": "^2.0.0",
"@actions/exec": "^1.0.1", "@actions/exec": "^2.0.0",
"@actions/glob": "^0.1.0", "@actions/glob": "^0.5.0",
"@actions/http-client": "^2.1.1", "@actions/http-client": "^3.0.0",
"@actions/io": "^1.0.1", "@actions/io": "^2.0.0",
"@azure/abort-controller": "^1.1.0", "@azure/abort-controller": "^1.1.0",
"@azure/ms-rest-js": "^2.6.0", "@azure/core-rest-pipeline": "^1.22.0",
"@azure/storage-blob": "^12.13.0", "@azure/storage-blob": "^12.29.1",
"@protobuf-ts/runtime-rpc": "^2.11.1", "@protobuf-ts/runtime-rpc": "^2.11.1",
"semver": "^6.3.1" "semver": "^6.3.1"
} }
}, },
"node_modules/@actions/cache/node_modules/@actions/glob": { "node_modules/@actions/cache/node_modules/@actions/http-client": {
"version": "0.1.2", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/@actions/glob/-/glob-0.1.2.tgz", "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-3.0.0.tgz",
"integrity": "sha512-SclLR7Ia5sEqjkJTPs7Sd86maMDw43p769YxBOxvPvEWuPEhpAnBsQfENOpXjFYMmhCqd127bmf+YdvJqVqR4A==", "integrity": "sha512-1s3tXAfVMSz9a4ZEBkXXRQD4QhY3+GAsWSbaYpeknPOKEeyRiU3lH+bHiLMZdo2x/fIeQ/hscL1wCkDLVM2DZQ==",
"license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^1.2.6", "tunnel": "^0.0.6",
"minimatch": "^3.0.4" "undici": "^5.28.5"
} }
}, },
"node_modules/@actions/cache/node_modules/@actions/io": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/@actions/io/-/io-1.1.3.tgz",
"integrity": "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q==",
"license": "MIT"
},
"node_modules/@actions/core": { "node_modules/@actions/core": {
"version": "1.11.1", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.11.1.tgz", "resolved": "https://registry.npmjs.org/@actions/core/-/core-2.0.1.tgz",
"integrity": "sha512-hXJCSrkwfA46Vd9Z3q4cpEpHB1rL5NG04+/rbqW9d3+CSvtB1tYe8UTpAlixa1vj0m/ULglfEK2UKxMGxCxv5A==", "integrity": "sha512-oBfqT3GwkvLlo1fjvhQLQxuwZCGTarTE5OuZ2Wg10hvhBj7LRIlF611WT4aZS6fDhO5ZKlY7lCAZTlpmyaHaeg==",
"license": "MIT",
"dependencies": { "dependencies": {
"@actions/exec": "^1.1.1", "@actions/exec": "^2.0.0",
"@actions/http-client": "^2.0.1" "@actions/http-client": "^3.0.0"
}
},
"node_modules/@actions/core/node_modules/@actions/http-client": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-3.0.0.tgz",
"integrity": "sha512-1s3tXAfVMSz9a4ZEBkXXRQD4QhY3+GAsWSbaYpeknPOKEeyRiU3lH+bHiLMZdo2x/fIeQ/hscL1wCkDLVM2DZQ==",
"license": "MIT",
"dependencies": {
"tunnel": "^0.0.6",
"undici": "^5.28.5"
} }
}, },
"node_modules/@actions/exec": { "node_modules/@actions/exec": {
"version": "1.1.1", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.1.1.tgz", "resolved": "https://registry.npmjs.org/@actions/exec/-/exec-2.0.0.tgz",
"integrity": "sha512-+sCcHHbVdk93a0XT19ECtO/gIXoxvdsgQLzb2fE2/5sIZmWQuluYyjPQtrtTHdU1YzTZ7bAPN4sITq2xi1679w==", "integrity": "sha512-k8ngrX2voJ/RIN6r9xB82NVqKpnMRtxDoiO+g3olkIUpQNqjArXrCQceduQZCQj3P3xm32pChRLqRrtXTlqhIw==",
"license": "MIT",
"dependencies": { "dependencies": {
"@actions/io": "^1.0.1" "@actions/io": "^2.0.0"
} }
}, },
"node_modules/@actions/exec/node_modules/@actions/io": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/@actions/io/-/io-1.1.3.tgz",
"integrity": "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q==",
"license": "MIT"
},
"node_modules/@actions/github": { "node_modules/@actions/github": {
"version": "6.0.1", "version": "6.0.1",
"resolved": "https://registry.npmjs.org/@actions/github/-/github-6.0.1.tgz", "resolved": "https://registry.npmjs.org/@actions/github/-/github-6.0.1.tgz",
@ -137,6 +157,31 @@
"minimatch": "^3.0.4" "minimatch": "^3.0.4"
} }
}, },
"node_modules/@actions/glob/node_modules/@actions/core": {
"version": "1.11.1",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.11.1.tgz",
"integrity": "sha512-hXJCSrkwfA46Vd9Z3q4cpEpHB1rL5NG04+/rbqW9d3+CSvtB1tYe8UTpAlixa1vj0m/ULglfEK2UKxMGxCxv5A==",
"license": "MIT",
"dependencies": {
"@actions/exec": "^1.1.1",
"@actions/http-client": "^2.0.1"
}
},
"node_modules/@actions/glob/node_modules/@actions/exec": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.1.1.tgz",
"integrity": "sha512-+sCcHHbVdk93a0XT19ECtO/gIXoxvdsgQLzb2fE2/5sIZmWQuluYyjPQtrtTHdU1YzTZ7bAPN4sITq2xi1679w==",
"license": "MIT",
"dependencies": {
"@actions/io": "^1.0.1"
}
},
"node_modules/@actions/glob/node_modules/@actions/io": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/@actions/io/-/io-1.1.3.tgz",
"integrity": "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q==",
"license": "MIT"
},
"node_modules/@actions/http-client": { "node_modules/@actions/http-client": {
"version": "2.2.3", "version": "2.2.3",
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.2.3.tgz", "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.2.3.tgz",
@ -175,6 +220,25 @@
"uuid": "^3.3.3" "uuid": "^3.3.3"
} }
}, },
"node_modules/@actions/warpbuild-cache/node_modules/@actions/core": {
"version": "1.11.1",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.11.1.tgz",
"integrity": "sha512-hXJCSrkwfA46Vd9Z3q4cpEpHB1rL5NG04+/rbqW9d3+CSvtB1tYe8UTpAlixa1vj0m/ULglfEK2UKxMGxCxv5A==",
"license": "MIT",
"dependencies": {
"@actions/exec": "^1.1.1",
"@actions/http-client": "^2.0.1"
}
},
"node_modules/@actions/warpbuild-cache/node_modules/@actions/exec": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.1.1.tgz",
"integrity": "sha512-+sCcHHbVdk93a0XT19ECtO/gIXoxvdsgQLzb2fE2/5sIZmWQuluYyjPQtrtTHdU1YzTZ7bAPN4sITq2xi1679w==",
"license": "MIT",
"dependencies": {
"@actions/io": "^1.0.1"
}
},
"node_modules/@actions/warpbuild-cache/node_modules/@actions/glob": { "node_modules/@actions/warpbuild-cache/node_modules/@actions/glob": {
"version": "0.1.2", "version": "0.1.2",
"resolved": "https://registry.npmjs.org/@actions/glob/-/glob-0.1.2.tgz", "resolved": "https://registry.npmjs.org/@actions/glob/-/glob-0.1.2.tgz",
@ -229,6 +293,7 @@
"version": "1.10.1", "version": "1.10.1",
"resolved": "https://registry.npmjs.org/@azure/core-client/-/core-client-1.10.1.tgz", "resolved": "https://registry.npmjs.org/@azure/core-client/-/core-client-1.10.1.tgz",
"integrity": "sha512-Nh5PhEOeY6PrnxNPsEHRr9eimxLwgLlpmguQaHKBinFYA/RU9+kOYVOQqOrTsCL+KSxrLLl1gD8Dk5BFW/7l/w==", "integrity": "sha512-Nh5PhEOeY6PrnxNPsEHRr9eimxLwgLlpmguQaHKBinFYA/RU9+kOYVOQqOrTsCL+KSxrLLl1gD8Dk5BFW/7l/w==",
"license": "MIT",
"dependencies": { "dependencies": {
"@azure/abort-controller": "^2.1.2", "@azure/abort-controller": "^2.1.2",
"@azure/core-auth": "^1.10.0", "@azure/core-auth": "^1.10.0",
@ -246,6 +311,7 @@
"version": "2.1.2", "version": "2.1.2",
"resolved": "https://registry.npmjs.org/@azure/abort-controller/-/abort-controller-2.1.2.tgz", "resolved": "https://registry.npmjs.org/@azure/abort-controller/-/abort-controller-2.1.2.tgz",
"integrity": "sha512-nBrLsEWm4J2u5LpAPjxADTlq3trDgVZZXHNKabeXZtpq3d3AbN/KGO82R87rdDz5/lYB024rtEf10/q0urNgsA==", "integrity": "sha512-nBrLsEWm4J2u5LpAPjxADTlq3trDgVZZXHNKabeXZtpq3d3AbN/KGO82R87rdDz5/lYB024rtEf10/q0urNgsA==",
"license": "MIT",
"dependencies": { "dependencies": {
"tslib": "^2.6.2" "tslib": "^2.6.2"
}, },
@ -257,6 +323,7 @@
"version": "2.3.1", "version": "2.3.1",
"resolved": "https://registry.npmjs.org/@azure/core-http-compat/-/core-http-compat-2.3.1.tgz", "resolved": "https://registry.npmjs.org/@azure/core-http-compat/-/core-http-compat-2.3.1.tgz",
"integrity": "sha512-az9BkXND3/d5VgdRRQVkiJb2gOmDU8Qcq4GvjtBmDICNiQ9udFmDk4ZpSB5Qq1OmtDJGlQAfBaS4palFsazQ5g==", "integrity": "sha512-az9BkXND3/d5VgdRRQVkiJb2gOmDU8Qcq4GvjtBmDICNiQ9udFmDk4ZpSB5Qq1OmtDJGlQAfBaS4palFsazQ5g==",
"license": "MIT",
"dependencies": { "dependencies": {
"@azure/abort-controller": "^2.1.2", "@azure/abort-controller": "^2.1.2",
"@azure/core-client": "^1.10.0", "@azure/core-client": "^1.10.0",
@ -270,6 +337,7 @@
"version": "2.1.2", "version": "2.1.2",
"resolved": "https://registry.npmjs.org/@azure/abort-controller/-/abort-controller-2.1.2.tgz", "resolved": "https://registry.npmjs.org/@azure/abort-controller/-/abort-controller-2.1.2.tgz",
"integrity": "sha512-nBrLsEWm4J2u5LpAPjxADTlq3trDgVZZXHNKabeXZtpq3d3AbN/KGO82R87rdDz5/lYB024rtEf10/q0urNgsA==", "integrity": "sha512-nBrLsEWm4J2u5LpAPjxADTlq3trDgVZZXHNKabeXZtpq3d3AbN/KGO82R87rdDz5/lYB024rtEf10/q0urNgsA==",
"license": "MIT",
"dependencies": { "dependencies": {
"tslib": "^2.6.2" "tslib": "^2.6.2"
}, },
@ -429,9 +497,10 @@
} }
}, },
"node_modules/@azure/storage-blob": { "node_modules/@azure/storage-blob": {
"version": "12.28.0", "version": "12.29.1",
"resolved": "https://registry.npmjs.org/@azure/storage-blob/-/storage-blob-12.28.0.tgz", "resolved": "https://registry.npmjs.org/@azure/storage-blob/-/storage-blob-12.29.1.tgz",
"integrity": "sha512-VhQHITXXO03SURhDiGuHhvc/k/sD2WvJUS7hqhiVNbErVCuQoLtWql7r97fleBlIRKHJaa9R7DpBjfE0pfLYcA==", "integrity": "sha512-7ktyY0rfTM0vo7HvtK6E3UvYnI9qfd6Oz6z/+92VhGRveWng3kJwMKeUpqmW/NmwcDNbxHpSlldG+vsUnRFnBg==",
"license": "MIT",
"dependencies": { "dependencies": {
"@azure/abort-controller": "^2.1.2", "@azure/abort-controller": "^2.1.2",
"@azure/core-auth": "^1.9.0", "@azure/core-auth": "^1.9.0",
@ -444,7 +513,7 @@
"@azure/core-util": "^1.11.0", "@azure/core-util": "^1.11.0",
"@azure/core-xml": "^1.4.5", "@azure/core-xml": "^1.4.5",
"@azure/logger": "^1.1.4", "@azure/logger": "^1.1.4",
"@azure/storage-common": "^12.0.0-beta.2", "@azure/storage-common": "^12.1.1",
"events": "^3.0.0", "events": "^3.0.0",
"tslib": "^2.8.1" "tslib": "^2.8.1"
}, },
@ -464,9 +533,10 @@
} }
}, },
"node_modules/@azure/storage-common": { "node_modules/@azure/storage-common": {
"version": "12.0.0", "version": "12.1.1",
"resolved": "https://registry.npmjs.org/@azure/storage-common/-/storage-common-12.0.0.tgz", "resolved": "https://registry.npmjs.org/@azure/storage-common/-/storage-common-12.1.1.tgz",
"integrity": "sha512-QyEWXgi4kdRo0wc1rHum9/KnaWZKCdQGZK1BjU4fFL6Jtedp7KLbQihgTTVxldFy1z1ZPtuDPx8mQ5l3huPPbA==", "integrity": "sha512-eIOH1pqFwI6UmVNnDQvmFeSg0XppuzDLFeUNO/Xht7ODAzRLgGDh7h550pSxoA+lPDxBl1+D2m/KG3jWzCUjTg==",
"license": "MIT",
"dependencies": { "dependencies": {
"@azure/abort-controller": "^2.1.2", "@azure/abort-controller": "^2.1.2",
"@azure/core-auth": "^1.9.0", "@azure/core-auth": "^1.9.0",
@ -486,6 +556,7 @@
"version": "2.1.2", "version": "2.1.2",
"resolved": "https://registry.npmjs.org/@azure/abort-controller/-/abort-controller-2.1.2.tgz", "resolved": "https://registry.npmjs.org/@azure/abort-controller/-/abort-controller-2.1.2.tgz",
"integrity": "sha512-nBrLsEWm4J2u5LpAPjxADTlq3trDgVZZXHNKabeXZtpq3d3AbN/KGO82R87rdDz5/lYB024rtEf10/q0urNgsA==", "integrity": "sha512-nBrLsEWm4J2u5LpAPjxADTlq3trDgVZZXHNKabeXZtpq3d3AbN/KGO82R87rdDz5/lYB024rtEf10/q0urNgsA==",
"license": "MIT",
"dependencies": { "dependencies": {
"tslib": "^2.6.2" "tslib": "^2.6.2"
}, },
@ -768,9 +839,9 @@
"integrity": "sha512-hWtVTC2q7hc7xZ/RLbxapMvDMgUnDvKvMOpKal4DrMyfGBUfB1oKaZlIRr6mJL+If3bAP6sV/QneGzF6tJjZDg==" "integrity": "sha512-hWtVTC2q7hc7xZ/RLbxapMvDMgUnDvKvMOpKal4DrMyfGBUfB1oKaZlIRr6mJL+If3bAP6sV/QneGzF6tJjZDg=="
}, },
"node_modules/@types/node": { "node_modules/@types/node": {
"version": "24.10.1", "version": "25.0.2",
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.10.1.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-25.0.2.tgz",
"integrity": "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ==", "integrity": "sha512-gWEkeiyYE4vqjON/+Obqcoeffmk0NF15WSBwSs7zwVA2bAbTaE0SJ7P0WNGoJn8uE7fiaV5a7dKYIJriEqOrmA==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"undici-types": "~7.16.0" "undici-types": "~7.16.0"
@ -1081,6 +1152,7 @@
"version": "3.3.0", "version": "3.3.0",
"resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz", "resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz",
"integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==", "integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==",
"license": "MIT",
"engines": { "engines": {
"node": ">=0.8.x" "node": ">=0.8.x"
} }

View File

@ -24,15 +24,15 @@
"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.7", "@actions/warpbuild-cache": "npm:github-actions.warp-cache@1.4.7",
"@actions/cache": "^4.1.0", "@actions/cache": "^5.0.1",
"@actions/core": "^1.11.1", "@actions/core": "^2.0.1",
"@actions/exec": "^1.1.1", "@actions/exec": "^2.0.0",
"@actions/glob": "^0.5.0", "@actions/glob": "^0.5.0",
"@actions/io": "^2.0.0", "@actions/io": "^2.0.0",
"smol-toml": "^1.5.2" "smol-toml": "^1.5.2"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^24.10.1", "@types/node": "^25.0.2",
"@vercel/ncc": "^0.38.4", "@vercel/ncc": "^0.38.4",
"linefix": "^0.1.1", "linefix": "^0.1.1",
"typescript": "5.9.3" "typescript": "5.9.3"

View File

@ -1,8 +1,9 @@
import * as core from "@actions/core"; import * as core from "@actions/core";
import * as glob from "@actions/glob"; import * as glob from "@actions/glob";
import crypto from "crypto"; import crypto from "crypto";
import fs from "fs"; import fs from "fs/promises";
import fs_promises from "fs/promises"; import { createReadStream } from "fs";
import { pipeline } from "stream/promises";
import os from "os"; import os from "os";
import path from "path"; import path from "path";
import * as toml from "smol-toml"; import * as toml from "smol-toml";
@ -18,6 +19,9 @@ const STATE_CONFIG = "RUST_CACHE_CONFIG";
const HASH_LENGTH = 8; const HASH_LENGTH = 8;
export class CacheConfig { export class CacheConfig {
/** A format string for running commands */
public cmdFormat: string = "";
/** All the paths we want to cache */ /** All the paths we want to cache */
public cachePaths: Array<string> = []; public cachePaths: Array<string> = [];
/** The primary cache key */ /** The primary cache key */
@ -37,7 +41,7 @@ export class CacheConfig {
/** The prefix portion of the cache key */ /** The prefix portion of the cache key */
private keyPrefix = ""; private keyPrefix = "";
/** The rust version considered for the cache key */ /** The rust version considered for the cache key */
private keyRust = ""; private keyRust: Array<string> = [];
/** The environment variables considered for the cache key */ /** The environment variables considered for the cache key */
private keyEnvs: Array<string> = []; private keyEnvs: Array<string> = [];
/** The files considered for the cache key */ /** The files considered for the cache key */
@ -53,6 +57,17 @@ export class CacheConfig {
static async new(): Promise<CacheConfig> { static async new(): Promise<CacheConfig> {
const self = new CacheConfig(); const self = new CacheConfig();
let cmdFormat = core.getInput("cmd-format");
if (cmdFormat) {
const placeholderMatches = cmdFormat.match(/\{0\}/g);
if (!placeholderMatches || placeholderMatches.length !== 1) {
cmdFormat = "{0}";
}
} else {
cmdFormat = "{0}";
}
self.cmdFormat = cmdFormat;
// Construct key prefix: // Construct key prefix:
// This uses either the `shared-key` input, // This uses either the `shared-key` input,
// or the `key` input combined with the `job` key. // or the `key` input combined with the `job` key.
@ -89,14 +104,16 @@ export class CacheConfig {
// resulting environment hash. // resulting environment hash.
let hasher = crypto.createHash("sha1"); let hasher = crypto.createHash("sha1");
const rustVersion = await getRustVersion(); const rustVersions = Array.from(await getRustVersions(cmdFormat));
// Doesn't matter how they're sorted, just as long as it's deterministic.
rustVersions.sort();
let keyRust = `${rustVersion.release} ${rustVersion.host}`; for (const rustVersion of rustVersions) {
hasher.update(keyRust); const { release, host, "commit-hash": commitHash } = rustVersion;
hasher.update(rustVersion["commit-hash"]); const keyRust = `${release} ${host} ${commitHash}`;
hasher.update(keyRust);
keyRust += ` (${rustVersion["commit-hash"]})`; self.keyRust.push(keyRust);
self.keyRust = keyRust; }
// these prefixes should cover most of the compiler / rust / cargo keys // these prefixes should cover most of the compiler / rust / cargo keys
const envPrefixes = ["CARGO", "CC", "CFLAGS", "CXX", "CMAKE", "RUST"]; const envPrefixes = ["CARGO", "CC", "CFLAGS", "CXX", "CMAKE", "RUST"];
@ -158,13 +175,13 @@ export class CacheConfig {
)), )),
); );
const workspaceMembers = await workspace.getWorkspaceMembers(); const workspaceMembers = await workspace.getWorkspaceMembers(cmdFormat);
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 {
const content = await fs_promises.readFile(cargo_manifest, { encoding: "utf8" }); const content = await fs.readFile(cargo_manifest, { encoding: "utf8" });
// Use any since TomlPrimitive is not exposed // Use any since TomlPrimitive is not exposed
const parsed = toml.parse(content) as { [key: string]: any }; const parsed = toml.parse(content) as { [key: string]: any };
@ -211,7 +228,7 @@ export class CacheConfig {
const cargo_lock = path.join(workspace.root, "Cargo.lock"); const cargo_lock = path.join(workspace.root, "Cargo.lock");
if (await exists(cargo_lock)) { if (await exists(cargo_lock)) {
try { try {
const content = await fs_promises.readFile(cargo_lock, { encoding: "utf8" }); const content = await fs.readFile(cargo_lock, { encoding: "utf8" });
const parsed = toml.parse(content); const parsed = toml.parse(content);
if ((parsed.version !== 3 && parsed.version !== 4) || !("package" in parsed)) { if ((parsed.version !== 3 && parsed.version !== 4) || !("package" in parsed)) {
@ -239,9 +256,7 @@ export class CacheConfig {
keyFiles = sort_and_uniq(keyFiles); keyFiles = sort_and_uniq(keyFiles);
for (const file of keyFiles) { for (const file of keyFiles) {
for await (const chunk of fs.createReadStream(file)) { await pipeline(createReadStream(file), hasher);
hasher.update(chunk);
}
} }
keyFiles.push(...parsedKeyFiles); keyFiles.push(...parsedKeyFiles);
@ -321,7 +336,10 @@ export class CacheConfig {
core.info(`.. Prefix:`); core.info(`.. Prefix:`);
core.info(` - ${this.keyPrefix}`); core.info(` - ${this.keyPrefix}`);
core.info(`.. Environment considered:`); core.info(`.. Environment considered:`);
core.info(` - Rust Version: ${this.keyRust}`); core.info(` - Rust Versions:`);
for (const rust of this.keyRust) {
core.info(` - ${rust}`);
}
for (const env of this.keyEnvs) { for (const env of this.keyEnvs) {
core.info(` - ${env}`); core.info(` - ${env}`);
} }
@ -366,9 +384,33 @@ interface RustVersion {
"commit-hash": string; "commit-hash": string;
} }
async function getRustVersion(): Promise<RustVersion> { async function getRustVersions(cmdFormat: string): Promise<Set<RustVersion>> {
const stdout = await getCmdOutput("rustc", ["-vV"]); const versions = new Set<RustVersion>();
let splits = stdout
versions.add(parseRustVersion(await getCmdOutput(cmdFormat, "rustc -vV")));
const stdout = await (async () => {
try {
return await getCmdOutput(cmdFormat, "rustup toolchain list --quiet");
} catch (e) {
core.warning(`Error running rustup toolchain list, falling back to default toolchain only: ${e}`);
return undefined;
}
})();
if (stdout !== undefined) {
for (const toolchain of stdout.split(/[\n\r]+/)) {
const trimmed = toolchain.trim();
if (!trimmed) {
continue;
}
versions.add(parseRustVersion(await getCmdOutput(cmdFormat, `rustup run ${toolchain} rustc -vV`)));
}
}
return versions;
}
function parseRustVersion(stdout: string): RustVersion {
const splits = stdout
.split(/[\n\r]+/) .split(/[\n\r]+/)
.filter(Boolean) .filter(Boolean)
.map((s) => s.split(":").map((s) => s.trim())) .map((s) => s.split(":").map((s) => s.trim()))
@ -380,10 +422,17 @@ async function globFiles(pattern: string): Promise<string[]> {
const globber = await glob.create(pattern, { const globber = await glob.create(pattern, {
followSymbolicLinks: false, followSymbolicLinks: false,
}); });
// fs.statSync resolve the symbolic link and returns stat for the // fs.stat resolve the symbolic link and returns stat for the
// file it pointed to, so isFile would make sure the resolved // file it pointed to, so isFile would make sure the resolved
// file is actually a regular file. // file is actually a regular file.
return (await globber.glob()).filter((file) => fs.statSync(file).isFile()); const files = [];
for (const file of await globber.glob()) {
const stats = await fs.stat(file);
if (stats.isFile()) {
files.push(file);
}
}
return files;
} }
function sort_and_uniq(a: string[]) { function sort_and_uniq(a: string[]) {

View File

@ -39,9 +39,9 @@ async function run() {
const workspaceCrates = core.getInput("cache-workspace-crates").toLowerCase() || "false"; 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(config.cmdFormat);
if (workspaceCrates === "true") { if (workspaceCrates === "true") {
const wsMembers = await workspace.getWorkspaceMembers(); const wsMembers = await workspace.getWorkspaceMembers(config.cmdFormat);
packages.push(...wsMembers); packages.push(...wsMembers);
} }
allPackages.push(...packages); allPackages.push(...packages);

View File

@ -16,14 +16,15 @@ export function reportError(e: any) {
} }
export async function getCmdOutput( export async function getCmdOutput(
cmdFormat: string,
cmd: string, cmd: string,
args: Array<string> = [],
options: exec.ExecOptions = {}, options: exec.ExecOptions = {},
): Promise<string> { ): Promise<string> {
cmd = cmdFormat.replace("{0}", cmd);
let stdout = ""; let stdout = "";
let stderr = ""; let stderr = "";
try { try {
await exec.exec(cmd, args, { await exec.exec(cmd, [], {
silent: true, silent: true,
listeners: { listeners: {
stdout(data) { stdout(data) {
@ -37,7 +38,7 @@ export async function getCmdOutput(
}); });
} catch (e) { } catch (e) {
(e as any).commandFailed = { (e as any).commandFailed = {
command: `${cmd} ${args.join(" ")}`, command: cmd,
stderr, stderr,
}; };
throw e; throw e;

View File

@ -8,12 +8,13 @@ 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(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 = []; let packages: Packages = [];
try { try {
core.debug(`collecting metadata for "${this.root}"`); core.debug(`collecting metadata for "${this.root}"`);
const meta: Meta = JSON.parse( const meta: Meta = JSON.parse(
await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1", ...extraArgs], { await getCmdOutput(cmdFormat, cmd, {
cwd: this.root, cwd: this.root,
env: { ...process.env, "CARGO_ENCODED_RUSTFLAGS": "" }, env: { ...process.env, "CARGO_ENCODED_RUSTFLAGS": "" },
}), }),
@ -29,12 +30,12 @@ export class Workspace {
return packages; return packages;
} }
public async getPackagesOutsideWorkspaceRoot(): Promise<Packages> { public async getPackagesOutsideWorkspaceRoot(cmdFormat: string): Promise<Packages> {
return await this.getPackages((pkg) => !pkg.manifest_path.startsWith(this.root)); return await this.getPackages(cmdFormat, (pkg) => !pkg.manifest_path.startsWith(this.root));
} }
public async getWorkspaceMembers(): Promise<Packages> { public async getWorkspaceMembers(cmdFormat: string): Promise<Packages> {
return await this.getPackages((_) => true, "--no-deps"); return await this.getPackages(cmdFormat, (_) => true, "--no-deps");
} }
} }

31
tests/flake.nix Normal file
View File

@ -0,0 +1,31 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = inputs @ { self, nixpkgs, flake-utils, rust-overlay, ... }:
flake-utils.lib.eachDefaultSystem (
system: let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs { inherit system overlays; };
in {
devShells.default = with pkgs; mkShell {
buildInputs = [
autoconf
gcc
gnumake
openssl
pkg-config
rust-bin.stable.latest.minimal
];
CARGO_TERM_COLOR = "always";
};
}
);
}