Skip to content

Commit 16b6d23

Browse files
committed
fix(ci-deployment-cleanup): prevent pr-based deletion when gh credentials are bad
1 parent 5cf0711 commit 16b6d23

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

ci-deployment-cleanup/helm-chart/cleanup.sh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,17 @@ check_pr_status() {
182182

183183
debug_log "GitHub API response received"
184184

185+
# Check for authentication errors
186+
local auth_error
187+
auth_error=$(echo "$pr_response" | grep -o '"message":[[:space:]]*"[^"]*"' | sed 's/"message":[[:space:]]*"\([^"]*\)"/\1/')
188+
189+
if [ "$auth_error" = "Bad credentials" ]; then
190+
echo " → GitHub authentication failed (bad credentials), skipping PR cleanup for all namespaces"
191+
debug_log "GitHub authentication failed - bad credentials"
192+
export GITHUB_AUTH_FAILED=true
193+
return 1
194+
fi
195+
185196
# Check if PR exists and get its state
186197
local pr_state
187198
pr_state=$(echo "$pr_response" | grep -o '"state":[[:space:]]*"[^"]*"' | sed 's/"state":[[:space:]]*"\([^"]*\)"/\1/')
@@ -298,8 +309,8 @@ kubectl get namespaces \
298309
debug_log "Age-based cleanup triggered"
299310
fi
300311

301-
# Check PR-based cleanup if enabled
302-
if [ "$PR_CLEANUP_ENABLED" = "true" ]; then
312+
# Check PR-based cleanup if enabled and GitHub auth is working
313+
if [ "$PR_CLEANUP_ENABLED" = "true" ] && [ "$GITHUB_AUTH_FAILED" != "true" ]; then
303314
if check_pr_status "$namespace"; then
304315
should_cleanup=true
305316
if [ -n "$cleanup_reason" ]; then
@@ -309,6 +320,9 @@ kubectl get namespaces \
309320
fi
310321
debug_log "PR-based cleanup triggered: $PR_CLEANUP_REASON"
311322
fi
323+
elif [ "$PR_CLEANUP_ENABLED" = "true" ] && [ "$GITHUB_AUTH_FAILED" = "true" ]; then
324+
echo " → Skipping PR-based cleanup due to GitHub authentication failure"
325+
debug_log "Skipping PR cleanup due to GitHub auth failure"
312326
fi
313327

314328
if [ "$should_cleanup" = "true" ]; then
@@ -370,4 +384,3 @@ kubectl get namespaces \
370384

371385
debug_log "Namespace processing completed"
372386
echo "Renku CI deployment cleanup completed"
373-

0 commit comments

Comments
 (0)