-
Notifications
You must be signed in to change notification settings - Fork 1
39 lines (37 loc) · 1.35 KB
/
github-workflow-cleaner.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
name: GitHub workflow cleaner
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
GITHUB_REPOSITORY: ${{ secrets.GITHUB_REPOSITORY }}
on:
workflow_call:
secrets:
GITHUB_REPOSITORY:
required: true
GH_TOKEN:
required: true
jobs:
workflow-cleanup:
name: RM Workflows
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
- name: Cleanup
run: |
workflow_ids=($(gh api repos/"$GITHUB_REPOSITORY"/actions/workflows | jq '.workflows[] | .id'))
for workflow_id in "${workflow_ids[@]}"
do
echo "Listing runs for the workflow ID $workflow_id"
run_ids=($(gh api repos/"$GITHUB_REPOSITORY"/actions/workflows/"$workflow_id"/runs?status=completed --paginate | jq '.workflow_runs[].id'))
for run_id in "${run_ids[@]}"
do
echo "Deleting Run ID $run_id"
gh api repos/"$GITHUB_REPOSITORY"/actions/runs/"$run_id" -X DELETE >/dev/null
done
done
echo "Deleting orphan workflows"
run_ids=($(gh api repos/"$GITHUB_REPOSITORY"/actions/runs?status=completed --paginate | jq '.workflow_runs[].id'))
for run_id in "${run_ids[@]}"
do
echo "Deleting Run ID $run_id"
gh api repos/"$GITHUB_REPOSITORY"/actions/runs/"$run_id" -X DELETE >/dev/null
done