@@ -887,12 +887,33 @@ WELCOME_STATIC
887887 if [ -z "$${_COMPOSER_GITHUB_TOKEN}" ]; then
888888 _CODER_BIN=$(find /tmp -name "coder" -path "*/coder.*/*" -type f -executable 2>/dev/null | head -1)
889889 if [ -n "$${_CODER_BIN}" ]; then
890- _COMPOSER_GITHUB_TOKEN=$("$${_CODER_BIN}" external-auth access-token github 2>/dev/null || true)
890+ # `coder external-auth access-token` prints the token to stdout and exits 0,
891+ # but when the user has no linked GitHub account it prints the *authentication
892+ # URL* to stdout and exits 1. The exit code must be honored: handing that URL
893+ # to Composer as an OAuth token makes every github.com dist download fail with
894+ # "Could not authenticate against github.com" and suppresses the anonymous
895+ # fallback, which is strictly worse than configuring no token at all.
896+ if _token=$("$${_CODER_BIN}" external-auth access-token github 2>/dev/null); then
897+ _COMPOSER_GITHUB_TOKEN="$_token"
898+ else
899+ log_setup "No linked GitHub account — using anonymous Composer downloads"
900+ fi
891901 fi
892902 fi
903+ # An expired or revoked token fails the same opaque way, so verify before use.
904+ if [ -n "$${_COMPOSER_GITHUB_TOKEN}" ] && \
905+ ! curl -sSf --max-time 10 -o /dev/null -H "Authorization: Bearer $${_COMPOSER_GITHUB_TOKEN}" https://api.github.com/user 2>/dev/null; then
906+ log_setup "⚠ GitHub token rejected by api.github.com — using anonymous Composer downloads"
907+ _COMPOSER_GITHUB_TOKEN=""
908+ fi
893909 if [ -n "$${_COMPOSER_GITHUB_TOKEN}" ]; then
894910 log_setup "Configuring Composer GitHub OAuth..."
895911 ddev exec composer config --global github-oauth.github.com "$${_COMPOSER_GITHUB_TOKEN}" >> "$SETUP_LOG" 2>&1 || true
912+ else
913+ # Clear any token a previous run configured. Composer's global config lives in
914+ # a persistent DDEV volume, so a bad value keeps breaking every later start
915+ # even once this code stops writing one.
916+ ddev exec composer config --global --unset github-oauth.github.com >> "$SETUP_LOG" 2>&1 || true
896917 fi
897918
898919 # Retry up to 3 times to handle transient codeload.github.com 400s.
@@ -1006,9 +1027,13 @@ WELCOME_STATIC
10061027 fi
10071028 fi # end SETUP_FAILED guard
10081029
1009- # Step 6.5: Cache rebuild — ensures a clean state after any setup path
1010- log_setup "Running cache rebuild..."
1011- ddev drush cr >> "$SETUP_LOG" 2>&1 || true
1030+ # Step 6.5: Cache rebuild — ensures a clean state after any successful setup path.
1031+ # Skipped when setup failed: there is no installed site to rebuild, and running it
1032+ # anyway just appends a confusing "drush is not available" error to the log.
1033+ if [ "$SETUP_FAILED" != "true" ]; then
1034+ log_setup "Running cache rebuild..."
1035+ ddev drush cr >> "$SETUP_LOG" 2>&1 || true
1036+ fi
10121037
10131038 # Step 6.6: Set up phpunit.xml for running core tests
10141039 if [ ! -f "phpunit.xml" ] && [ -f "phpunit-ddev.xml" ]; then
0 commit comments