Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/skills/agentic-workflows/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Load these files from `github/gh-aw` (they are not available locally).
- `.github/aw/github-mcp-server-pagination.md`
- `.github/aw/github-mcp-server.md`
- `.github/aw/instructions.md`
- `.github/aw/jobs.md`
- `.github/aw/linter-workflows.md`
- `.github/aw/llms.md`
- `.github/aw/loop.md`
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/aw.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"auto_upgrade": { "cron": "0 9 * * 1" },
"ghes": false,
"maintenance": {
"action_failure_issue_expires": 12,
"label_triggers": true
Expand Down
6 changes: 6 additions & 0 deletions pkg/cli/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func InitRepository(opts InitOptions) error {
initLog.Print("Verified git repository")

// Auto-detect GHES deployment and configure aw.json ghes: true when needed.
// ensureGHESRepoConfig skips detection in CI, where gh-proxy can make the environment look like GHES.
if _, err := ensureGHESRepoConfig(opts.Verbose); err != nil {
initLog.Printf("Failed to configure GHES repo config: %v", err)
// Non-fatal: continue with the rest of init
Expand Down Expand Up @@ -368,6 +369,11 @@ func detectGHESDeployment() string {
// if GHES is not detected or if "ghes": true is already present.
// Returns (updated bool, err).
func ensureGHESRepoConfig(verbose bool) (bool, error) {
if IsRunningInCI() {
initLog.Print("Running in CI, skipping GHES repo configuration")
return false, nil
}

ghesHost := detectGHESDeployment()
if ghesHost == "" {
initLog.Print("No GHES deployment detected, skipping aw.json ghes configuration")
Expand Down
40 changes: 40 additions & 0 deletions pkg/cli/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ func TestEnsureGHESRepoConfig_GHHostEnvVar(t *testing.T) {
}

// Point GH_HOST at a GHES instance
clearCIEnvironment(t)
t.Setenv("GH_HOST", "ghes.example.com")
t.Setenv("GITHUB_SERVER_URL", "")

Expand Down Expand Up @@ -471,6 +472,7 @@ func TestEnsureGHESRepoConfig_Idempotent(t *testing.T) {
t.Fatalf("git init failed: %v", err)
}

clearCIEnvironment(t)
t.Setenv("GH_HOST", "ghes.example.com")
t.Setenv("GITHUB_SERVER_URL", "")

Expand All @@ -492,3 +494,41 @@ func TestEnsureGHESRepoConfig_Idempotent(t *testing.T) {
t.Error("Second call should be idempotent (no update when ghes: true already set)")
}
}

func TestEnsureGHESRepoConfig_SkipsCI(t *testing.T) {
tempDir := t.TempDir()
oldWd, err := os.Getwd()
if err != nil {
t.Fatalf("Failed to get cwd: %v", err)
}
defer func() { _ = os.Chdir(oldWd) }()
if err := os.Chdir(tempDir); err != nil {
t.Fatalf("Failed to chdir: %v", err)
}

if err := exec.Command("git", "init").Run(); err != nil {
t.Fatalf("git init failed: %v", err)
}

t.Setenv("CI", "true")
t.Setenv("GH_HOST", "ghes.example.com")

updated, err := ensureGHESRepoConfig(false)
if err != nil {
t.Fatalf("ensureGHESRepoConfig returned unexpected error: %v", err)
}
if updated {
t.Fatal("ensureGHESRepoConfig should skip GHES configuration in CI")
}

if _, err := os.Stat(filepath.Join(tempDir, ".github", "workflows", "aw.json")); !os.IsNotExist(err) {
t.Fatal("ensureGHESRepoConfig should not create aw.json in CI")
Comment on lines +524 to +525
}
}

func clearCIEnvironment(t *testing.T) {
t.Helper()
for _, envVar := range []string{"CI", "CONTINUOUS_INTEGRATION", "GITHUB_ACTIONS", "COPILOT_AGENT_SESSION_ID"} {
t.Setenv(envVar, "")
}
}
Loading