Skip to content

fix: propagate GH_HOST to custom frontmatter jobs and safe-outputs for GHES/GHEC#21523

Merged
lpcox merged 3 commits intomainfrom
claude/ghes-gh-host-propagation
Mar 18, 2026
Merged

fix: propagate GH_HOST to custom frontmatter jobs and safe-outputs for GHES/GHEC#21523
lpcox merged 3 commits intomainfrom
claude/ghes-gh-host-propagation

Conversation

@lpcox
Copy link
Collaborator

@lpcox lpcox commented Mar 18, 2026

Problem

When a workflow runs on GHES/GHEC, the gh CLI needs GH_HOST set to the enterprise hostname. The agent job already handles this via configure_gh_for_ghe.sh, but custom frontmatter jobs and the safe-outputs job run as independent GitHub Actions jobs that don't inherit GITHUB_ENV from the agent job.

Relates to #18480

Solution

Add a lightweight inline step at the start of custom frontmatter jobs and the safe-outputs job:

- name: Configure GH_HOST for enterprise compatibility
  run: |
    GH_HOST="${GITHUB_SERVER_URL#https://}"
    GH_HOST="${GH_HOST#http://}"
    echo "GH_HOST=${GH_HOST}" >> "$GITHUB_ENV"
  • On github.com: harmless no-op
  • On GHES/GHEC: ensures gh CLI targets the correct enterprise instance
  • Zero external dependencies
  • Only added to jobs with steps (not reusable workflow jobs)

Changes

File Change
pkg/workflow/ghes_host_step.go New helper: generateGHESHostConfigurationStep()
pkg/workflow/ghes_host_step_test.go Tests for step content, custom job injection, reusable workflow exclusion
pkg/workflow/compiler_jobs.go Prepend GH_HOST step to custom frontmatter jobs
pkg/workflow/compiler_safe_outputs_job.go Add GH_HOST step to safe-outputs job
*.lock.yml (169 files) Recompiled workflows

…r GHES/GHEC

The gh CLI uses GH_HOST to determine which GitHub instance to target.
The agent job already sets GH_HOST via configure_gh_for_ghe.sh, but
custom frontmatter jobs (independent GitHub Actions jobs defined in
the workflow markdown) and the safe-outputs job run on separate runners
and don't inherit GITHUB_ENV from the agent job.

This adds a lightweight inline step that derives GH_HOST from
GITHUB_SERVER_URL (stripping the https:// prefix) and exports it to
GITHUB_ENV at the start of:

- Custom frontmatter jobs with steps (not reusable workflow jobs)
- The consolidated safe-outputs job

On github.com this is a harmless no-op (GH_HOST=github.com).
On GHES/GHEC it ensures every gh CLI command in the job targets the
correct enterprise instance.

Relates to: #18480

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 18, 2026 03:27
Copy link
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

This PR ensures GH_HOST is set for GitHub Enterprise Server / Enterprise Cloud runs in jobs that don’t inherit GITHUB_ENV from the agent job, so gh CLI invocations target the correct host.

Changes:

  • Added a reusable helper to generate an inline “Configure GH_HOST” step derived from GITHUB_SERVER_URL.
  • Prepended that step to custom frontmatter jobs and inserted it into the consolidated safe-outputs job.
  • Recompiled workflow lockfiles to include the new step in affected jobs.

Reviewed changes

Copilot reviewed 173 out of 173 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/workflow/ghes_host_step.go Adds helper to emit an inline step that sets GH_HOST via GITHUB_ENV.
pkg/workflow/ghes_host_step_test.go Adds unit tests for step content and injection behavior (including reusable workflow exclusion).
pkg/workflow/compiler_jobs.go Prepends the GH_HOST configuration step to custom jobs that define steps.
pkg/workflow/compiler_safe_outputs_job.go Inserts the GH_HOST configuration step into the consolidated safe-outputs job before user steps.
.github/workflows/*.lock.yml Recompiled locked workflows to include the new GH_HOST configuration step where applicable.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +21 to +27
return ` - name: Configure GH_HOST for enterprise compatibility
run: |
# Derive GH_HOST from GITHUB_SERVER_URL so the gh CLI targets the correct
# GitHub instance (GHES/GHEC). On github.com this is a harmless no-op.
GH_HOST="${GITHUB_SERVER_URL#https://}"
GH_HOST="${GH_HOST#http://}"
echo "GH_HOST=${GH_HOST}" >> "$GITHUB_ENV"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Copy link
Contributor

Choose a reason for hiding this comment

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

Added shell: bash to the generated step in d35fc86. The step now explicitly specifies bash, ensuring Bash-style parameter expansion (${VAR#prefix}) works correctly even on Windows runners that default to pwsh.

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copy link
Contributor

Copilot AI commented Mar 18, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/graphql
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw (http block)
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw pB95jqwYBO8C (http block)
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw -pack /home/REDACTED/work/gh-aw/gh-aw/pkg/cli/access_log.go /home/REDACTED/work/gh-aw/gh-aw/pkg/cli/actionlint.go /pre�� (http block)
  • https://api.github.com/repos/actions/setup-node/git/ref/tags/v6
    • Triggering command: /usr/bin/gh gh api /repos/actions/setup-node/git/ref/tags/v6 --jq .object.sha on&#39; --ignore-patremote.origin.url cfg $name) { hasDiscussionsEnabled } } (http block)
  • https://api.github.com/repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b
    • Triggering command: /usr/bin/gh gh api /repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b --jq .object.sha ath ../../../.pr**/*.json (http block)
  • https://api.github.com/repos/github/gh-aw
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw --jq .visibility (http block)
  • https://api.github.com/repos/githubnext/agentics/git/ref/tags/
    • Triggering command: /usr/bin/gh gh api /repos/githubnext/agentics/git/ref/tags/# --jq .object.sha (http block)

If you need me to access, download, or install something from one of these locations, you can either:

@lpcox lpcox merged commit c5ad522 into main Mar 18, 2026
53 checks passed
@lpcox lpcox deleted the claude/ghes-gh-host-propagation branch March 18, 2026 03:42
github-actions bot added a commit that referenced this pull request Mar 18, 2026
- cli.md: document that custom frontmatter jobs and safe-outputs now
  automatically have GH_HOST configured (from PR #21523). Remove the
  instruction to manually source configure_gh_for_ghe.sh for GH_HOST.
  Note that when GH_TOKEN is set the script skips gh auth login
  (PR #21525).

- common-issues.md: add "GitHub Enterprise Server Issues" section with
  Copilot prerequisites checklist (GitHub Connect, licensing, seats,
  token type) and a troubleshooting table for common GHES error messages
  (400 Bad Request, 403 not licensed, 403 PAT, Could not resolve
  Repository, firewall blocks, wizard PR on wrong host).

Closes #20968

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
github-actions bot added a commit that referenced this pull request Mar 18, 2026
Add two new terms identified from recent commits:

- GH_HOST: gh CLI env var for GHES/GHEC enterprise hostname routing,
  auto-configured by configure_gh_for_ghe.sh and propagated to
  custom frontmatter jobs and safe-outputs (PRs #21523, #21525)
- RUNNER_TEMP / runner.temp: GitHub Actions temp dir used for
  storing gh-aw runtime artifacts, replacing /opt/gh-aw for
  self-hosted runner compatibility (PR #21443)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

3 participants