Skip to content

Commit f9455ee

Browse files
Extract nightly release cleanup to a shell script
This commit refactors the nightly release process by extracting the cleanup logic from the GitHub Actions workflow into a dedicated `clearRelease.sh` script. This improves the modularity and readability of the CI configuration. The new script `clearRelease.sh` is responsible for: - Fetching all existing releases from the GitHub repository. - Filtering for releases with tags starting with "nightly-". - Iterating through the identified nightly releases and deleting both the release and its associated git tag. - Adding more detailed logging for debugging purposes. The `nightly-release.yml` workflow is updated to execute this new script, replacing the previous inline shell commands.
1 parent 73f3e1d commit f9455ee

File tree

2 files changed

+43
-16
lines changed

2 files changed

+43
-16
lines changed

.github/workflows/nightly-release.yml

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,8 @@ jobs:
1919
- name: Delete existing nightly release
2020
env:
2121
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22-
run: |
23-
old_releases=$(curl -sSf -H "Authorization: Bearer $GITHUB_TOKEN" \
24-
"https://api.github.com/repos/${GITHUB_REPOSITORY}/releases" | jq -r '.[] | select(.tag_name | startswith("nightly-")) | .id + " " + .tag_name')
25-
26-
for release in $old_releases; do
27-
release_id=$(echo $release | cut -d' ' -f1)
28-
tag_name=$(echo $release | cut -d' ' -f2)
29-
30-
# Delete release
31-
curl -sSf -H "Authorization: Bearer $GITHUB_TOKEN" \
32-
-X DELETE "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/${release_id}"
33-
34-
# Delete tag
35-
curl -sSf -H "Authorization: Bearer $GITHUB_TOKEN" \
36-
-X DELETE "https://api.github.com/repos/${GITHUB_REPOSITORY}/git/refs/tags/${tag_name}"
37-
done
22+
run: bash clearRelease.sh
23+
3824

3925
build:
4026
name: Build, Sign & Release

clearRelease.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
echo "=== Fetching all releases ==="
5+
curl -sSf -H "Authorization: Bearer $GITHUB_TOKEN" \
6+
"https://api.github.com/repos/${GITHUB_REPOSITORY}/releases" | jq -r '.[] | "\(.id)\t\(.tag_name)"'
7+
8+
echo "=== Getting nightly releases ==="
9+
old_releases=$(curl -sSf -H "Authorization: Bearer $GITHUB_TOKEN" \
10+
"https://api.github.com/repos/${GITHUB_REPOSITORY}/releases" | \
11+
jq -r '.[] | select(.tag_name | startswith("nightly-")) | "\(.id)\t\(.tag_name)"')
12+
13+
if [ -z "$old_releases" ]; then
14+
echo "No nightly releases found. Exiting."
15+
exit 0
16+
fi
17+
18+
echo "=== Looping through nightly releases ==="
19+
echo "$old_releases" | while IFS=$'\t' read -r release_id tag_name; do
20+
echo "Preparing to delete release: ID=$release_id, Tag=$tag_name"
21+
22+
# Check release URL
23+
release_url="https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/${release_id}"
24+
echo "Release URL: $release_url"
25+
curl -v -H "Authorization: Bearer $GITHUB_TOKEN" "$release_url"
26+
27+
# Delete release
28+
echo "Deleting release..."
29+
curl -v -sSf -H "Authorization: Bearer $GITHUB_TOKEN" -X DELETE "$release_url"
30+
31+
# Check tag URL
32+
tag_url="https://api.github.com/repos/${GITHUB_REPOSITORY}/git/refs/tags/${tag_name}"
33+
echo "Tag URL: $tag_url"
34+
curl -v -H "Authorization: Bearer $GITHUB_TOKEN" "$tag_url"
35+
36+
# Delete tag
37+
echo "Deleting tag..."
38+
curl -v -sSf -H "Authorization: Bearer $GITHUB_TOKEN" -X DELETE "$tag_url"
39+
40+
echo "---"
41+
done

0 commit comments

Comments
 (0)