From 62e7fe2a2796031681ef2c9e775dfe1b3b525cb9 Mon Sep 17 00:00:00 2001 From: Patrick Armstrong Date: Fri, 19 Jul 2024 21:32:42 +1000 Subject: [PATCH] Create cancel_workflow_runs.yml --- .github/workflows/cancel_workflow_runs.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/workflows/cancel_workflow_runs.yml diff --git a/.github/workflows/cancel_workflow_runs.yml b/.github/workflows/cancel_workflow_runs.yml new file mode 100644 index 0000000..4b6e472 --- /dev/null +++ b/.github/workflows/cancel_workflow_runs.yml @@ -0,0 +1,19 @@ +name: Delete branch +on: delete +jobs: + delete_workflow_runs: + runs-on: ubuntu-latest + steps: + - name: Delete workflow runs for deleted branch + id: delete-workflow-runs-for-deleted-branch + if: github.event.ref_type == 'branch' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_BRANCH: ${{ github.event.ref }} + GITHUB_REPOSITORY_URL: ${{ github.event.repository.url }} + run: | + echo "Deleting workflow runs for deleted branch ${GITHUB_BRANCH}" + for id in $(curl -s -H "Authorization: Bearer ${GITHUB_TOKEN}" ${GITHUB_REPOSITORY_URL}/actions/runs?branch=${GITHUB_BRANCH} | jq '.workflow_runs | .[] | .id'); do + curl -s -X DELETE -H "Authorization: Bearer ${GITHUB_TOKEN}" ${GITHUB_REPOSITORY_URL}/actions/runs/${id} + echo "Deleted workflow run ${id}" + done