fix: unset stale GH_HOST when configuring gh for github.com#24222
fix: unset stale GH_HOST when configuring gh for github.com#24222
Conversation
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/30a6422b-97fb-4c86-bb2a-187e682fd2d2 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes a GitHub CLI host mismatch when running on github.com by clearing/overriding a stale GH_HOST value that could otherwise cause downstream gh commands (e.g., gh pr checkout) to fail.
Changes:
- When the resolved host is
github.com, detect and clear a staleGH_HOSTvalue. - Persist the corrected host setting for later GitHub Actions steps via
$GITHUB_ENV.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| echo "Using public GitHub (github.com) - no additional gh configuration needed" | ||
| # Clear any stale GH_HOST to prevent gh CLI mismatches | ||
| if [ -n "${GH_HOST:-}" ] && [ "${GH_HOST}" != "github.com" ]; then | ||
| echo "Clearing stale GH_HOST=${GH_HOST}" |
There was a problem hiding this comment.
echo "Clearing stale GH_HOST=${GH_HOST}" will print the previous (potentially internal) GHE hostname into GitHub Actions logs when running on github.com. If these workflows run in public repos, this can leak internal infrastructure details; additionally, echoing raw environment values risks accidental workflow-command injection if GH_HOST ever contains ::... sequences. Consider omitting the value (log a generic message), or at least writing the message to stderr and sanitizing the value before printing.
| echo "Clearing stale GH_HOST=${GH_HOST}" | |
| echo "Clearing stale GH_HOST" >&2 |
| echo "Clearing stale GH_HOST=${GH_HOST}" | ||
| unset GH_HOST | ||
| if [ -n "${GITHUB_ENV:-}" ]; then | ||
| echo "GH_HOST=github.com" >> "${GITHUB_ENV}" |
There was a problem hiding this comment.
This block says it is clearing a stale GH_HOST, but for subsequent steps it writes GH_HOST=github.com into $GITHUB_ENV (so GH_HOST remains set rather than cleared). Elsewhere in this repo, clearing GH_HOST for later steps is done by writing an empty assignment (e.g., actions/setup/sh/stop_difc_proxy.sh:28 uses GH_HOST=). Consider using the same clearing pattern here (or adjust the comment/message to reflect that the intent is to force GH_HOST to github.com, not clear it).
| echo "GH_HOST=github.com" >> "${GITHUB_ENV}" | |
| echo "GH_HOST=" >> "${GITHUB_ENV}" |
|
@copilot review comments |
…ITHUB_ENV Agent-Logs-Url: https://github.com/github/gh-aw/sessions/f7fa60de-4903-4101-bfa5-3211d8b0c0e0 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
configure_gh_for_ghe.shreturned early forgithub.comwithout clearingGH_HOST, leaving any stale GHE host value in place. Downstreamghcommands (e.g.,gh pr checkout) would then fail withnone of the git remotes correspond to the GH_HOST environment variable.Changes
actions/setup/sh/configure_gh_for_ghe.sh: When the resolved host isgithub.com, explicitly clear a staleGH_HOSTvalue —unset GH_HOSTin the current shell and writeGH_HOST=to$GITHUB_ENVto clear it for subsequent steps.The guard (
GH_HOSTset and not alreadygithub.com) ensures no-ops whenGH_HOSTis already correct or unset. The log message omits the stale value to avoid leaking internal hostnames or risking workflow-command injection. TheGITHUB_ENVwrite uses an empty assignment (GH_HOST=) to fully clear the variable for subsequent steps, consistent with the pattern used instop_difc_proxy.sh.