mirror of
https://github.com/Swatinem/rust-cache.git
synced 2025-12-16 14:39:41 +00:00
Add support for running rust-cache commands from within a Nix shell (#290)
This commit is contained in:
parent
779680da71
commit
151eeee51b
33
.github/workflows/nix.yml
vendored
Normal file
33
.github/workflows/nix.yml
vendored
Normal 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@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- uses: cachix/install-nix-action@0b0e072294b088b73964f1d72dfdac0951439dbd # v31.8.4
|
||||||
|
|
||||||
|
- 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
|
||||||
10
README.md
10
README.md
@ -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.
|
||||||
|
|||||||
@ -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."
|
||||||
|
|||||||
41
dist/restore/index.js
vendored
41
dist/restore/index.js
vendored
@ -150675,11 +150675,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 +150695,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 +150743,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 +150763,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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150787,6 +150789,8 @@ 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 */
|
||||||
@ -150815,6 +150819,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,7 +150860,7 @@ 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 rustVersion = await getRustVersion(cmdFormat);
|
||||||
let keyRust = `${rustVersion.release} ${rustVersion.host}`;
|
let keyRust = `${rustVersion.release} ${rustVersion.host}`;
|
||||||
hasher.update(keyRust);
|
hasher.update(keyRust);
|
||||||
hasher.update(rustVersion["commit-hash"]);
|
hasher.update(rustVersion["commit-hash"]);
|
||||||
@ -150895,7 +150910,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 {
|
||||||
@ -151071,8 +151086,8 @@ 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 getRustVersion(cmdFormat) {
|
||||||
const stdout = await getCmdOutput("rustc", ["-vV"]);
|
const stdout = await getCmdOutput(cmdFormat, "rustc -vV");
|
||||||
let splits = stdout
|
let splits = stdout
|
||||||
.split(/[\n\r]+/)
|
.split(/[\n\r]+/)
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
|
|||||||
45
dist/save/index.js
vendored
45
dist/save/index.js
vendored
@ -150675,11 +150675,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 +150695,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 +150743,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 +150763,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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150787,6 +150789,8 @@ 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 */
|
||||||
@ -150815,6 +150819,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,7 +150860,7 @@ 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 rustVersion = await getRustVersion(cmdFormat);
|
||||||
let keyRust = `${rustVersion.release} ${rustVersion.host}`;
|
let keyRust = `${rustVersion.release} ${rustVersion.host}`;
|
||||||
hasher.update(keyRust);
|
hasher.update(keyRust);
|
||||||
hasher.update(rustVersion["commit-hash"]);
|
hasher.update(rustVersion["commit-hash"]);
|
||||||
@ -150895,7 +150910,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 {
|
||||||
@ -151071,8 +151086,8 @@ 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 getRustVersion(cmdFormat) {
|
||||||
const stdout = await getCmdOutput("rustc", ["-vV"]);
|
const stdout = await getCmdOutput(cmdFormat, "rustc -vV");
|
||||||
let splits = stdout
|
let splits = stdout
|
||||||
.split(/[\n\r]+/)
|
.split(/[\n\r]+/)
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
@ -151428,9 +151443,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);
|
||||||
|
|||||||
@ -18,6 +18,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 */
|
||||||
@ -53,6 +56,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,7 +103,7 @@ export class CacheConfig {
|
|||||||
// resulting environment hash.
|
// resulting environment hash.
|
||||||
|
|
||||||
let hasher = crypto.createHash("sha1");
|
let hasher = crypto.createHash("sha1");
|
||||||
const rustVersion = await getRustVersion();
|
const rustVersion = await getRustVersion(cmdFormat);
|
||||||
|
|
||||||
let keyRust = `${rustVersion.release} ${rustVersion.host}`;
|
let keyRust = `${rustVersion.release} ${rustVersion.host}`;
|
||||||
hasher.update(keyRust);
|
hasher.update(keyRust);
|
||||||
@ -158,7 +172,7 @@ 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")));
|
||||||
|
|
||||||
@ -366,8 +380,8 @@ interface RustVersion {
|
|||||||
"commit-hash": string;
|
"commit-hash": string;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getRustVersion(): Promise<RustVersion> {
|
async function getRustVersion(cmdFormat: string): Promise<RustVersion> {
|
||||||
const stdout = await getCmdOutput("rustc", ["-vV"]);
|
const stdout = await getCmdOutput(cmdFormat, "rustc -vV");
|
||||||
let splits = stdout
|
let splits = stdout
|
||||||
.split(/[\n\r]+/)
|
.split(/[\n\r]+/)
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
@ -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;
|
||||||
|
|||||||
@ -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
31
tests/flake.nix
Normal 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";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user