From 415bbd18937cae6dafd4c96fb85ffee178c62f7a Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Fri, 3 Jan 2025 16:21:45 +0100 Subject: [PATCH] Fix deletion of old releases --- .github/workflows/nightly.yml | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index f87edc0..7a93d10 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -27,7 +27,36 @@ jobs: run: git push origin --delete nightly || true - name: Delete existing nightly release run: | - curl -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/releases/tags/nightly + TAG_NAME=nightly + + # Fetch the release associated with the tag + RESPONSE=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \ + -H "Accept: application/vnd.github+json" \ + "https://api.github.com/repos/$REPO/releases/tags/$TAG_NAME") + + # Check if a release was found + RELEASE_ID=$(echo "$RESPONSE" | jq -r ".id") + + if [[ "$RELEASE_ID" == "null" || -z "$RELEASE_ID" ]]; then + echo "No release found for tag: $TAG_NAME" + else + echo "Deleting release with ID: $RELEASE_ID" + curl -s -X DELETE -H "Authorization: Bearer $GITHUB_TOKEN" \ + -H "Accept: application/vnd.github+json" \ + "https://api.github.com/repos/$REPO/releases/$RELEASE_ID" + fi + + # Delete the tag. + RESPONSE=$(curl -s -X DELETE -H "Authorization: Bearer $GITHUB_TOKEN" \ + -H "Accept: application/vnd.github+json" \ + "https://api.github.com/repos/$REPO/git/refs/tags/$TAG_NAME") + + # Check for success + if echo "$RESPONSE" | grep -q '"message":'; then + echo "Error: $(echo "$RESPONSE" | jq -r '.message')" + else + echo "Tag '$TAG_NAME' deleted successfully." + fi - name: Release uses: softprops/action-gh-release@v2 with: