diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ba0775..7b33572 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # 1.2.0 -- Updated to not save the cache if one of the required paths does not exist. +- Added a `target-dirs` input, allowing the target folders to be specified. Can now cache multiple + target folders. +- Updated to skip caching a directory if it does not exist, instead of failing. +- Updated dependencies. # 1.1.0 diff --git a/README.md b/README.md index 682a841..9a70ac7 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,8 @@ optional. - `inherit-toolchain` - Inherit all toolchain settings from the `rust-toolchain.toml` file. Defaults to `false`. - `targets` - Comma-separated list of additional targets to install. +- `target-dirs` - Comma-separated list of target folder paths, relative from the repository root. + Defaults to `target`. - `profile` - Profile to install. Defaults to `minimal`. ## Configuring the Rust toolchain diff --git a/action.yml b/action.yml index 249ef27..d207767 100644 --- a/action.yml +++ b/action.yml @@ -24,6 +24,9 @@ inputs: default: 'false' targets: description: 'Comma-separated list of additional targets to install.' + target-dirs: + description: 'Comma-separated list of target folder paths, relative from the repository root.' + default: 'target' profile: description: 'Profile to install. Defaults to "minimal".' outputs: diff --git a/src/cache.ts b/src/cache.ts index b276cf6..5dc0190 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -18,12 +18,19 @@ export function getCacheTarget(): string { return core.getInput('cache-target') || 'debug'; } +export function getTargetPaths(): string[] { + const profile = getCacheTarget(); + const dirs = core.getInput('target-dirs', { required: true }).split(','); + + return dirs.filter((dir) => dir.trim()).map((dir) => path.join(WORKSPACE_ROOT, dir, profile)); +} + export function getCachePaths(): string[] { return [ // ~/.cargo/registry path.join(CARGO_HOME, 'registry'), // /workspace/target/debug - path.join(WORKSPACE_ROOT, 'target', getCacheTarget()), + ...getTargetPaths(), ]; } diff --git a/src/cargo.ts b/src/cargo.ts index 9ae2704..01a4883 100644 --- a/src/cargo.ts +++ b/src/cargo.ts @@ -165,14 +165,14 @@ export async function saveCache() { return; } - const cachePaths = getCachePaths(); - - for (const cachePath of cachePaths) { + const cachePaths = getCachePaths().filter((cachePath) => { if (!fs.existsSync(cachePath)) { - core.info(`Cache path ${cachePath} does not exist, skipping save`); - return; + core.info(`Cache path ${cachePath} does not exist, skipping`); + return false; } - } + + return true; + }); await cleanCargoRegistry(); await cleanTargetProfile();