mirror of
https://github.com/moonrepo/setup-rust.git
synced 2025-04-20 09:38:43 +00:00
new: Add cache-target input.
This commit is contained in:
parent
cef1bc3f53
commit
28b46eda6c
5 changed files with 26 additions and 9 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
- Breaking: Cargo `bins` must provide the `cargo-` crate prefix manually. This change allows
|
||||
non-crate globals to be installed.
|
||||
- Added a `cache-target` input, to customize which target profile is cached. Defaults to `debug`.
|
||||
|
||||
# 0.5.0
|
||||
|
||||
|
|
|
@ -79,12 +79,14 @@ names.
|
|||
## Caching in CI
|
||||
|
||||
By default this action will cache the `~/.cargo/registry` and `/target/debug` directories to improve
|
||||
CI times. To disable caching, set the `cache` input to `false`.
|
||||
CI times. To disable caching, set the `cache` input to `false`. Furthermore, the target profile can
|
||||
be changed with the `cache-target` input, which defaults to `debug`.
|
||||
|
||||
```yaml
|
||||
- uses: moonrepo/setup-rust@v0
|
||||
with:
|
||||
cache: false
|
||||
cache-target: release
|
||||
```
|
||||
|
||||
The following optimizations and considerations are taken into account when caching:
|
||||
|
@ -98,7 +100,7 @@ The following optimizations and considerations are taken into account when cachi
|
|||
`.cache`, and any other unnecessary files.
|
||||
- `/target`
|
||||
- Only the `/debug` profile is cached, as this profile is typically used for formatting, linting,
|
||||
and testing.
|
||||
and testing. This can be changed with the `cache-target` input.
|
||||
- The `/examples` and `/incremental` sub-directories are not cached as they are not necessary for
|
||||
CI.
|
||||
- All dep-info (`*.d`) files are removed, as they're meant for build systems and signaling
|
||||
|
|
|
@ -7,8 +7,11 @@ inputs:
|
|||
bins:
|
||||
description: 'Comma-separated list of global binaries to install into Cargo.'
|
||||
cache:
|
||||
description: 'Toggle caching of ~/.cargo/registry and /target/debug directories.'
|
||||
description: 'Toggle caching of ~/.cargo/registry and /target/<cache-target> directories.'
|
||||
default: true
|
||||
cache-target:
|
||||
description: 'Name of the target profile to cache.'
|
||||
default: 'debug'
|
||||
channel:
|
||||
description: 'Toolchain specification/channel to install.'
|
||||
components:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@moonrepo/setup-rust",
|
||||
"version": "0.5.0",
|
||||
"version": "0.6.0",
|
||||
"description": "A GitHub action for setting up Rust and Cargo.",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
|
|
21
src/cargo.ts
21
src/cargo.ts
|
@ -83,12 +83,16 @@ export async function installBins() {
|
|||
await exec.exec('cargo', ['binstall', '--no-confirm', '--log-level', 'info', ...bins]);
|
||||
}
|
||||
|
||||
export function getCacheTarget(): string {
|
||||
return core.getInput('cache-target') || 'debug';
|
||||
}
|
||||
|
||||
export function getCachePaths(): string[] {
|
||||
return [
|
||||
// ~/.cargo/registry
|
||||
path.join(CARGO_HOME, 'registry'),
|
||||
// /workspace/target/debug
|
||||
path.join(WORKSPACE_ROOT, 'target/debug'),
|
||||
path.join(WORKSPACE_ROOT, 'target', getCacheTarget()),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -112,6 +116,11 @@ export async function getPrimaryCacheKey() {
|
|||
core.debug(`Hashing Cargo.lock = ${lockHash}`);
|
||||
hasher.update(lockHash);
|
||||
|
||||
const cacheTarget = getCacheTarget();
|
||||
|
||||
core.debug(`Hashing target profile = ${cacheTarget}`);
|
||||
hasher.update(cacheTarget);
|
||||
|
||||
const job = process.env.GITHUB_JOB;
|
||||
|
||||
if (job) {
|
||||
|
@ -148,11 +157,13 @@ export async function cleanCargoRegistry() {
|
|||
|
||||
// https://doc.rust-lang.org/cargo/guide/build-cache.html
|
||||
export async function cleanTargetProfile() {
|
||||
core.info('Cleaning target/debug before saving');
|
||||
const targetProfile = getCacheTarget();
|
||||
|
||||
const targetDir = path.join(WORKSPACE_ROOT, 'target/debug');
|
||||
core.info(`Cleaning target/${targetProfile} before saving`);
|
||||
|
||||
// target/debug/{examples,incremental} - Not required in CI
|
||||
const targetDir = path.join(WORKSPACE_ROOT, 'target', targetProfile);
|
||||
|
||||
// target/*/{examples,incremental} - Not required in CI
|
||||
core.info('Removing examples and incremental directories');
|
||||
|
||||
await Promise.all(
|
||||
|
@ -165,7 +176,7 @@ export async function cleanTargetProfile() {
|
|||
}),
|
||||
);
|
||||
|
||||
// target/debug/**/*.d - Not required in CI?
|
||||
// target/**/*.d - Not required in CI?
|
||||
core.info('Removing dep-info files (*.d)');
|
||||
|
||||
const globber = await glob.create(path.join(targetDir, '**/*.d'));
|
||||
|
|
Loading…
Add table
Reference in a new issue