Add ACTIONS_RUNTIME_TOKEN and runtime env vars to ScriptHandler#4325
Add ACTIONS_RUNTIME_TOKEN and runtime env vars to ScriptHandler#43250b01 wants to merge 2 commits intoactions:mainfrom
ACTIONS_RUNTIME_TOKEN and runtime env vars to ScriptHandler#4325Conversation
…ing NodeScriptActionHandler Agent-Logs-Url: https://github.com/0b01/runner/sessions/e1e389f7-0641-4766-a1e2-29342a652d09 Co-authored-by: 0b01 <1768528+0b01@users.noreply.github.com>
…ailable Add ACTIONS_RUNTIME_TOKEN and runtime env vars to ScriptHandler
There was a problem hiding this comment.
Pull request overview
This PR updates ScriptHandler to expose the same GitHub Actions Runtime environment variables that are already provided to Node/container actions, enabling run: steps and hook scripts to call runtime services (cache, artifacts/results, etc.).
Changes:
- Add
ACTIONS_RUNTIME_URLandACTIONS_RUNTIME_TOKENtoScriptHandlerenvironment setup. - Add optional runtime service URLs (
ACTIONS_CACHE_URL,ACTIONS_RESULTS_URL) sourced fromSystemVssConnectionendpoint data. - Align
ScriptHandlerordering with other handlers by setting runtime env vars beforeACTIONS_ID_TOKEN_REQUEST_*.
Show a summary per file
| File | Description |
|---|---|
| src/Runner.Worker/Handlers/ScriptHandler.cs | Adds Actions runtime env var injection for script execution environments. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 1
| // Add Actions Runtime server info | ||
| var systemConnection = ExecutionContext.Global.Endpoints.Single(x => string.Equals(x.Name, WellKnownServiceEndpointNames.SystemVssConnection, StringComparison.OrdinalIgnoreCase)); | ||
| Environment["ACTIONS_RUNTIME_URL"] = systemConnection.Url.AbsoluteUri; | ||
| Environment["ACTIONS_RUNTIME_TOKEN"] = systemConnection.Authorization.Parameters[EndpointAuthorizationParameters.AccessToken]; | ||
| if (systemConnection.Data.TryGetValue("CacheServerUrl", out var cacheUrl) && !string.IsNullOrEmpty(cacheUrl)) | ||
| { | ||
| Environment["ACTIONS_CACHE_URL"] = cacheUrl; | ||
| } | ||
| if (systemConnection.Data.TryGetValue("PipelinesServiceUrl", out var pipelinesServiceUrl) && !string.IsNullOrEmpty(pipelinesServiceUrl)) | ||
| { | ||
| Environment["ACTIONS_RUNTIME_URL"] = pipelinesServiceUrl; | ||
| } | ||
| if (systemConnection.Data.TryGetValue("GenerateIdTokenUrl", out var generateIdTokenUrl) && !string.IsNullOrEmpty(generateIdTokenUrl)) | ||
| { | ||
| Environment["ACTIONS_ID_TOKEN_REQUEST_URL"] = generateIdTokenUrl; | ||
| Environment["ACTIONS_ID_TOKEN_REQUEST_TOKEN"] = systemConnection.Authorization.Parameters[EndpointAuthorizationParameters.AccessToken]; | ||
| } | ||
| if (systemConnection.Data.TryGetValue("ResultsServiceUrl", out var resultsUrl) && !string.IsNullOrEmpty(resultsUrl)) | ||
| { | ||
| Environment["ACTIONS_RESULTS_URL"] = resultsUrl; | ||
| } |
There was a problem hiding this comment.
New runtime environment variable injection in ScriptHandler (ACTIONS_RUNTIME_URL/TOKEN/CACHE_URL/RESULTS_URL) changes observable behavior for run: steps and hook scripts, but there are no automated tests covering that these variables are set correctly from SystemVssConnection endpoint data. Please add an L0 test that constructs a ScriptHandler with a mocked ExecutionContext.Global.Endpoints (including CacheServerUrl/PipelinesServiceUrl/ResultsServiceUrl) and asserts the expected Environment entries are populated (and that PipelinesServiceUrl overrides ACTIONS_RUNTIME_URL when present).
ScriptHandlerwas missing the Actions Runtime environment variables (ACTIONS_RUNTIME_URL,ACTIONS_RUNTIME_TOKEN,ACTIONS_CACHE_URL,ACTIONS_RESULTS_URL) thatNodeScriptActionHandlerandContainerActionHandleralready expose. This meant run: steps and hook scripts couldn't interact with Actions runtime services (such as caching, artifacts, etc.) the same way Node/container actions(such as@actions/upload-artifact) can.Added the same runtime env var block from
NodeScriptActionHandlerintoScriptHandler, placed before the existingACTIONS_ID_TOKEN_REQUEST_*setup similar toNodeScriptActionHandler.