@@ -195,59 +195,62 @@ async function run(): Promise<void> {
195195 token,
196196 } ;
197197
198- info ( "> Waiting for the status checks to pass..." ) ;
199- const [ statusOnTemp , waitForChecksError ] = await to (
200- waitForCheckSuites ( temporaryBranchInformation , {
201- intervalSeconds,
202- timeoutSeconds,
203- } )
204- ) ;
205- if ( waitForChecksError ) {
206- errorHandler (
207- `Error while waiting on status checks on temporary branch ${ temporaryBranch } . Aborting.` ,
208- waitForChecksError
198+ // Now that the temporary branch is pushed, we want to delete that branch even if the next steps fails.
199+ try {
200+ info ( "> Waiting for the status checks to pass..." ) ;
201+ const [ statusOnTemp , waitForChecksError ] = await to (
202+ waitForCheckSuites ( temporaryBranchInformation , {
203+ intervalSeconds,
204+ timeoutSeconds,
205+ } )
209206 ) ;
210- return ;
211- }
212- const passedOnTemp = statusOnTemp . every (
213- ( status ) => status . conclusion !== "success"
214- ) ;
215- if ( ! passedOnTemp ) {
216- setFailed (
217- `> The status checks did not pass on the temporary branch. Aborting.`
207+ if ( waitForChecksError ) {
208+ errorHandler (
209+ `Error while waiting on status checks on temporary branch ${ temporaryBranch } . Aborting.` ,
210+ waitForChecksError
211+ ) ;
212+ return ;
213+ }
214+ const passedOnTemp = statusOnTemp . every (
215+ ( status ) => status . conclusion !== "success"
218216 ) ;
219- return ;
220- }
217+ if ( ! passedOnTemp ) {
218+ setFailed (
219+ `> The status checks did not pass on the temporary branch. Aborting.`
220+ ) ;
221+ return ;
222+ }
221223
222- info ( `> The status checks passed!` ) ;
223- info ( `> Pushing ${ temporaryBranch } --> origin/${ branchToPushTo } ...` ) ;
224- const [ , secondCheckoutError ] = await to ( git . checkout ( branchToPushTo ) ) ;
225- if ( secondCheckoutError ) {
226- errorHandler (
227- `Could not checkout branch ${ branchToPushTo } . Aborting.` ,
228- secondCheckoutError
229- ) ;
230- return ;
231- }
232- const [ , resetError ] = await to ( git . reset ( [ "--hard" , temporaryBranch ] ) ) ;
233- if ( resetError ) {
234- errorHandler (
235- `Could not reset branch ${ branchToPushTo } to temporary branch ${ temporaryBranch } . Aborting.` ,
236- resetError
237- ) ;
238- return ;
239- }
240- const [ , secondPushError ] = await to ( git . push ( ) ) ;
241- if ( secondPushError ) {
242- errorHandler (
243- `Could not push branch ${ branchToPushTo } to remote. Aborting.` ,
244- secondPushError
245- ) ;
246- return ;
224+ info ( `> The status checks passed!` ) ;
225+ info ( `> Pushing ${ temporaryBranch } --> origin/${ branchToPushTo } ...` ) ;
226+ const [ , secondCheckoutError ] = await to ( git . checkout ( branchToPushTo ) ) ;
227+ if ( secondCheckoutError ) {
228+ errorHandler (
229+ `Could not checkout branch ${ branchToPushTo } . Aborting.` ,
230+ secondCheckoutError
231+ ) ;
232+ return ;
233+ }
234+ const [ , resetError ] = await to ( git . reset ( [ "--hard" , temporaryBranch ] ) ) ;
235+ if ( resetError ) {
236+ errorHandler (
237+ `Could not reset branch ${ branchToPushTo } to temporary branch ${ temporaryBranch } . Aborting.` ,
238+ resetError
239+ ) ;
240+ return ;
241+ }
242+ const [ , secondPushError ] = await to ( git . push ( ) ) ;
243+ if ( secondPushError ) {
244+ errorHandler (
245+ `Could not push branch ${ branchToPushTo } to remote. Aborting.` ,
246+ secondPushError
247+ ) ;
248+ return ;
249+ }
250+ } finally {
251+ info ( `> Deleting ${ temporaryBranch } ...` ) ;
252+ await deleteRemoteBranch ( temporaryBranchInformation ) ;
247253 }
248-
249- info ( `> Deleting ${ temporaryBranch } ...` ) ;
250- await deleteRemoteBranch ( temporaryBranchInformation ) ;
251254 } else {
252255 setFailed ( `> The remote branch does not require status checks.` ) ;
253256 info (
0 commit comments