mirror of
https://github.com/moonrepo/setup-rust.git
synced 2025-04-29 13:30:03 +00:00
fix: Fix caching issues.
This commit is contained in:
parent
b183549b9a
commit
c49c6099c9
4 changed files with 22 additions and 14 deletions
|
@ -94,8 +94,8 @@ The following optimizations and considerations are taken into account when cachi
|
||||||
`src`, `.cache`, and any other unnecessary files.
|
`src`, `.cache`, and any other unnecessary files.
|
||||||
- Only the `/target/debug` profile is cached, as this profile is typically used for formatting,
|
- Only the `/target/debug` profile is cached, as this profile is typically used for formatting,
|
||||||
linting, and testing.
|
linting, and testing.
|
||||||
- The following sources are hashed for the generated cache key: `Cargo.lock`, Rust version, Rust
|
- The following sources are hashed for the generated cache key: `$GITHUB_JOB`, `Cargo.lock`, Rust
|
||||||
commit hash, and operating system.
|
version, Rust commit hash, and operating system.
|
||||||
|
|
||||||
## Compared to
|
## Compared to
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@moonrepo/setup-rust",
|
"name": "@moonrepo/setup-rust",
|
||||||
"version": "0.3.0",
|
"version": "0.3.1",
|
||||||
"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": {
|
||||||
|
@ -20,6 +20,7 @@
|
||||||
"@actions/core": "^1.10.0",
|
"@actions/core": "^1.10.0",
|
||||||
"@actions/exec": "^1.1.1",
|
"@actions/exec": "^1.1.1",
|
||||||
"@actions/glob": "^0.4.0",
|
"@actions/glob": "^0.4.0",
|
||||||
|
"@actions/io": "^1.1.3",
|
||||||
"@actions/tool-cache": "^2.0.1",
|
"@actions/tool-cache": "^2.0.1",
|
||||||
"@ltd/j-toml": "^1.38.0"
|
"@ltd/j-toml": "^1.38.0"
|
||||||
},
|
},
|
||||||
|
|
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
|
@ -13,6 +13,9 @@ dependencies:
|
||||||
'@actions/glob':
|
'@actions/glob':
|
||||||
specifier: ^0.4.0
|
specifier: ^0.4.0
|
||||||
version: 0.4.0
|
version: 0.4.0
|
||||||
|
'@actions/io':
|
||||||
|
specifier: ^1.1.3
|
||||||
|
version: 1.1.3
|
||||||
'@actions/tool-cache':
|
'@actions/tool-cache':
|
||||||
specifier: ^2.0.1
|
specifier: ^2.0.1
|
||||||
version: 2.0.1
|
version: 2.0.1
|
||||||
|
|
26
src/cargo.ts
26
src/cargo.ts
|
@ -1,16 +1,13 @@
|
||||||
/* eslint-disable node/no-unsupported-features/node-builtins */
|
|
||||||
|
|
||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
import fs from 'fs';
|
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import * as cache from '@actions/cache';
|
import * as cache from '@actions/cache';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
import * as glob from '@actions/glob';
|
import * as glob from '@actions/glob';
|
||||||
|
import * as io from '@actions/io';
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
export const CARGO_HOME = process.env.CARGO_HOME ?? path.join(os.homedir(), '.cargo');
|
||||||
export const CARGO_HOME = process.env.CARGO_HOME || path.join(os.homedir(), '.cargo');
|
|
||||||
|
|
||||||
export const CACHE_ENABLED = core.getBooleanInput('cache') || cache.isFeatureAvailable();
|
export const CACHE_ENABLED = core.getBooleanInput('cache') || cache.isFeatureAvailable();
|
||||||
|
|
||||||
|
@ -21,25 +18,32 @@ export async function getPrimaryCacheKey() {
|
||||||
return CACHE_KEY;
|
return CACHE_KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hasher = crypto.createHash('sha1');
|
||||||
|
|
||||||
core.info('Generating cache key');
|
core.info('Generating cache key');
|
||||||
|
|
||||||
const rustVersion = core.getState('rust-version');
|
const rustVersion = core.getState('rust-version');
|
||||||
|
|
||||||
core.debug(`Hashing Rust version = ${rustVersion}`);
|
core.debug(`Hashing Rust version = ${rustVersion}`);
|
||||||
|
hasher.update(rustVersion);
|
||||||
|
|
||||||
const rustHash = core.getState('rust-hash');
|
const rustHash = core.getState('rust-hash');
|
||||||
|
|
||||||
core.debug(`Hashing Rust commit hash = ${rustHash}`);
|
core.debug(`Hashing Rust commit hash = ${rustHash}`);
|
||||||
|
hasher.update(rustHash);
|
||||||
|
|
||||||
const lockHash = await glob.hashFiles('Cargo.lock');
|
const lockHash = await glob.hashFiles('Cargo.lock');
|
||||||
|
|
||||||
core.debug(`Hashing Cargo.lock = ${lockHash}`);
|
core.debug(`Hashing Cargo.lock = ${lockHash}`);
|
||||||
|
|
||||||
const hasher = crypto.createHash('sha1');
|
|
||||||
hasher.update(rustVersion);
|
|
||||||
hasher.update(rustHash);
|
|
||||||
hasher.update(lockHash);
|
hasher.update(lockHash);
|
||||||
|
|
||||||
|
const job = process.env.GITHUB_JOB;
|
||||||
|
|
||||||
|
if (job) {
|
||||||
|
core.debug(`Hashing GITHUB_JOB = ${job}`);
|
||||||
|
hasher.update(job);
|
||||||
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line require-atomic-updates
|
// eslint-disable-next-line require-atomic-updates
|
||||||
CACHE_KEY = `setup-rustcargo-${process.platform}-${hasher.digest('hex')}`;
|
CACHE_KEY = `setup-rustcargo-${process.platform}-${hasher.digest('hex')}`;
|
||||||
|
|
||||||
|
@ -51,7 +55,7 @@ export function getPathsToCache(): string[] {
|
||||||
// ~/.cargo/registry
|
// ~/.cargo/registry
|
||||||
path.join(CARGO_HOME, 'registry'),
|
path.join(CARGO_HOME, 'registry'),
|
||||||
// /workspace/target/debug
|
// /workspace/target/debug
|
||||||
path.join(process.cwd(), 'target/debug'),
|
path.join(process.env.GITHUB_WORKSPACE ?? process.cwd(), 'target/debug'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +72,7 @@ export async function cleanCargoRegistry() {
|
||||||
|
|
||||||
for await (const file of globber.globGenerator()) {
|
for await (const file of globber.globGenerator()) {
|
||||||
core.debug(`Deleting ${file}`);
|
core.debug(`Deleting ${file}`);
|
||||||
await fs.promises.unlink(file);
|
await io.rmRF(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
// .cargo/registry/cache - Do nothing?
|
// .cargo/registry/cache - Do nothing?
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue