fix: recover toolchain env vars from $GITHUB_ENV file#1977
Conversation
When AWF runs via sudo, non-standard env vars like GOROOT, CARGO_HOME, JAVA_HOME are stripped. Add readGitHubEnvEntries() to read the $GITHUB_ENV file directly (analogous to existing readGitHubPathEntries for $GITHUB_PATH) and use it as a fallback for toolchain variables. Key changes: - Add parseGitHubEnvFile() supporting KEY=VALUE and heredoc formats - Add readGitHubEnvEntries() reading from $GITHUB_ENV file path - Replace individual process.env checks with TOOLCHAIN_ENV_VARS loop that falls back to $GITHUB_ENV when process.env is empty - 14 new tests covering parser, file reader, and integration Closes #1958 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
✅ Coverage Check PassedOverall Coverage
📁 Per-file Coverage Changes (1 files)
Coverage comparison generated by |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
This PR addresses toolchain environment variables (e.g., GOROOT, JAVA_HOME) being lost when AWF is invoked via sudo by recovering allowlisted values from the GitHub Actions $GITHUB_ENV file, analogous to the existing $GITHUB_PATH handling.
Changes:
- Added
$GITHUB_ENVreading/parsing helpers to recover exported env vars even ifsudostripsprocess.env. - Introduced an allowlist (
TOOLCHAIN_ENV_VARS) and refactored toolchain env propagation into a loop. - Added unit/integration-style tests covering
$GITHUB_ENVparsing/reading and precedence vsprocess.env.
Show a summary per file
| File | Description |
|---|---|
src/docker-manager.ts |
Adds $GITHUB_ENV parsing/reading and uses it as a fallback source for allowlisted toolchain vars when constructing container env. |
src/docker-manager.test.ts |
Adds tests for $GITHUB_ENV parsing/reading and verifies toolchain fallback + precedence behavior. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 1
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
Smoke Test Results✅ GitHub MCP — #1976 "feat: add upstream corporate proxy support for self-hosted runners" / #1974 "optimize(secret-digger-claude): default threat detection to Haiku, drop version-reporting import" Overall: PASS
|
🔥 Smoke Test Results — @lpcox
Overall: PARTIAL PASS — MCP and network connectivity confirmed; file test data unavailable due to unexpanded workflow template variables.
|
Smoke Test: GitHub Actions Services Connectivity ✅All checks passed:
Note:
|
|
Smoke test results:
|
Chroot Version Comparison Results
Result: Not all versions match. Go matches, but Python (3.12.13 vs 3.12.3) and Node.js (v24.14.1 vs v20.20.2) differ between host and chroot environments.
|
Security Review:
|
🏗️ Build Test Suite Results
Overall: 8/8 ecosystems passed — ✅ PASS
|
Summary
Fixes toolchain environment variables (GOROOT, CARGO_HOME, JAVA_HOME, etc.) being lost when AWF runs via
sudo, which strips non-standard env vars.Problem
When
actions/setup-go(or setup-java, setup-dotnet, etc.) runs before AWF, it exportsGOROOTviacore.exportVariable(), which writes to the$GITHUB_ENVfile. The Actions runner injects these into the step env. Butsudo awf --env-allstrips them becausesudoonly preserves a small set of vars.AWF already solved this for
PATHviareadGitHubPathEntries()which reads$GITHUB_PATHdirectly. This PR adds the equivalent for$GITHUB_ENV.Changes
src/docker-manager.tsparseGitHubEnvFile(content)— Parses$GITHUB_ENVfile content. Supports bothKEY=VALUE(with=in values) and heredoc (KEY<<DELIM) formats. Handles CRLF.readGitHubEnvEntries()— Reads the file at$GITHUB_ENVpath, returns parsed key-value mapTOOLCHAIN_ENV_VARS— Allowlisted set:GOROOT,CARGO_HOME,RUSTUP_HOME,JAVA_HOME,DOTNET_ROOT,BUN_INSTALLif (process.env.X)blocks with a loop that falls back to$GITHUB_ENVwhenprocess.envis emptyTests (14 new)
parseGitHubEnvFile: simple values, values with=, heredoc, CRLF, mixed, empty, unterminated heredocreadGitHubEnvEntries: file missing, file exists, GITHUB_ENV unsetSecurity
The
$GITHUB_ENVfallback is narrowly allowlisted toTOOLCHAIN_ENV_VARSonly — it does NOT broadly merge all entries into the container env. This avoids reintroducing secrets or proxy settings that sudo intentionally stripped.Closes #1958