From ddfcf070c8516588b60594437c4a1fbf1abe4a94 Mon Sep 17 00:00:00 2001 From: Daniel Donenfeld Date: Fri, 15 Feb 2019 11:51:34 -0800 Subject: [PATCH] Only delete asm branches if it is the last build --- appveyor.yml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index ba8f620..7f0ff22 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -160,19 +160,22 @@ deploy_script: on_finish: - ps: | - # Delete all branches for asm if(-not (Test-Path env:APPVEYOR_PULL_REQUEST_NUMBER)) { + # Delete all branches for asm if this is the last build $build = Invoke-RestMethod -Uri "https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG" -Method GET -Headers @{ "Authorization" = "Bearer $env:APPVEYOR_API_TOKEN" "Content-type" = "application/json" } - $build.build.jobs | Foreach-Object { - $branchName = "asm/$($env:APPVEYOR_REPO_COMMIT)/appveyor-$($_.jobId)" - git ls-remote --heads --exit-code https://github.com/dadonenf/GSL.git $branchName - if($?){ - git push origin --delete asm/$($env:APPVEYOR_REPO_COMMIT)/appveyor-$($_.jobId) + $jobs = $buildData.build.jobs + $lastJob = ($jobs | Select-Object -Last 1).jobId + + if ($lastJob -eq $env:APPVEYOR_JOB_ID) { + $jobs | Foreach-Object { + $branchName = "asm/$($env:APPVEYOR_REPO_COMMIT)/appveyor-$($_.jobId)" + git ls-remote --heads --exit-code https://github.com/dadonenf/GSL.git $branchName + if($?){ + git push origin --delete asm/$($env:APPVEYOR_REPO_COMMIT)/appveyor-$($_.jobId) + } } } } - -