-
Notifications
You must be signed in to change notification settings - Fork 7
60 lines (47 loc) · 2.4 KB
/
delete_old.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
58
59
60
name: Delete Old Build Artifacts
on:
workflow_dispatch:
push:
schedule:
- cron: "0 21 * * *"
jobs:
get_and_delete_old_run_ids:
runs-on: ubuntu-latest
permissions:
actions: write
steps:
- name: Get old run IDs
run: |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "OLD_IDS<<$EOF" >> "$GITHUB_ENV"
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository_owner }}/${{ github.event.repository.name }}/actions/runs \
| jq -r '.workflow_runs[] | select(.created_at < "'$(date -d "-7 day" +%Y-%m-%dT%H:%M:%SZ)'") | .id' >> "$GITHUB_ENV"
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository_owner }}/${{ github.event.repository.name }}/actions/runs \
| jq -r '.workflow_runs[] | select(.name == "Delete Old Build Artifacts") | .id' >> "$GITHUB_ENV"
echo "$EOF" >> "$GITHUB_ENV"
- name: Delete old run IDs
run: |
echo $OLD_IDS | while read -d ' ' -r id || [[ -n ${id} ]]; do
curl -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository_owner }}/${{ github.event.repository.name }}/actions/runs/$id
echo "Delete run id: $id"
done
# curl -L \
# -X DELETE \
# -H "Accept: application/vnd.github+json" \
# -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}"\
# -H "X-GitHub-Api-Version: 2022-11-28" \
# https://api.github.com/repos/${{ github.repository_owner }}/${{ github.event.repository.name }}/actions/runs/RUN_ID
# curl -X GET -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/Roarcannotprogramming/openwrt_workflow/actions/runs | jq -r '.workflow_runs[] | select(.created_at < "'$(date -d "-7 day" +%Y-%m-%dT%H:%M:%SZ)'") | .id'