diff --git a/.github/workflows/delete-pr-build-on-close.yml b/.github/workflows/delete-pr-build-on-close.yml index 1838cc84..37b41365 100644 --- a/.github/workflows/delete-pr-build-on-close.yml +++ b/.github/workflows/delete-pr-build-on-close.yml @@ -18,8 +18,18 @@ jobs: shell: bash run: | # 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. - LATEST_RELEASE_TAG=$(gh release list --repo slackapi/slack-cli --json tagName,isLatest --jq ".[] | select(.isLatest == true) | .tagName" ) - TAG_NAME="$LATEST_RELEASE_TAG-${{ github.event.ref }}" - echo "Identified pre-release tagname to 🔪: $TAG_NAME" - # Delete the pre-release - GH_DEBUG=1 gh release --repo slackapi/slack-cli delete $TAG_NAME -y --cleanup-tag + 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}-${{ github.event.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" + exit 0 + else + echo "Failed to find $TAG_NAME, trying next..." + fi + done + echo "No matching pre-releases tag was found for the branch $TAG_NAME in recent versions" + exit 1