Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 42 additions & 17 deletions .github/workflows/cleanup-temp-releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,33 +36,58 @@ jobs:

- name: Delete all temporary releases and tags for merged branch
run: |
PREFIX="temp-${SAFE_BRANCH}-v"
set -euo pipefail

echo "Looking for releases with prefix: $PREFIX"
PREFIX="temp-${SAFE_BRANCH}-v"

RELEASE_TAGS="$(
gh release list \
--limit 1000 \
--json tagName \
--jq '.[] | .tagName | select(test("^'"${PREFIX}"'[0-9]+$"))'
echo "Repository: ${GITHUB_REPOSITORY}"
echo "Looking for temp releases with prefix: ${PREFIX}"

gh api \
--paginate \
"repos/${GITHUB_REPOSITORY}/releases" \
--jq '.[] | [.id, .tag_name] | @tsv' \
> releases.tsv

echo "All release tags currently visible:"
cut -f2 releases.tsv || true

MATCHES="$(
awk -v prefix="$PREFIX" '
BEGIN { prefix_len = length(prefix) }
index($2, prefix) == 1 {
suffix = substr($2, prefix_len + 1)
if (suffix ~ /^[0-9]+$/) {
print $1 "\t" $2
}
}
' releases.tsv
)"

if [ -z "$RELEASE_TAGS" ]; then
echo "No temporary releases found for branch: $BRANCH_NAME"
if [ -z "$MATCHES" ]; then
echo "No matching temporary releases found for branch: ${BRANCH_NAME}"
echo "Expected tags like: ${PREFIX}1, ${PREFIX}2, ${PREFIX}3"
exit 0
fi

echo "Found temporary releases:"
echo "$RELEASE_TAGS"
echo "Matching releases to delete:"
echo "$MATCHES"

echo "$RELEASE_TAGS" | while IFS= read -r TAG; do
if [ -z "$TAG" ]; then
echo "$MATCHES" | while IFS="$(printf '\t')" read -r RELEASE_ID TAG; do
if [ -z "$RELEASE_ID" ] || [ -z "$TAG" ]; then
continue
fi

echo "Deleting release and tag: $TAG"
echo "Deleting release id=${RELEASE_ID}, tag=${TAG}"

gh api \
--method DELETE \
"repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}"

echo "Deleting git tag ref: ${TAG}"

gh release delete "$TAG" \
--yes \
--cleanup-tag
gh api \
--method DELETE \
"repos/${GITHUB_REPOSITORY}/git/refs/tags/${TAG}" \
|| echo "Tag ${TAG} was already deleted or did not exist"
done
Loading