Add new input.

This commit is contained in:
Miles Johnson 2024-05-03 11:37:20 -07:00
parent e6a829b5bd
commit 6a8624d80a
5 changed files with 23 additions and 8 deletions

View file

@ -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

View file

@ -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

View file

@ -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:

View file

@ -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(),
];
}

View file

@ -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();