Skip to content

Commit

Permalink
fix cleanup by including all required data for github releases
Browse files Browse the repository at this point in the history
  • Loading branch information
VJftw committed Oct 13, 2023
1 parent a680280 commit add69c3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ jobs:
fail-fast: false
matrix:
flavour:
# - arch:xfce4
- arch:xfce4
- debian:xfce4
# - debian/kali:xfce4
- debian/kali:xfce4

name: ${{ matrix.flavour }}
runs-on: ubuntu-latest
Expand Down
34 changes: 20 additions & 14 deletions build/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,36 @@ for csv_instance in "${all_csv_instances[@]}"; do
done

## only keep last 10 releases
mapfile -t all_github_release_ids < \
<(curl --silent -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/${github_repository}/releases" | jq -r '.[] | ( .name + "," + (.id|tostring) )')
mapfile -t all_github_releases < \
<(
curl --silent -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/${github_repository}/releases" \
| jq -r '.[] | ( (.id|tostring) + "," + .name + "," + .body | gsub("[\\n]"; ":") )' \
| sort -u
)

printf "found %d release(s).\n" "${#all_github_releases[@]}"

mapfile -t releases_to_delete < \
<(printf "%s\n" "${all_github_release_ids[@]}" | tail -n +11)
<(printf "%s\n" "${all_github_releases[@]}" | tail -n +10)

if (( ${#releases_to_delete[@]} )); then
printf "deleting ${#releases_to_delete[@]} releases.\n"


for release_id in "${releases_to_delete[@]}"; do
release="$(echo "$release_id" | cut -f1 -d",")"
id="$(echo "$release_id" | cut -f2 -d",")"
for id_release_body in "${releases_to_delete[@]}"; do
id="$(echo "$id_release_body" | cut -f1 -d",")"
echo "DELETE https://api.github.com/repos/${github_repository}/releases/$id"
# curl --silent -L \
# -X DELETE \
# -H "Accept: application/vnd.github+json" \
# -H "Authorization: Bearer $GITHUB_TOKEN" \
# -H "X-GitHub-Api-Version: 2022-11-28" \
# "https://api.github.com/repos/${github_repository}/releases/$id"
curl --silent -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/${github_repository}/releases/$id"
done
else
echo "no releases to delete"
fi

exit 1
## delete images not associated with a release

all_csv_images=($(gcloud --project "${gcp_project}" compute images list --no-standard-images --format="csv(name, creationTimestamp)" | tail -n+2))
Expand Down Expand Up @@ -80,7 +86,7 @@ git fetch --tags --prune --prune-tags
all_git_tags=($(git tag))

for git_tag in "${all_git_tags[@]}"; do
if [[ "${all_github_release_ids[@]}" != *"${git_tag}"* ]]; then
if [[ "${all_github_releases[@]}" != *"${git_tag}"* ]]; then
printf "deleting tag '%s'.\n" "${git_tag}"
git tag -d "${git_tag}"
git push --delete origin "${git_tag}"
Expand Down

0 comments on commit add69c3

Please sign in to comment.