From 96f3a5afab061cfa1235922f712720259e6a0f7b Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Fri, 6 May 2022 17:32:30 +0300 Subject: [PATCH] Add a cleanup job to backport workflow (#68596) * Add a cleanup job to backport workflow * Add once a day schedule * Pass GH token to the job --- .github/workflows/backport.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index a9d20ab..9ddb513 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -2,6 +2,9 @@ name: Backport PR to branch on: issue_comment: types: [created] + schedule: + # once a day at 13:00 UTC + - cron: '0 13 * * *' permissions: contents: write @@ -9,6 +12,22 @@ permissions: pull-requests: write jobs: + cleanup_old_runs: + if: github.event.schedule == '0 13 * * *' + runs-on: ubuntu-20.04 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: Delete old workflow runs + run: | + _UrlPath="/repos/$GITHUB_REPOSITORY/actions/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' \ + | xargs -I{} gh api -X DELETE "$_UrlPath"/{} + backport: if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/backport to') runs-on: ubuntu-20.04 -- 2.7.4