From d919a375b38e926f967b8a8c5dac855502c3ac02 Mon Sep 17 00:00:00 2001 From: Shamil Mubarakshin <127750046+shamil-mubarakshin@users.noreply.github.com> Date: Thu, 30 Nov 2023 17:37:37 +0100 Subject: [PATCH] Add PR_HEAD_REF env variable to ci-cleanup.yml (#8916) * Add PR_HEAD_REF env variable to ci-cleanup.yml * Fix quotes around env var --- .github/workflows/ci-cleanup.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-cleanup.yml b/.github/workflows/ci-cleanup.yml index 3b532e4cc..8b9a94f8d 100644 --- a/.github/workflows/ci-cleanup.yml +++ b/.github/workflows/ci-cleanup.yml @@ -14,6 +14,7 @@ jobs: steps: - env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR_HEAD_REF: ${{ github.event.pull_request.head.ref }} shell: pwsh run: | $startDate = Get-Date -UFormat %s @@ -21,13 +22,13 @@ jobs: while ($true) { $continue = $false foreach ($wf in $workflows) { - $skippedCommand = "gh run list --workflow ${wf}.yml --branch ${{ github.event.pull_request.head.ref }} --repo ${{ github.repository }} --status skipped --json databaseId" + $skippedCommand = "gh run list --workflow ${wf}.yml --branch '$env:PR_HEAD_REF' --repo ${{ github.repository }} --status skipped --json databaseId" $skippedIds = Invoke-Expression -Command $skippedCommand | ConvertFrom-Json | ForEach-Object { $_.databaseId } $skippedIds | ForEach-Object { $deleteCommand = "gh run delete --repo ${{ github.repository }} $_" Invoke-Expression -Command $deleteCommand } - $pendingCommand = "gh run list --workflow ${wf}.yml --branch ${{ github.event.pull_request.head.ref }} --repo ${{ github.repository }} --status requested --json databaseId --template '{{ . | len }}'" + $pendingCommand = "gh run list --workflow ${wf}.yml --branch '$env:PR_HEAD_REF' --repo ${{ github.repository }} --status requested --json databaseId --template '{{ . | len }}'" $pending = Invoke-Expression -Command $pendingCommand if ($pending -gt 0) { Write-Host "Pending for ${wf}.yml: $pending run(s)"