1
- import * as core from '@actions/core'
1
+ import { ICore } from './src/core'
2
+ import { ActionsCore } from './src/actions_core'
2
3
import { mkdirp } from './src/downloader'
3
4
import { restoreCache , saveCache } from '@actions/cache'
4
5
import process from 'process'
@@ -11,9 +12,6 @@ import {
11
12
import { getViaCIArtifacts } from './src/ci_artifacts'
12
13
import * as fs from 'fs'
13
14
14
- const flavor = core . getInput ( 'flavor' )
15
- const architecture = core . getInput ( 'architecture' )
16
-
17
15
/**
18
16
* Some Azure VM types have a temporary disk which is local to the VM and therefore provides
19
17
* _much_ faster disk IO than the OS Disk (or any other attached disk).
@@ -23,7 +21,7 @@ const architecture = core.getInput('architecture')
23
21
*
24
22
* https://learn.microsoft.com/en-us/azure/virtual-machines/managed-disks-overview#temporary-disk
25
23
*/
26
- function getDriveLetterPrefix ( ) : string {
24
+ function getDriveLetterPrefix ( core : ICore ) : string {
27
25
if ( fs . existsSync ( 'D:/' ) ) {
28
26
core . info ( 'Found a fast, temporary disk on this VM (D:/). Will use that.' )
29
27
return 'D:/'
@@ -32,7 +30,11 @@ function getDriveLetterPrefix(): string {
32
30
return 'C:/'
33
31
}
34
32
35
- async function run ( ) : Promise < void > {
33
+ async function setup (
34
+ core : ICore ,
35
+ flavor : string ,
36
+ architecture : string
37
+ ) : Promise < void > {
36
38
try {
37
39
if ( process . platform !== 'win32' ) {
38
40
core . warning (
@@ -47,10 +49,10 @@ async function run(): Promise<void> {
47
49
48
50
const { artifactName, download, id} =
49
51
flavor === 'minimal'
50
- ? await getViaCIArtifacts ( architecture , githubToken )
51
- : await getViaGit ( flavor , architecture , githubToken )
52
+ ? await getViaCIArtifacts ( core , architecture , githubToken )
53
+ : await getViaGit ( core , flavor , architecture , githubToken )
52
54
const outputDirectory =
53
- core . getInput ( 'path' ) || `${ getDriveLetterPrefix ( ) } ${ artifactName } `
55
+ core . getInput ( 'path' ) || `${ getDriveLetterPrefix ( core ) } ${ artifactName } `
54
56
core . setOutput ( 'result' , outputDirectory )
55
57
56
58
let useCache : boolean
@@ -158,7 +160,7 @@ async function run(): Promise<void> {
158
160
}
159
161
}
160
162
161
- function cleanup ( ) : void {
163
+ function cleanup ( core : ICore , flavor : string , architecture : string ) : void {
162
164
if ( core . getInput ( 'cleanup' ) !== 'true' ) {
163
165
core . info (
164
166
`Won't clean up SDK files as the 'cleanup' input was not provided or doesn't equal 'true'.`
@@ -168,7 +170,7 @@ function cleanup(): void {
168
170
169
171
const outputDirectory =
170
172
core . getInput ( 'path' ) ||
171
- `${ getDriveLetterPrefix ( ) } ${
173
+ `${ getDriveLetterPrefix ( core ) } ${
172
174
getArtifactMetadata ( flavor , architecture ) . artifactName
173
175
} `
174
176
@@ -203,20 +205,22 @@ function cleanup(): void {
203
205
core . info ( `Finished cleaning up ${ outputDirectory } .` )
204
206
}
205
207
206
- /**
207
- * Indicates whether the POST action is running
208
- */
209
- export const isPost = ! ! core . getState ( 'isPost' )
210
-
211
- if ( ! isPost ) {
212
- run ( )
213
- /*
214
- * Publish a variable so that when the POST action runs, it can determine it should run the cleanup logic .
215
- * This is necessary since we don't have a separate entry point.
216
- * Inspired by https://github.com/actions/checkout/blob/v3.1.0/src/state-helper.ts#L56-L60
217
- */
218
- core . saveState ( 'isPost' , 'true' )
219
- } else {
220
- // If the POST action is running, we cleanup our artifacts
221
- cleanup ( )
208
+ async function run ( core : ICore ) : Promise < void > {
209
+ const flavor = core . getInput ( 'flavor' )
210
+ const architecture = core . getInput ( 'architecture' )
211
+ const isPost = ! ! core . getState ( 'isPost' )
212
+ if ( ! isPost ) {
213
+ setup ( core , flavor , architecture )
214
+ /*
215
+ * Publish a variable so that when the POST action runs, it can determine it should run the cleanup logic.
216
+ * This is necessary since we don't have a separate entry point .
217
+ * Inspired by https://github.com/actions/checkout/blob/v3.1.0/src/state-helper.ts#L56-L60
218
+ */
219
+ core . saveState ( 'isPost' , 'true' )
220
+ } else {
221
+ // If the POST action is running, we cleanup our artifacts
222
+ cleanup ( core , flavor , architecture )
223
+ }
222
224
}
225
+
226
+ run ( new ActionsCore ( ) )
0 commit comments