Skip to content

Commit c49c609

Browse files
committed
fix: Fix caching issues.
1 parent b183549 commit c49c609

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ The following optimizations and considerations are taken into account when cachi
9494
`src`, `.cache`, and any other unnecessary files.
9595
- Only the `/target/debug` profile is cached, as this profile is typically used for formatting,
9696
linting, and testing.
97-
- The following sources are hashed for the generated cache key: `Cargo.lock`, Rust version, Rust
98-
commit hash, and operating system.
97+
- The following sources are hashed for the generated cache key: `$GITHUB_JOB`, `Cargo.lock`, Rust
98+
version, Rust commit hash, and operating system.
9999

100100
## Compared to
101101

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@moonrepo/setup-rust",
3-
"version": "0.3.0",
3+
"version": "0.3.1",
44
"description": "A GitHub action for setting up Rust and Cargo.",
55
"main": "dist/index.js",
66
"scripts": {
@@ -20,6 +20,7 @@
2020
"@actions/core": "^1.10.0",
2121
"@actions/exec": "^1.1.1",
2222
"@actions/glob": "^0.4.0",
23+
"@actions/io": "^1.1.3",
2324
"@actions/tool-cache": "^2.0.1",
2425
"@ltd/j-toml": "^1.38.0"
2526
},

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cargo.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
/* eslint-disable node/no-unsupported-features/node-builtins */
2-
31
import crypto from 'crypto';
4-
import fs from 'fs';
52
import os from 'os';
63
import path from 'path';
74
import * as cache from '@actions/cache';
85
import * as core from '@actions/core';
96
import * as exec from '@actions/exec';
107
import * as glob from '@actions/glob';
8+
import * as io from '@actions/io';
119

12-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
13-
export const CARGO_HOME = process.env.CARGO_HOME || path.join(os.homedir(), '.cargo');
10+
export const CARGO_HOME = process.env.CARGO_HOME ?? path.join(os.homedir(), '.cargo');
1411

1512
export const CACHE_ENABLED = core.getBooleanInput('cache') || cache.isFeatureAvailable();
1613

@@ -21,25 +18,32 @@ export async function getPrimaryCacheKey() {
2118
return CACHE_KEY;
2219
}
2320

21+
const hasher = crypto.createHash('sha1');
22+
2423
core.info('Generating cache key');
2524

2625
const rustVersion = core.getState('rust-version');
2726

2827
core.debug(`Hashing Rust version = ${rustVersion}`);
28+
hasher.update(rustVersion);
2929

3030
const rustHash = core.getState('rust-hash');
3131

3232
core.debug(`Hashing Rust commit hash = ${rustHash}`);
33+
hasher.update(rustHash);
3334

3435
const lockHash = await glob.hashFiles('Cargo.lock');
3536

3637
core.debug(`Hashing Cargo.lock = ${lockHash}`);
37-
38-
const hasher = crypto.createHash('sha1');
39-
hasher.update(rustVersion);
40-
hasher.update(rustHash);
4138
hasher.update(lockHash);
4239

40+
const job = process.env.GITHUB_JOB;
41+
42+
if (job) {
43+
core.debug(`Hashing GITHUB_JOB = ${job}`);
44+
hasher.update(job);
45+
}
46+
4347
// eslint-disable-next-line require-atomic-updates
4448
CACHE_KEY = `setup-rustcargo-${process.platform}-${hasher.digest('hex')}`;
4549

@@ -51,7 +55,7 @@ export function getPathsToCache(): string[] {
5155
// ~/.cargo/registry
5256
path.join(CARGO_HOME, 'registry'),
5357
// /workspace/target/debug
54-
path.join(process.cwd(), 'target/debug'),
58+
path.join(process.env.GITHUB_WORKSPACE ?? process.cwd(), 'target/debug'),
5559
];
5660
}
5761

@@ -68,7 +72,7 @@ export async function cleanCargoRegistry() {
6872

6973
for await (const file of globber.globGenerator()) {
7074
core.debug(`Deleting ${file}`);
71-
await fs.promises.unlink(file);
75+
await io.rmRF(file);
7276
}
7377

7478
// .cargo/registry/cache - Do nothing?

0 commit comments

Comments
 (0)