1- import * as core from '@actions/core'
1+ import { ICore } from './src/core'
2+ import { ActionsCore } from './src/actions_core'
23import { mkdirp } from './src/downloader'
34import { restoreCache , saveCache } from '@actions/cache'
45import process from 'process'
@@ -11,9 +12,6 @@ import {
1112import { getViaCIArtifacts } from './src/ci_artifacts'
1213import * as fs from 'fs'
1314
14- const flavor = core . getInput ( 'flavor' )
15- const architecture = core . getInput ( 'architecture' )
16-
1715/**
1816 * Some Azure VM types have a temporary disk which is local to the VM and therefore provides
1917 * _much_ faster disk IO than the OS Disk (or any other attached disk).
@@ -23,7 +21,7 @@ const architecture = core.getInput('architecture')
2321 *
2422 * https://learn.microsoft.com/en-us/azure/virtual-machines/managed-disks-overview#temporary-disk
2523 */
26- function getDriveLetterPrefix ( ) : string {
24+ function getDriveLetterPrefix ( core : ICore ) : string {
2725 if ( fs . existsSync ( 'D:/' ) ) {
2826 core . info ( 'Found a fast, temporary disk on this VM (D:/). Will use that.' )
2927 return 'D:/'
@@ -32,7 +30,11 @@ function getDriveLetterPrefix(): string {
3230 return 'C:/'
3331}
3432
35- async function run ( ) : Promise < void > {
33+ async function setup (
34+ core : ICore ,
35+ flavor : string ,
36+ architecture : string
37+ ) : Promise < void > {
3638 try {
3739 if ( process . platform !== 'win32' ) {
3840 core . warning (
@@ -47,10 +49,10 @@ async function run(): Promise<void> {
4749
4850 const { artifactName, download, id} =
4951 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 )
5254 const outputDirectory =
53- core . getInput ( 'path' ) || `${ getDriveLetterPrefix ( ) } ${ artifactName } `
55+ core . getInput ( 'path' ) || `${ getDriveLetterPrefix ( core ) } ${ artifactName } `
5456 core . setOutput ( 'result' , outputDirectory )
5557
5658 let useCache : boolean
@@ -158,7 +160,7 @@ async function run(): Promise<void> {
158160 }
159161}
160162
161- function cleanup ( ) : void {
163+ function cleanup ( core : ICore , flavor : string , architecture : string ) : void {
162164 if ( core . getInput ( 'cleanup' ) !== 'true' ) {
163165 core . info (
164166 `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 {
168170
169171 const outputDirectory =
170172 core . getInput ( 'path' ) ||
171- `${ getDriveLetterPrefix ( ) } ${
173+ `${ getDriveLetterPrefix ( core ) } ${
172174 getArtifactMetadata ( flavor , architecture ) . artifactName
173175 } `
174176
@@ -203,20 +205,22 @@ function cleanup(): void {
203205 core . info ( `Finished cleaning up ${ outputDirectory } .` )
204206}
205207
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+ }
222224}
225+
226+ run ( new ActionsCore ( ) )
0 commit comments