mirror of
https://github.com/moonrepo/setup-rust.git
synced 2025-04-29 21:40:01 +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
|
- Breaking: Cargo `bins` must provide the `cargo-` crate prefix manually. This change allows
|
||||||
non-crate globals to be installed.
|
non-crate globals to be installed.
|
||||||
|
- Added a `cache-target` input, to customize which target profile is cached. Defaults to `debug`.
|
||||||
|
|
||||||
# 0.5.0
|
# 0.5.0
|
||||||
|
|
||||||
|
|
|
@ -79,12 +79,14 @@ names.
|
||||||
## Caching in CI
|
## Caching in CI
|
||||||
|
|
||||||
By default this action will cache the `~/.cargo/registry` and `/target/debug` directories to improve
|
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
|
```yaml
|
||||||
- uses: moonrepo/setup-rust@v0
|
- uses: moonrepo/setup-rust@v0
|
||||||
with:
|
with:
|
||||||
cache: false
|
cache: false
|
||||||
|
cache-target: release
|
||||||
```
|
```
|
||||||
|
|
||||||
The following optimizations and considerations are taken into account when caching:
|
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.
|
`.cache`, and any other unnecessary files.
|
||||||
- `/target`
|
- `/target`
|
||||||
- Only the `/debug` profile is cached, as this profile is typically used for formatting, linting,
|
- 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
|
- The `/examples` and `/incremental` sub-directories are not cached as they are not necessary for
|
||||||
CI.
|
CI.
|
||||||
- All dep-info (`*.d`) files are removed, as they're meant for build systems and signaling
|
- All dep-info (`*.d`) files are removed, as they're meant for build systems and signaling
|
||||||
|
|
|
@ -7,8 +7,11 @@ inputs:
|
||||||
bins:
|
bins:
|
||||||
description: 'Comma-separated list of global binaries to install into Cargo.'
|
description: 'Comma-separated list of global binaries to install into Cargo.'
|
||||||
cache:
|
cache:
|
||||||
description: 'Toggle caching of ~/.cargo/registry and /target/debug directories.'
|
description: 'Toggle caching of ~/.cargo/registry and /target/<cache-target> directories.'
|
||||||
default: true
|
default: true
|
||||||
|
cache-target:
|
||||||
|
description: 'Name of the target profile to cache.'
|
||||||
|
default: 'debug'
|
||||||
channel:
|
channel:
|
||||||
description: 'Toolchain specification/channel to install.'
|
description: 'Toolchain specification/channel to install.'
|
||||||
components:
|
components:
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@moonrepo/setup-rust",
|
"name": "@moonrepo/setup-rust",
|
||||||
"version": "0.5.0",
|
"version": "0.6.0",
|
||||||
"description": "A GitHub action for setting up Rust and Cargo.",
|
"description": "A GitHub action for setting up Rust and Cargo.",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"scripts": {
|
"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]);
|
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[] {
|
export function getCachePaths(): string[] {
|
||||||
return [
|
return [
|
||||||
// ~/.cargo/registry
|
// ~/.cargo/registry
|
||||||
path.join(CARGO_HOME, 'registry'),
|
path.join(CARGO_HOME, 'registry'),
|
||||||
// /workspace/target/debug
|
// /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}`);
|
core.debug(`Hashing Cargo.lock = ${lockHash}`);
|
||||||
hasher.update(lockHash);
|
hasher.update(lockHash);
|
||||||
|
|
||||||
|
const cacheTarget = getCacheTarget();
|
||||||
|
|
||||||
|
core.debug(`Hashing target profile = ${cacheTarget}`);
|
||||||
|
hasher.update(cacheTarget);
|
||||||
|
|
||||||
const job = process.env.GITHUB_JOB;
|
const job = process.env.GITHUB_JOB;
|
||||||
|
|
||||||
if (job) {
|
if (job) {
|
||||||
|
@ -148,11 +157,13 @@ export async function cleanCargoRegistry() {
|
||||||
|
|
||||||
// https://doc.rust-lang.org/cargo/guide/build-cache.html
|
// https://doc.rust-lang.org/cargo/guide/build-cache.html
|
||||||
export async function cleanTargetProfile() {
|
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');
|
core.info('Removing examples and incremental directories');
|
||||||
|
|
||||||
await Promise.all(
|
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)');
|
core.info('Removing dep-info files (*.d)');
|
||||||
|
|
||||||
const globber = await glob.create(path.join(targetDir, '**/*.d'));
|
const globber = await glob.create(path.join(targetDir, '**/*.d'));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue