1
1
import * as core from '@actions/core'
2
- import { ChildProcess , spawn } from 'child_process '
2
+ import { spawnAndWaitForExitCode , SpawnReturnArgs } from './spawn '
3
3
import { Octokit } from '@octokit/rest'
4
4
import { delimiter } from 'path'
5
5
import * as fs from 'fs'
@@ -48,14 +48,14 @@ export function getArtifactMetadata(
48
48
return { repo, artifactName}
49
49
}
50
50
51
- async function clone (
51
+ export async function clone (
52
52
url : string ,
53
53
destination : string ,
54
54
verbose : number | boolean ,
55
55
cloneExtraOptions : string [ ] = [ ]
56
56
) : Promise < void > {
57
57
if ( verbose ) core . info ( `Cloning ${ url } to ${ destination } ` )
58
- const child = spawn (
58
+ const child = await spawnAndWaitForExitCode (
59
59
gitExePath ,
60
60
[
61
61
'clone' ,
@@ -69,44 +69,30 @@ async function clone(
69
69
{
70
70
env : {
71
71
GIT_CONFIG_PARAMETERS
72
- } ,
73
- stdio : [ undefined , 'inherit' , 'inherit' ]
72
+ }
74
73
}
75
74
)
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
+ }
85
78
}
86
79
87
80
async function updateHEAD (
88
81
bareRepositoryPath : string ,
89
82
headSHA : string
90
83
) : Promise < void > {
91
- const child = spawn (
84
+ const child = await spawnAndWaitForExitCode (
92
85
gitExePath ,
93
86
[ '--git-dir' , bareRepositoryPath , 'update-ref' , 'HEAD' , headSHA ] ,
94
87
{
95
88
env : {
96
89
GIT_CONFIG_PARAMETERS
97
- } ,
98
- stdio : [ undefined , 'inherit' , 'inherit' ]
90
+ }
99
91
}
100
92
)
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
+ }
110
96
}
111
97
112
98
export async function getViaGit (
@@ -175,17 +161,16 @@ export async function getViaGit(
175
161
] )
176
162
core . endGroup ( )
177
163
178
- let child : ChildProcess
164
+ let child : SpawnReturnArgs
179
165
if ( flavor === 'full' ) {
180
166
core . startGroup ( `Checking out ${ repo } ` )
181
- child = spawn (
167
+ child = await spawnAndWaitForExitCode (
182
168
gitExePath ,
183
169
[ `--git-dir=.tmp` , 'worktree' , 'add' , outputDirectory , head_sha ] ,
184
170
{
185
171
env : {
186
172
GIT_CONFIG_PARAMETERS
187
- } ,
188
- stdio : [ undefined , 'inherit' , 'inherit' ]
173
+ }
189
174
}
190
175
)
191
176
} else {
@@ -200,7 +185,7 @@ export async function getViaGit(
200
185
201
186
core . startGroup ( `Creating ${ flavor } artifact` )
202
187
const traceArg = verbose ? [ '-x' ] : [ ]
203
- child = spawn (
188
+ child = await spawnAndWaitForExitCode (
204
189
`${ gitForWindowsUsrBinPath } /bash.exe` ,
205
190
[
206
191
...traceArg ,
@@ -221,21 +206,16 @@ export async function getViaGit(
221
206
CHERE_INVOKING : '1' ,
222
207
MSYSTEM : 'MINGW64' ,
223
208
PATH : `${ gitForWindowsBinPaths . join ( delimiter ) } ${ delimiter } ${ process . env . PATH } `
224
- } ,
225
- stdio : [ undefined , 'inherit' , 'inherit' ]
209
+ }
226
210
}
227
211
)
228
212
}
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
+ }
239
219
}
240
220
}
241
221
}
0 commit comments