Skip to content
Merged
Changes from 2 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
20 changes: 15 additions & 5 deletions .github/workflows/delete-pr-build-on-close.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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=6 --jq ".[] | .tagName")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This command is similar to the one before, but now lists more recent releases:

$ gh release list --repo="slackapi/slack-cli" --order="desc" --json="tagName" --exclude-drafts --exclude-pre-releases --limit=6 --jq ".[] | .tagName"
v3.0.4
v3.0.3
v3.0.2

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome find! Any reason why you chose --limit 6? It looks like the default is --limit 30 which could prevent undeleted pre-releases further back?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mwbrooks Hmm I'm glad you called this out! 🤔

I agree 6 seems to be not enough releases, but I also wanted to limit this to avoid rate limits in the following loop if the branch isn't found.

That might have a better workaround though...

Keeping some --limit feels right to me since the default isn't clear otherwise, and this is now 24 which should cover more branches!

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
Loading