Skip to content
Merged
Show file tree
Hide file tree
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
72 changes: 72 additions & 0 deletions .github/workflows/cleanup-temp-releases.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Cleanup Temporary Branch Releases

on:
pull_request:
types:
- closed
branches:
- main

permissions:
contents: write
pull-requests: read

jobs:
cleanup-temp-releases:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest

env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

steps:
- name: Normalize merged branch name
run: |
BRANCH_NAME="${{ github.event.pull_request.head.ref }}"

SAFE_BRANCH="${BRANCH_NAME//\//-}"
SAFE_BRANCH="${SAFE_BRANCH//_/-}"
SAFE_BRANCH="$(echo "$SAFE_BRANCH" | tr '[:upper:]' '[:lower:]')"

echo "BRANCH_NAME=$BRANCH_NAME" >> "$GITHUB_ENV"
echo "SAFE_BRANCH=$SAFE_BRANCH" >> "$GITHUB_ENV"

echo "Merged branch: $BRANCH_NAME"
echo "Safe branch: $SAFE_BRANCH"

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

echo "Looking for releases with prefix: $PREFIX"

RELEASE_TAGS="$(
gh api \
--paginate \
"repos/${GITHUB_REPOSITORY}/releases" \
--jq '.[].tag_name' \
| grep -E "^${PREFIX}[0-9]+$" \
|| true
)"

if [ -z "$RELEASE_TAGS" ]; then
echo "No temporary releases found for branch: $BRANCH_NAME"
exit 0
fi

echo "Found temporary releases:"
echo "$RELEASE_TAGS"

while IFS= read -r TAG; do
if [ -z "$TAG" ]; then
continue
fi

echo "Deleting release and tag: $TAG"

gh release delete "$TAG" \
--yes \
--cleanup-tag
done <<EOF
$RELEASE_TAGS
EOF
15 changes: 1 addition & 14 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,4 @@ jobs:
files: release-assets/a
make_latest: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Mark latest main release
if: github.ref_name == 'main'
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

git tag -f latest "$GITHUB_SHA"
git push origin latest --force

gh release edit "$RELEASE_TAG" --latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions main.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sdasd
Loading