@@ -18,25 +18,33 @@ export interface Release {
18
18
isPrerelease : boolean ;
19
19
}
20
20
21
- export async function makeToolcacheDir ( release : Release , platform : string ) : Promise < [ string , boolean ] > {
21
+ export async function getToolcacheDir ( platform : string , release : Release ) : Promise < [ string , boolean ] > {
22
22
let toolpath : string = tc . find ( "MATLAB" , release . version ) ;
23
23
let alreadyExists = false ;
24
24
if ( toolpath ) {
25
25
core . info ( `Found MATLAB ${ release . name } in cache at ${ toolpath } .` ) ;
26
26
alreadyExists = true ;
27
27
} else {
28
- if ( platform === "win32" ) {
29
- toolpath = await windowsHostedToolpath ( release ) . catch ( async ( ) => {
30
- return await defaultToolpath ( release , platform ) ;
31
- } ) ;
32
- } else {
33
- toolpath = await defaultToolpath ( release , platform ) ;
34
- }
28
+ toolpath = await makeToolcacheDir ( platform , release ) ;
29
+ }
30
+ if ( platform == "darwin" ) {
31
+ toolpath = toolpath + "/MATLAB.app" ;
35
32
}
36
33
return [ toolpath , alreadyExists ]
37
34
}
38
35
39
- async function windowsHostedToolpath ( release : Release ) : Promise < string > {
36
+ async function makeToolcacheDir ( platform : string , release : Release ) : Promise < string > {
37
+ let toolcacheDir : string ;
38
+ if ( platform === "win32" ) {
39
+ toolcacheDir = await makeWindowsHostedToolpath ( release )
40
+ . catch ( async ( ) => await makeDefaultToolpath ( release ) ) ;
41
+ } else {
42
+ toolcacheDir = await makeDefaultToolpath ( release ) ;
43
+ }
44
+ return toolcacheDir ;
45
+ }
46
+
47
+ async function makeWindowsHostedToolpath ( release : Release ) : Promise < string > {
40
48
// bail early if not on a github hosted runner
41
49
if ( process . env [ 'RUNNER_ENVIRONMENT' ] !== 'github-hosted' && process . env [ 'AGENT_ISSELFHOSTED' ] === '1' ) {
42
50
return Promise . reject ( ) ;
@@ -55,30 +63,36 @@ async function windowsHostedToolpath(release: Release): Promise<string> {
55
63
const actualToolCacheRoot = defaultToolCacheRoot . replace ( "C:" , "D:" ) . replace ( "c:" , "d:" ) ;
56
64
process . env [ 'RUNNER_TOOL_CACHE' ] = actualToolCacheRoot ;
57
65
58
- // create install directory and link it to the toolcache directory
59
- fs . writeFileSync ( ".keep" , "" ) ;
60
- let actualToolCacheDir = await tc . cacheFile ( ".keep" , ".keep" , "MATLAB" , release . version ) ;
61
- io . rmRF ( ".keep" ) ;
62
- let defaultToolCacheDir = actualToolCacheDir . replace ( actualToolCacheRoot , defaultToolCacheRoot ) ;
63
- fs . mkdirSync ( path . dirname ( defaultToolCacheDir ) , { recursive : true } ) ;
64
- fs . symlinkSync ( actualToolCacheDir , defaultToolCacheDir , 'junction' ) ;
65
-
66
- // required for github actions to make the cacheDir persistent
67
- const actualToolCacheCompleteFile = `${ actualToolCacheDir } .complete` ;
68
- const defaultToolCacheCompleteFile = `${ defaultToolCacheDir } .complete` ;
69
- fs . symlinkSync ( actualToolCacheCompleteFile , defaultToolCacheCompleteFile , 'file' ) ;
70
-
71
- process . env [ 'RUNNER_TOOL_CACHE' ] = defaultToolCacheRoot ;
72
- return actualToolCacheDir ;
66
+ try {
67
+ // create install directory and link it to the toolcache directory
68
+ fs . writeFileSync ( ".keep" , "" ) ;
69
+ let actualToolCacheDir = await tc . cacheFile ( ".keep" , ".keep" , "MATLAB" , release . version ) ;
70
+ await io . rmRF ( ".keep" ) ;
71
+ let defaultToolCacheDir = actualToolCacheDir . replace ( actualToolCacheRoot , defaultToolCacheRoot ) ;
72
+
73
+ // remove cruft from incomplete installs
74
+ await io . rmRF ( defaultToolCacheDir ) ;
75
+
76
+ // link to actual tool cache directory
77
+ fs . mkdirSync ( path . dirname ( defaultToolCacheDir ) , { recursive : true } ) ;
78
+ fs . symlinkSync ( actualToolCacheDir , defaultToolCacheDir , 'junction' ) ;
79
+
80
+ // .complete file is required for github actions to make the cacheDir persistent
81
+ const actualToolCacheCompleteFile = `${ actualToolCacheDir } .complete` ;
82
+ const defaultToolCacheCompleteFile = `${ defaultToolCacheDir } .complete` ;
83
+ await io . rmRF ( defaultToolCacheCompleteFile ) ;
84
+ fs . symlinkSync ( actualToolCacheCompleteFile , defaultToolCacheCompleteFile , 'file' ) ;
85
+
86
+ return actualToolCacheDir ;
87
+ } finally {
88
+ process . env [ 'RUNNER_TOOL_CACHE' ] = defaultToolCacheRoot ;
89
+ }
73
90
}
74
91
75
- async function defaultToolpath ( release : Release , platform : string ) : Promise < string > {
92
+ async function makeDefaultToolpath ( release : Release ) : Promise < string > {
76
93
fs . writeFileSync ( ".keep" , "" ) ;
77
94
let toolpath = await tc . cacheFile ( ".keep" , ".keep" , "MATLAB" , release . version ) ;
78
- io . rmRF ( ".keep" ) ;
79
- if ( platform == "darwin" ) {
80
- toolpath = toolpath + "/MATLAB.app" ;
81
- }
95
+ await io . rmRF ( ".keep" ) ;
82
96
return toolpath
83
97
}
84
98
@@ -199,7 +213,7 @@ export async function installSystemDependencies(platform: string, architecture:
199
213
200
214
async function installAppleSiliconJdk ( ) {
201
215
const jdkPath = path . join ( process . env [ "RUNNER_TEMP" ] ?? "" , "jdk.pkg" ) ;
202
- io . rmRF ( jdkPath ) ;
216
+ await io . rmRF ( jdkPath ) ;
203
217
const jdk = await tc . downloadTool ( properties . appleSiliconJdkUrl , jdkPath ) ;
204
218
const exitCode = await exec . exec ( `sudo installer -pkg "${ jdk } " -target /` ) ;
205
219
if ( exitCode !== 0 ) {
0 commit comments