Skip to content

Commit

Permalink
Add new input.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed May 3, 2024
1 parent e6a829b commit 6a8624d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 8 additions & 1 deletion src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
];
}

Expand Down
12 changes: 6 additions & 6 deletions src/cargo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 6a8624d

Please sign in to comment.