Skip to content

fix: unset stale GH_HOST when configuring gh for github.com#24222

Merged
pelikhan merged 4 commits intomainfrom
copilot/fix-configure-gh-for-ghe-stale-gh-host
Apr 3, 2026
Merged

fix: unset stale GH_HOST when configuring gh for github.com#24222
pelikhan merged 4 commits intomainfrom
copilot/fix-configure-gh-for-ghe-stale-gh-host

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 3, 2026

configure_gh_for_ghe.sh returned early for github.com without clearing GH_HOST, leaving any stale GHE host value in place. Downstream gh commands (e.g., gh pr checkout) would then fail with none of the git remotes correspond to the GH_HOST environment variable.

Changes

  • actions/setup/sh/configure_gh_for_ghe.sh: When the resolved host is github.com, explicitly clear a stale GH_HOST value — unset GH_HOST in the current shell and write GH_HOST= to $GITHUB_ENV to clear it for subsequent steps.
if [ "$github_host" = "github.com" ]; then
  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" >&2
    unset GH_HOST
    if [ -n "${GITHUB_ENV:-}" ]; then
      echo "GH_HOST=" >> "${GITHUB_ENV}"
    fi
  fi
  return 0
fi

The guard (GH_HOST set and not already github.com) ensures no-ops when GH_HOST is already correct or unset. The log message omits the stale value to avoid leaking internal hostnames or risking workflow-command injection. The GITHUB_ENV write uses an empty assignment (GH_HOST=) to fully clear the variable for subsequent steps, consistent with the pattern used in stop_difc_proxy.sh.

Copilot AI changed the title [WIP] Fix configure_gh_for_ghe.sh to unset stale GH_HOST on github.com fix: unset stale GH_HOST when configuring gh for github.com Apr 3, 2026
Copilot AI requested a review from pelikhan April 3, 2026 03:36
@pelikhan pelikhan marked this pull request as ready for review April 3, 2026 04:27
Copilot AI review requested due to automatic review settings April 3, 2026 04:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 stale GH_HOST value.
  • 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}"
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
echo "Clearing stale GH_HOST=${GH_HOST}"
echo "Clearing stale GH_HOST" >&2

Copilot uses AI. Check for mistakes.
echo "Clearing stale GH_HOST=${GH_HOST}"
unset GH_HOST
if [ -n "${GITHUB_ENV:-}" ]; then
echo "GH_HOST=github.com" >> "${GITHUB_ENV}"
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
echo "GH_HOST=github.com" >> "${GITHUB_ENV}"
echo "GH_HOST=" >> "${GITHUB_ENV}"

Copilot uses AI. Check for mistakes.
@pelikhan
Copy link
Copy Markdown
Collaborator

pelikhan commented Apr 3, 2026

@copilot review comments

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 3, 2026

@copilot review comments

Addressed both review comments in 634d533:

  • Log message no longer prints the stale GH_HOST value (written to stderr as a generic message)
  • GITHUB_ENV now writes GH_HOST= to clear the variable for subsequent steps, consistent with stop_difc_proxy.sh

@pelikhan pelikhan merged commit aa71e9c into main Apr 3, 2026
50 checks passed
@pelikhan pelikhan deleted the copilot/fix-configure-gh-for-ghe-stale-gh-host branch April 3, 2026 04:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: configure_gh_for_ghe.sh should unset stale GH_HOST on github.com

3 participants