Skip to content

refactor: replace hardcoded /opt/gh-aw paths with GH_AW_HOME constants (partial)#21422

Closed
Copilot wants to merge 3 commits intomainfrom
copilot/reimplement-gh-aw-home-support
Closed

refactor: replace hardcoded /opt/gh-aw paths with GH_AW_HOME constants (partial)#21422
Copilot wants to merge 3 commits intomainfrom
copilot/reimplement-gh-aw-home-support

Conversation

Copy link
Contributor

Copilot AI commented Mar 17, 2026

Hardcoded /opt/gh-aw paths throughout the compiler prevent self-hosted runners from relocating the installation directory. This PR introduces typed constants and a helper to abstract all path references, allowing operators to override via GH_AW_HOME.

New abstractions (pkg/workflow/setup_action_paths.go)

Constant/Helper Value Use in
GhAwHome ${GH_AW_HOME} bash run: blocks
GhAwHomeJS process.env.GH_AW_HOME JS require() expressions
GhAwHomeExpr ${{ env.GH_AW_HOME }} YAML env: blocks
GhAwHomeExprDefault ${{ env.GH_AW_HOME || '/opt/gh-aw' }} job-level env with fallback
JsRequireGhAw(path) helper generates process.env.GH_AW_HOME + '/path'

SetupActionDestination updated to GhAwHomeExpr + "/actions".

pkg/constants/constants.go

  • Added GhAwHomeDefault = "/opt/gh-aw"
  • Updated DefaultGhAwMount to \${GH_AW_HOME}:\${GH_AW_HOME}:ro (shell-expanded at runtime)

Example replacement pattern

// Before
yaml.WriteString("const { main } = require('/opt/gh-aw/actions/redact_secrets.cjs');\n")
yaml.WriteString("bash /opt/gh-aw/actions/stop_mcp_gateway.sh\n")

// After
yaml.WriteString("const { main } = require(" + JsRequireGhAw("actions/redact_secrets.cjs") + ");\n")
yaml.WriteString("bash " + GhAwHome + "/actions/stop_mcp_gateway.sh\n")

Status

~20 compiler files updated. Remaining: notify_comment.go, compiler_main_job.go (GH_AW_HOME job-level env injection), compiler_yaml.go, cache.go, safe_jobs.go, maintenance_workflow.go, mcp_github_config.go, several others, JS .cjs files, test updates, and lock file recompilation.

…aths (partial)

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

@copilot keep working

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@github-actions
Copy link
Contributor

Hey @Copilot 👋 — great start on the GH_AW_HOME path-abstraction refactor! Centralizing the hardcoded /opt/gh-aw paths behind typed constants (GhAwHome, GhAwHomeJS, GhAwHomeExprDefault, and the JsRequireGhAw helper) is exactly the kind of change that makes self-hosted runner deployments much more flexible. The description table and before/after examples are excellent.

A couple of things to close out before this can leave draft:

  • No tests yet — the PR body already flags "test updates" as a remaining item, and the checklist confirms no _test.go files were touched. The codebase has good coverage patterns to follow: pkg/workflow/cjs_require_validation_test.go already tests .cjs require paths, and pkg/workflow/agentic_workflow_test.go / pkg/workflow/agentic_output_test.go exercise many of the compiled YAML paths that now reference the new constants. Any test that asserts a generated YAML snippet containing /opt/gh-aw should be updated to expect the $\{\{ env.GH_AW_HOME || '/opt/gh-aw' }} (or shell-variable) form.

  • Remaining filesnotify_comment.go, compiler_main_job.go, compiler_yaml.go, cache.go, safe_jobs.go, maintenance_workflow.go, mcp_github_config.go, and the JS .cjs files are still pending per the status section. The PR should be complete (or explicitly scoped with a follow-up issue) before merging.

  • Run make agent-finish — once the remaining files and tests are in place, run make agent-finish (build + test + lint + recompile + fmt) to confirm everything is green, as required by the contribution process.

If you'd like a hand finishing up, you can assign this prompt to your coding agent:

Continue the GH_AW_HOME path-abstraction refactor in the gh-aw repository on branch copilot/reimplement-gh-aw-home-support.

Context:
- pkg/workflow/setup_action_paths.go already defines GhAwHome, GhAwHomeJS, GhAwHomeExpr, GhAwHomeExprDefault, and JsRequireGhAw().
- pkg/constants/constants.go now has GhAwHomeDefault = "/opt/gh-aw" and an updated DefaultGhAwMount.
- ~20 compiler files have already been migrated.

Tasks:
1. Migrate the remaining files that still contain hardcoded /opt/gh-aw paths:
   - pkg/workflow/notify_comment.go
   - pkg/workflow/compiler_main_job.go  (also inject GH_AW_HOME job-level env)
   - pkg/workflow/compiler_yaml.go
   - pkg/workflow/cache.go
   - pkg/workflow/safe_jobs.go
   - pkg/workflow/maintenance_workflow.go
   - pkg/workflow/mcp_github_config.go
   - Any remaining .go files: run `grep -r '/opt/gh-aw' pkg/` to find stragglers.
   - JS .cjs files under actions/ that hardcode /opt/gh-aw.

2. Update tests:
   - In pkg/workflow/cjs_require_validation_test.go, pkg/workflow/agentic_workflow_test.go, and any other test that asserts YAML output containing /opt/gh-aw literals, update expected strings to use the new constant forms (e.g. process.env.GH_AW_HOME, \$\{GH_AW_HOME}, $\{\{ env.GH_AW_HOME || '/opt/gh-aw' }}).
   - Add a unit test in pkg/workflow/ that calls JsRequireGhAw("actions/redact_secrets.cjs") and asserts the returned string equals `process.env.GH_AW_HOME + '/actions/redact_secrets.cjs'`.

3. Run `make agent-finish` to validate the full build, test, lint, recompile, and format pipeline passes before committing.

Generated by Contribution Check ·

@pelikhan
Copy link
Contributor

see #21443

@pelikhan pelikhan closed this Mar 17, 2026
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.

2 participants