-
-
Notifications
You must be signed in to change notification settings - Fork 6
49 lines (48 loc) · 1.5 KB
/
delete_draft_releases.yaml
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
name: Delete draft releases
on:
delete
jobs:
delete:
name: Delete releases
runs-on: ubuntu-latest
steps:
- name: Get all releases as JSON
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
curl -H "Authorization: token $GITHUB_TOKEN" \
"$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases" -o releases.json
cat releases.json
- name: Find draft releases
run: |
python <<EOF
import json
import sys
with open('releases.json') as file:
releases = json.loads(file.read())
draft_releases = [release["id"] for release in releases if release["draft"]]
if not len(draft_releases) == 0:
with open('draft_releases', 'w') as file:
for id in draft_releases:
print(id)
file.write(f"{id}\n")
EOF
- name: Delete draft releases, if any
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
sh <<EOF
if test -f draft_releases
then :
else
echo 'draft_releases: file not found'
exit 0
fi
cat draft_releases | while read ID; do
echo "\$ID"
curl -H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
-X 'DELETE' \
"$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases/\$ID" 2>/dev/null
done
EOF