Skip to content

build(deps): bump actions/checkout from 5.0.1 to 6.0.0 #251

build(deps): bump actions/checkout from 5.0.1 to 6.0.0

build(deps): bump actions/checkout from 5.0.1 to 6.0.0 #251

name: Delete pre-release when a branch is deleted
# This workflow action deletes pre-releases when a PR is merged or closed.
#
# The CircleCI configuration builds CLI binaries when a PR is opened.
# These are uploaded to the upstream project as GitHub (pre-)releases.
#
# The release tag matches one of the following patterns:
# - v1.2.3-example-branch-placeholder # Branches on upstream
# - v1.2.3-pull-12-head # Branches from forks
#
# A "pull_request_target" event is used to delete pre-releases upstream.
#
# See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#running-your-pull_request-workflow-when-a-pull-request-merges
# See https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#pull_request_target
on:
pull_request_target: # zizmor: ignore[dangerous-triggers]
types:
- closed
jobs:
delete-pre-release:
name: Delete pre-release if exists
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Delete pre-release and tag named after branch
env:
GH_TOKEN: ${{ github.token }}
PR_BRANCH: ${{ github.event.pull_request.head.ref }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_REPO: ${{ github.event.pull_request.head.repo.full_name }}
shell: bash
run: |
# Use either an upstream or fork PR branch
if [[ "$PR_REPO" != "slackapi/slack-cli" ]]; then
BRANCH="pull/$PR_NUMBER/head"
else
BRANCH="$PR_BRANCH"
fi
# Escape tags to create a semantic version
REF=$(echo "${BRANCH}" | sed 's/\//-/g')
RELEASE_FOUND=1
# Delete tags matching the pull request branch from forks
if GH_DEBUG=1 gh release --repo="slackapi/slack-cli" delete "${REF}" -y --cleanup-tag; then
echo "Successfully deleted ${REF}"
RELEASE_FOUND=0
else
echo "Did not find ${REF} tag, trying version prefixes..."
fi
# Figure out tag name from branch name. This is coupled to the tag name generation that exists in .circleci/config.yml's `create-github-release` job.
RELEASES=$(gh release list --repo="slackapi/slack-cli" --order="desc" --json="tagName" --exclude-drafts --exclude-pre-releases --limit=24 --jq ".[] | .tagName")
for TAGS in $RELEASES; do
TAG_NAME="${TAGS}-${REF}"
echo "Identified pre-release tagname to 🔪: $TAG_NAME"
# Delete the pre-release
if GH_DEBUG=1 gh release --repo="slackapi/slack-cli" delete "$TAG_NAME" -y --cleanup-tag; then
echo "Successfully deleted $TAG_NAME"
RELEASE_FOUND=0
else
echo "Failed to find $TAG_NAME, trying next..."
fi
sleep 1
FEATURE_TAG_NAME="${TAGS}-${REF}-feature"
echo "Identified feature-release tagname as 🔪: $FEATURE_TAG_NAME"
# Delete a feature-release
if GH_DEBUG=1 gh release --repo="slackapi/slack-cli" delete "$FEATURE_TAG_NAME" -y --cleanup-tag; then
echo "Successfully deleted $FEATURE_TAG_NAME"
RELEASE_FOUND=0
else
echo "Failed to find $FEATURE_TAG_NAME, trying next..."
fi
sleep 1
done
if [ "$RELEASE_FOUND" -ne 0 ]; then
echo "No matching pre-releases tag was found for the branch $TAG_NAME in recent versions"
fi
exit "$RELEASE_FOUND"