mirror of
https://github.com/moonrepo/setup-rust.git
synced 2025-04-20 09:38:43 +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.
|
||||
- Only the `/target/debug` profile is cached, as this profile is typically used for formatting,
|
||||
linting, and testing.
|
||||
- The following sources are hashed for the generated cache key: `Cargo.lock`, Rust version, Rust
|
||||
commit hash, and operating system.
|
||||
- The following sources are hashed for the generated cache key: `$GITHUB_JOB`, `Cargo.lock`, Rust
|
||||
version, Rust commit hash, and operating system.
|
||||
|
||||
## Compared to
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@moonrepo/setup-rust",
|
||||
"version": "0.3.0",
|
||||
"version": "0.3.1",
|
||||
"description": "A GitHub action for setting up Rust and Cargo.",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
|
@ -20,6 +20,7 @@
|
|||
"@actions/core": "^1.10.0",
|
||||
"@actions/exec": "^1.1.1",
|
||||
"@actions/glob": "^0.4.0",
|
||||
"@actions/io": "^1.1.3",
|
||||
"@actions/tool-cache": "^2.0.1",
|
||||
"@ltd/j-toml": "^1.38.0"
|
||||
},
|
||||
|
|
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
|
@ -13,6 +13,9 @@ dependencies:
|
|||
'@actions/glob':
|
||||
specifier: ^0.4.0
|
||||
version: 0.4.0
|
||||
'@actions/io':
|
||||
specifier: ^1.1.3
|
||||
version: 1.1.3
|
||||
'@actions/tool-cache':
|
||||
specifier: ^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 fs from 'fs';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import * as cache from '@actions/cache';
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
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();
|
||||
|
||||
|
@ -21,25 +18,32 @@ export async function getPrimaryCacheKey() {
|
|||
return CACHE_KEY;
|
||||
}
|
||||
|
||||
const hasher = crypto.createHash('sha1');
|
||||
|
||||
core.info('Generating cache key');
|
||||
|
||||
const rustVersion = core.getState('rust-version');
|
||||
|
||||
core.debug(`Hashing Rust version = ${rustVersion}`);
|
||||
hasher.update(rustVersion);
|
||||
|
||||
const rustHash = core.getState('rust-hash');
|
||||
|
||||
core.debug(`Hashing Rust commit hash = ${rustHash}`);
|
||||
hasher.update(rustHash);
|
||||
|
||||
const lockHash = await glob.hashFiles('Cargo.lock');
|
||||
|
||||
core.debug(`Hashing Cargo.lock = ${lockHash}`);
|
||||
|
||||
const hasher = crypto.createHash('sha1');
|
||||
hasher.update(rustVersion);
|
||||
hasher.update(rustHash);
|
||||
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
|
||||
CACHE_KEY = `setup-rustcargo-${process.platform}-${hasher.digest('hex')}`;
|
||||
|
||||
|
@ -51,7 +55,7 @@ export function getPathsToCache(): string[] {
|
|||
// ~/.cargo/registry
|
||||
path.join(CARGO_HOME, 'registry'),
|
||||
// /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()) {
|
||||
core.debug(`Deleting ${file}`);
|
||||
await fs.promises.unlink(file);
|
||||
await io.rmRF(file);
|
||||
}
|
||||
|
||||
// .cargo/registry/cache - Do nothing?
|
||||
|
|
Loading…
Add table
Reference in a new issue