-
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathclearRelease.sh
More file actions
41 lines (32 loc) · 1.4 KB
/
clearRelease.sh
File metadata and controls
41 lines (32 loc) · 1.4 KB
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
#!/usr/bin/env bash
set -e
echo "=== Fetching all releases ==="
curl -sSf -H "Authorization: Bearer $GITHUB_TOKEN" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/releases" | jq -r '.[] | "\(.id)\t\(.tag_name)"'
echo "=== Getting nightly releases ==="
old_releases=$(curl -sSf -H "Authorization: Bearer $GITHUB_TOKEN" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/releases" | \
jq -r '.[] | select(.tag_name | startswith("nightly-")) | "\(.id)\t\(.tag_name)"')
if [ -z "$old_releases" ]; then
echo "No nightly releases found. Exiting."
exit 0
fi
echo "=== Looping through nightly releases ==="
echo "$old_releases" | while IFS=$'\t' read -r release_id tag_name; do
echo "Preparing to delete release: ID=$release_id, Tag=$tag_name"
# Check release URL
release_url="https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/${release_id}"
echo "Release URL: $release_url"
curl -v -H "Authorization: Bearer $GITHUB_TOKEN" "$release_url"
# Delete release
echo "Deleting release..."
curl -v -sSf -H "Authorization: Bearer $GITHUB_TOKEN" -X DELETE "$release_url"
# Check tag URL
tag_url="https://api.github.com/repos/${GITHUB_REPOSITORY}/git/refs/tags/${tag_name}"
echo "Tag URL: $tag_url"
curl -v -H "Authorization: Bearer $GITHUB_TOKEN" "$tag_url"
# Delete tag
echo "Deleting tag..."
curl -v -sSf -H "Authorization: Bearer $GITHUB_TOKEN" -X DELETE "$tag_url"
echo "---"
done