Use a better endpoint for backport workflows runs (#69617)
authorAdeel Mujahid <3840695+am11@users.noreply.github.com>
Mon, 23 May 2022 15:31:52 +0000 (18:31 +0300)
committerGitHub <noreply@github.com>
Mon, 23 May 2022 15:31:52 +0000 (17:31 +0200)
.github/workflows/backport.yml

index 3f7a3dd..68b18cf 100644 (file)
@@ -22,12 +22,16 @@ jobs:
     steps:
     - name: Delete old workflow runs
       run: |
-        _UrlPath="/repos/$GITHUB_REPOSITORY/actions/runs"
+        _UrlPath="/repos/$GITHUB_REPOSITORY/actions/workflows"
+
+        _CurrentWorkflowID="$(gh api -X GET "$_UrlPath" | jq '.workflows[] | select(.name == '\""$GITHUB_WORKFLOW"\"') | .id')"
+
+        _UrlPath="$_UrlPath/$_CurrentWorkflowID/runs"
 
         # delete workitems which are 'completed'. (other candidate values of status field are: 'queued' and 'in_progress')
 
         gh api -X GET "$_UrlPath" --paginate \
-          | jq '.workflow_runs[] | select(.name == '\""$GITHUB_WORKFLOW"\"' and .status == "completed") | .id' \
+          | jq '.workflow_runs[] | select(.status == "completed") | .id' \
           | xargs -I{} gh api -X DELETE "$_UrlPath"/{}
 
   backport: