Repository navigation
Allow to overwrite ACTIONS_CACHE_URL environment variable - #3906
dawidmalina wants to merge 1 commit into
Conversation
The runner script sets the `ACTIONS_CACHE_URL` using the value from the system connection. Currently, there's no way to override it. Some community users use custom cache solutions with self-hosted runners. They need to maintain a fork of `actions/runner` or `actions/toolkit`, and `actions/cache` to override the value in their solution. However it leads to significant maintenance work. If the runner script allows the `ACTIONS_CACHE_URL` value to be overridden by the `CUSTOM_ACTIONS_CACHE_URL` environment variable, it makes life a lot easier for the community, includes myself. An alternative solution could involve allowing the base URL value in `actions/toolkit` to be overridden. Several individuals have submitted similar PRs to this one actions/toolkit#1695, but they have not received adequate attention from the maintainers.
f25bf83 to
335cda5
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR enables users to override the ACTIONS_CACHE_URL via a new CUSTOM_ACTIONS_CACHE_URL environment variable before falling back to the system connection’s cache server URL.
- Add override logic in NodeScriptActionHandler
- Add override logic in ContainerActionHandler
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Runner.Worker/Handlers/NodeScriptActionHandler.cs | Inject CUSTOM_ACTIONS_CACHE_URL override before using system cache URL |
| src/Runner.Worker/Handlers/ContainerActionHandler.cs | Inject CUSTOM_ACTIONS_CACHE_URL override before using system cache URL |
Comments suppressed due to low confidence (2)
src/Runner.Worker/Handlers/NodeScriptActionHandler.cs:58
- There are no tests covering the new
CUSTOM_ACTIONS_CACHE_URLoverride behavior; adding unit or integration tests would help ensure this feature stays correct over time.
string customCacheUrl = System.Environment.GetEnvironmentVariable("CUSTOM_ACTIONS_CACHE_URL");
src/Runner.Worker/Handlers/NodeScriptActionHandler.cs:58
- Update the project documentation or README to mention the
CUSTOM_ACTIONS_CACHE_URLenvironment variable and describe its effect on cache URL resolution.
string customCacheUrl = System.Environment.GetEnvironmentVariable("CUSTOM_ACTIONS_CACHE_URL");
| string customCacheUrl = System.Environment.GetEnvironmentVariable("CUSTOM_ACTIONS_CACHE_URL"); | ||
| if (!string.IsNullOrEmpty(customCacheUrl)) | ||
| { | ||
| Environment["ACTIONS_CACHE_URL"] = customCacheUrl; | ||
| } | ||
| else if (systemConnection.Data.TryGetValue("CacheServerUrl", out var cacheUrl) && !string.IsNullOrEmpty(cacheUrl)) | ||
| { | ||
| Environment["ACTIONS_CACHE_URL"] = cacheUrl; | ||
| } |
There was a problem hiding this comment.
The override logic for ACTIONS_CACHE_URL is duplicated in multiple handlers; consider extracting it into a shared helper method to reduce code duplication and ease future updates.
| string customCacheUrl = System.Environment.GetEnvironmentVariable("CUSTOM_ACTIONS_CACHE_URL"); | |
| if (!string.IsNullOrEmpty(customCacheUrl)) | |
| { | |
| Environment["ACTIONS_CACHE_URL"] = customCacheUrl; | |
| } | |
| else if (systemConnection.Data.TryGetValue("CacheServerUrl", out var cacheUrl) && !string.IsNullOrEmpty(cacheUrl)) | |
| { | |
| Environment["ACTIONS_CACHE_URL"] = cacheUrl; | |
| } | |
| Environment["ACTIONS_CACHE_URL"] = GetActionsCacheUrl(systemConnection); |
| Environment["ACTIONS_RUNTIME_TOKEN"] = systemConnection.Authorization.Parameters[EndpointAuthorizationParameters.AccessToken]; | ||
| if (systemConnection.Data.TryGetValue("CacheServerUrl", out var cacheUrl) && !string.IsNullOrEmpty(cacheUrl)) | ||
|
|
||
| string customCacheUrl = System.Environment.GetEnvironmentVariable("CUSTOM_ACTIONS_CACHE_URL"); |
There was a problem hiding this comment.
Consider defining CUSTOM_ACTIONS_CACHE_URL as a constant or configuration key in a central class rather than using a string literal, to avoid typos and improve discoverability.
| string customCacheUrl = System.Environment.GetEnvironmentVariable("CUSTOM_ACTIONS_CACHE_URL"); | |
| string customCacheUrl = System.Environment.GetEnvironmentVariable(CustomActionsCacheUrlKey); |
The runner script sets the
ACTIONS_CACHE_URLusing the value from the system connection. Currently, there's no way to override it.Some community users use custom cache solutions with self-hosted runners. They need to maintain a fork of
actions/runneroractions/toolkit, andactions/cacheto override the value in their solution. However it leads to significant maintenance work.If the runner script allows the
ACTIONS_CACHE_URLvalue to be overridden by theCUSTOM_ACTIONS_CACHE_URLenvironment variable, it makes life a lot easier for the community, includes myself.An alternative solution could involve allowing the base URL value in
actions/toolkitto be overridden. Several individuals have submitted similar PRs to this one actions/toolkit#1695, but they have not received adequate attention from the maintainers.