@@ -271,6 +271,12 @@ load_env_file() {
271271cleanup_gh_account () {
272272 local target_account=" vinhnguyenxuan-ct"
273273
274+ # Don't try to switch back if GITHUB_TOKEN is set (CI environment)
275+ if [[ -n " ${GITHUB_TOKEN:- } " ]]; then
276+ print_info " GITHUB_TOKEN is set - skipping account cleanup (not needed for token authentication)"
277+ return 0
278+ fi
279+
274280 # Only try cleanup if we switched accounts
275281 if [[ " ${GH_ACCOUNT_SWITCHED:- false} " == " true" ]]; then
276282 print_info " Performing cleanup - switching back to original account..."
@@ -720,7 +726,7 @@ update_vscode_extension_version() {
720726# $1: target_account - GitHub username to switch to
721727# $2: operation - Description of the operation (for logging)
722728# Returns:
723- # 0 if switch successful, 1 otherwise
729+ # 0 if switch successful or not needed , 1 if critical failure
724730switch_gh_account () {
725731 local target_account=$1
726732 local operation=$2
@@ -730,6 +736,13 @@ switch_gh_account() {
730736 return 1
731737 fi
732738
739+ # If GITHUB_TOKEN is set, we're in a CI environment or using token auth
740+ # In this case, we don't need to switch accounts - the token provides authentication
741+ if [[ -n " ${GITHUB_TOKEN:- } " ]]; then
742+ print_info " GITHUB_TOKEN environment variable is set - using token authentication (no account switch needed)"
743+ return 0
744+ fi
745+
733746 print_info " Switching GitHub CLI to account: $target_account ($operation )"
734747
735748 # Switch without prompts using -u flag
@@ -748,7 +761,7 @@ switch_gh_account() {
748761# Args:
749762# $1: expected_account - GitHub username to verify
750763# Returns:
751- # 0 if account matches , 1 otherwise
764+ # 0 if authenticated (either via token or account) , 1 otherwise
752765verify_gh_account () {
753766 local expected_account=$1
754767
@@ -757,6 +770,18 @@ verify_gh_account() {
757770 return 1
758771 fi
759772
773+ # If GITHUB_TOKEN is set, verify token authentication works
774+ if [[ -n " ${GITHUB_TOKEN:- } " ]]; then
775+ if gh auth status > /dev/null 2>&1 ; then
776+ print_success " GitHub CLI authenticated with GITHUB_TOKEN"
777+ return 0
778+ else
779+ print_error " GITHUB_TOKEN is set but GitHub CLI authentication failed"
780+ return 1
781+ fi
782+ fi
783+
784+ # Traditional account verification for non-token auth
760785 if ! gh auth status > /dev/null 2>&1 ; then
761786 print_error " GitHub CLI is not authenticated"
762787 return 1
0 commit comments