-
Notifications
You must be signed in to change notification settings - Fork 1
57 lines (55 loc) · 1.89 KB
/
github-cleanup.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
name: GitHub Cleaner
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
GITHUB_REPOSITORY: ${{ secrets.GITHUB_REPOSITORY }}
on:
workflow_call:
secrets:
GH_TOKEN:
required: true
inputs:
GITHUB_REPOSITORY:
required: false
default: ${{ github.repository }}
type: string
RELEASE_CLEANUP_PATTERN:
required: false
default: '[\s\S]*'
type: string
jobs:
release-cleanup:
name: GitHub Cleanup
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
- name: Delete Older Releases
uses: nikhilbadyal/[email protected]
with:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
RELEASE_PATTERN: ${{ inputs.RELEASE_CLEANUP_PATTERN }}
#https://github.com/orgs/community/discussions/8488
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