11import * as core from '@actions/core'
2- import { ChildProcess , spawn } from 'child_process '
2+ import { spawnAndWaitForExitCode , SpawnReturnArgs } from './spawn '
33import { Octokit } from '@octokit/rest'
44import { delimiter } from 'path'
55import * as fs from 'fs'
@@ -48,14 +48,14 @@ export function getArtifactMetadata(
4848 return { repo, artifactName}
4949}
5050
51- async function clone (
51+ export async function clone (
5252 url : string ,
5353 destination : string ,
5454 verbose : number | boolean ,
5555 cloneExtraOptions : string [ ] = [ ]
5656) : Promise < void > {
5757 if ( verbose ) core . info ( `Cloning ${ url } to ${ destination } ` )
58- const child = spawn (
58+ const child = await spawnAndWaitForExitCode (
5959 gitExePath ,
6060 [
6161 'clone' ,
@@ -69,44 +69,30 @@ async function clone(
6969 {
7070 env : {
7171 GIT_CONFIG_PARAMETERS
72- } ,
73- stdio : [ undefined , 'inherit' , 'inherit' ]
72+ }
7473 }
7574 )
76- return new Promise < void > ( ( resolve , reject ) => {
77- child . on ( 'close' , code => {
78- if ( code === 0 ) {
79- resolve ( )
80- } else {
81- reject ( new Error ( `git clone: exited with code ${ code } ` ) )
82- }
83- } )
84- } )
75+ if ( child . exitCode !== 0 ) {
76+ throw new Error ( `git clone: exited with code ${ child . exitCode } ` )
77+ }
8578}
8679
8780async function updateHEAD (
8881 bareRepositoryPath : string ,
8982 headSHA : string
9083) : Promise < void > {
91- const child = spawn (
84+ const child = await spawnAndWaitForExitCode (
9285 gitExePath ,
9386 [ '--git-dir' , bareRepositoryPath , 'update-ref' , 'HEAD' , headSHA ] ,
9487 {
9588 env : {
9689 GIT_CONFIG_PARAMETERS
97- } ,
98- stdio : [ undefined , 'inherit' , 'inherit' ]
90+ }
9991 }
10092 )
101- return new Promise < void > ( ( resolve , reject ) => {
102- child . on ( 'close' , code => {
103- if ( code === 0 ) {
104- resolve ( )
105- } else {
106- reject ( new Error ( `git: exited with code ${ code } ` ) )
107- }
108- } )
109- } )
93+ if ( child . exitCode !== 0 ) {
94+ throw new Error ( `git: exited with code ${ child . exitCode } ` )
95+ }
11096}
11197
11298export async function getViaGit (
@@ -175,17 +161,16 @@ export async function getViaGit(
175161 ] )
176162 core . endGroup ( )
177163
178- let child : ChildProcess
164+ let child : SpawnReturnArgs
179165 if ( flavor === 'full' ) {
180166 core . startGroup ( `Checking out ${ repo } ` )
181- child = spawn (
167+ child = await spawnAndWaitForExitCode (
182168 gitExePath ,
183169 [ `--git-dir=.tmp` , 'worktree' , 'add' , outputDirectory , head_sha ] ,
184170 {
185171 env : {
186172 GIT_CONFIG_PARAMETERS
187- } ,
188- stdio : [ undefined , 'inherit' , 'inherit' ]
173+ }
189174 }
190175 )
191176 } else {
@@ -200,7 +185,7 @@ export async function getViaGit(
200185
201186 core . startGroup ( `Creating ${ flavor } artifact` )
202187 const traceArg = verbose ? [ '-x' ] : [ ]
203- child = spawn (
188+ child = await spawnAndWaitForExitCode (
204189 `${ gitForWindowsUsrBinPath } /bash.exe` ,
205190 [
206191 ...traceArg ,
@@ -221,21 +206,16 @@ export async function getViaGit(
221206 CHERE_INVOKING : '1' ,
222207 MSYSTEM : 'MINGW64' ,
223208 PATH : `${ gitForWindowsBinPaths . join ( delimiter ) } ${ delimiter } ${ process . env . PATH } `
224- } ,
225- stdio : [ undefined , 'inherit' , 'inherit' ]
209+ }
226210 }
227211 )
228212 }
229- return new Promise < void > ( ( resolve , reject ) => {
230- child . on ( 'close' , code => {
231- core . endGroup ( )
232- if ( code === 0 ) {
233- fs . rm ( '.tmp' , { recursive : true } , ( ) => resolve ( ) )
234- } else {
235- reject ( new Error ( `process exited with code ${ code } ` ) )
236- }
237- } )
238- } )
213+ core . endGroup ( )
214+ if ( child . exitCode === 0 ) {
215+ fs . rmSync ( '.tmp' , { recursive : true } )
216+ } else {
217+ throw new Error ( `process exited with code ${ child . exitCode } ` )
218+ }
239219 }
240220 }
241221}
0 commit comments