Skip to content

Commit a47b188

Browse files
Merge pull request #107 from Githubguy132010/dev
Refactor release cleanup step to use GH_TOKEN for authentication and improve error handling for release listing
2 parents 146dd3f + 77432ad commit a47b188

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

.github/workflows/build.yaml

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ jobs:
197197
# This step runs after the GitHub CLI setup and release creation
198198
if: github.ref == 'refs/heads/main' && success()
199199
env:
200-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
200+
# Don't set GITHUB_TOKEN here as it conflicts with gh auth
201+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
201202
run: |
202203
set +e # Don't exit on error
203204
@@ -207,21 +208,20 @@ jobs:
207208
current_tag="v${{ env.VERSION }}"
208209
echo "ℹ️ Current release tag: $current_tag"
209210
210-
# Explicitly authenticate with GitHub CLI using the token
211-
echo "$GITHUB_TOKEN" | gh auth login --with-token
212-
213-
if [ $? -ne 0 ]; then
214-
echo "::warning::Failed to authenticate with GitHub CLI. Skipping release cleanup."
215-
exit 0 # Continue workflow
216-
fi
211+
# GitHub CLI uses GH_TOKEN environment variable automatically
212+
# No need to explicitly authenticate
217213
218214
# List all releases
219215
echo "ℹ️ Listing existing releases..."
220216
221217
# Use simple list format first to check if releases exist
222-
release_count=$(gh release list | wc -l)
218+
if ! release_count=$(gh release list | wc -l); then
219+
echo "::warning::Failed to list releases. Skipping cleanup."
220+
echo "::endgroup::"
221+
exit 0
222+
fi
223223
224-
if [ $release_count -eq 0 ]; then
224+
if [ "$release_count" -eq 0 ]; then
225225
echo "ℹ️ No existing releases found. Nothing to clean up."
226226
echo "::endgroup::"
227227
exit 0
@@ -230,9 +230,7 @@ jobs:
230230
echo "ℹ️ Found $release_count releases in total"
231231
232232
# Get detailed release info with JSON
233-
releases=$(gh release list --limit 100 --json tagName,createdAt 2>/dev/null)
234-
235-
if [ $? -ne 0 ] || [ -z "$releases" ]; then
233+
if ! releases=$(gh release list --limit 100 --json tagName,createdAt 2>/dev/null); then
236234
echo "::warning::Unable to get detailed release information. Skipping cleanup."
237235
echo "::endgroup::"
238236
exit 0

0 commit comments

Comments
 (0)