Skip to content

Commit 9118650

Browse files
author
Test User
committed
refactor: use GitHub API directly instead of installing gh CLI
- Use curl and GitHub API to delete existing release - Simpler and faster (no installation needed) - jq is already available in GitHub Actions runners
1 parent 8bfc864 commit 9118650

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

.github/workflows/release.yml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,16 @@ jobs:
2828

2929
- name: Delete existing release (if re-running)
3030
run: |
31-
# Install GitHub CLI if not available
32-
if ! command -v gh &> /dev/null; then
33-
echo "Installing GitHub CLI..."
34-
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
35-
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
36-
sudo apt update && sudo apt install gh -y
37-
fi
38-
3931
# Check if release exists and delete it to allow re-upload
40-
if gh release view "${{ github.ref_name }}" &>/dev/null; then
41-
echo "Release ${{ github.ref_name }} exists, deleting to allow re-upload..."
42-
gh release delete "${{ github.ref_name }}" --yes || true
32+
RELEASE_ID=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
33+
"https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ github.ref_name }}" \
34+
| jq -r '.id // empty')
35+
36+
if [ -n "$RELEASE_ID" ] && [ "$RELEASE_ID" != "null" ]; then
37+
echo "Release ${{ github.ref_name }} exists (ID: $RELEASE_ID), deleting to allow re-upload..."
38+
curl -X DELETE -H "Authorization: token $GITHUB_TOKEN" \
39+
"https://api.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID" || true
40+
echo "Release deleted successfully"
4341
else
4442
echo "No existing release found for ${{ github.ref_name }}"
4543
fi

0 commit comments

Comments
 (0)