1
- /* eslint-disable node/no-unsupported-features/node-builtins */
2
-
3
1
import crypto from 'crypto' ;
4
- import fs from 'fs' ;
5
2
import os from 'os' ;
6
3
import path from 'path' ;
7
4
import * as cache from '@actions/cache' ;
8
5
import * as core from '@actions/core' ;
9
6
import * as exec from '@actions/exec' ;
10
7
import * as glob from '@actions/glob' ;
8
+ import * as io from '@actions/io' ;
11
9
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' ) ;
14
11
15
12
export const CACHE_ENABLED = core . getBooleanInput ( 'cache' ) || cache . isFeatureAvailable ( ) ;
16
13
@@ -21,25 +18,32 @@ export async function getPrimaryCacheKey() {
21
18
return CACHE_KEY ;
22
19
}
23
20
21
+ const hasher = crypto . createHash ( 'sha1' ) ;
22
+
24
23
core . info ( 'Generating cache key' ) ;
25
24
26
25
const rustVersion = core . getState ( 'rust-version' ) ;
27
26
28
27
core . debug ( `Hashing Rust version = ${ rustVersion } ` ) ;
28
+ hasher . update ( rustVersion ) ;
29
29
30
30
const rustHash = core . getState ( 'rust-hash' ) ;
31
31
32
32
core . debug ( `Hashing Rust commit hash = ${ rustHash } ` ) ;
33
+ hasher . update ( rustHash ) ;
33
34
34
35
const lockHash = await glob . hashFiles ( 'Cargo.lock' ) ;
35
36
36
37
core . debug ( `Hashing Cargo.lock = ${ lockHash } ` ) ;
37
-
38
- const hasher = crypto . createHash ( 'sha1' ) ;
39
- hasher . update ( rustVersion ) ;
40
- hasher . update ( rustHash ) ;
41
38
hasher . update ( lockHash ) ;
42
39
40
+ const job = process . env . GITHUB_JOB ;
41
+
42
+ if ( job ) {
43
+ core . debug ( `Hashing GITHUB_JOB = ${ job } ` ) ;
44
+ hasher . update ( job ) ;
45
+ }
46
+
43
47
// eslint-disable-next-line require-atomic-updates
44
48
CACHE_KEY = `setup-rustcargo-${ process . platform } -${ hasher . digest ( 'hex' ) } ` ;
45
49
@@ -51,7 +55,7 @@ export function getPathsToCache(): string[] {
51
55
// ~/.cargo/registry
52
56
path . join ( CARGO_HOME , 'registry' ) ,
53
57
// /workspace/target/debug
54
- path . join ( process . cwd ( ) , 'target/debug' ) ,
58
+ path . join ( process . env . GITHUB_WORKSPACE ?? process . cwd ( ) , 'target/debug' ) ,
55
59
] ;
56
60
}
57
61
@@ -68,7 +72,7 @@ export async function cleanCargoRegistry() {
68
72
69
73
for await ( const file of globber . globGenerator ( ) ) {
70
74
core . debug ( `Deleting ${ file } ` ) ;
71
- await fs . promises . unlink ( file ) ;
75
+ await io . rmRF ( file ) ;
72
76
}
73
77
74
78
// .cargo/registry/cache - Do nothing?
0 commit comments