Skip to content

Commit b4b987d

Browse files
committed
added cleanup temp releases
1 parent 0b7335b commit b4b987d

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Cleanup Temporary Branch Releases
2+
3+
on:
4+
pull_request:
5+
types:
6+
- closed
7+
branches:
8+
- main
9+
10+
permissions:
11+
contents: write
12+
pull-requests: read
13+
14+
jobs:
15+
cleanup-temp-releases:
16+
if: github.event.pull_request.merged == true
17+
runs-on: ubuntu-latest
18+
19+
env:
20+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
22+
steps:
23+
- name: Normalize merged branch name
24+
run: |
25+
BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
26+
27+
SAFE_BRANCH="${BRANCH_NAME//\//-}"
28+
SAFE_BRANCH="${SAFE_BRANCH//_/-}"
29+
SAFE_BRANCH="$(echo "$SAFE_BRANCH" | tr '[:upper:]' '[:lower:]')"
30+
31+
echo "BRANCH_NAME=$BRANCH_NAME" >> "$GITHUB_ENV"
32+
echo "SAFE_BRANCH=$SAFE_BRANCH" >> "$GITHUB_ENV"
33+
34+
echo "Merged branch: $BRANCH_NAME"
35+
echo "Safe branch: $SAFE_BRANCH"
36+
37+
- name: Delete temporary releases and tags for merged branch
38+
run: |
39+
PREFIX="temp-${SAFE_BRANCH}-v"
40+
41+
echo "Looking for releases with prefix: $PREFIX"
42+
43+
RELEASE_TAGS="$(
44+
gh api \
45+
--paginate \
46+
"repos/${GITHUB_REPOSITORY}/releases" \
47+
--jq '.[].tag_name' \
48+
| grep -E "^${PREFIX}[0-9]+$" \
49+
|| true
50+
)"
51+
52+
if [ -z "$RELEASE_TAGS" ]; then
53+
echo "No temporary releases found for branch: $BRANCH_NAME"
54+
exit 0
55+
fi
56+
57+
echo "Found temporary releases:"
58+
echo "$RELEASE_TAGS"
59+
60+
while IFS= read -r TAG; do
61+
if [ -z "$TAG" ]; then
62+
continue
63+
fi
64+
65+
echo "Deleting release and tag: $TAG"
66+
67+
gh release delete "$TAG" \
68+
--yes \
69+
--cleanup-tag
70+
done <<EOF
71+
$RELEASE_TAGS
72+
EOF

0 commit comments

Comments
 (0)