Skip to content

Allow to overwrite ACTIONS_CACHE_URL environment variable - #3906

Closed
dawidmalina wants to merge 1 commit into
actions:mainfrom
dawidmalina:custom-cache-url
Closed

dawidmalina wants to merge 1 commit into
actions:mainfrom
dawidmalina:custom-cache-url

Conversation

@dawidmalina

Copy link
Copy Markdown

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.

Copilot AI review requested due to automatic review settings June 11, 2025 13:48
@dawidmalina
dawidmalina requested a review from a team as a code owner June 11, 2025 13:48
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.
@dawidmalina
dawidmalina deleted the custom-cache-url branch June 11, 2025 13:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_URL override 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_URL environment variable and describe its effect on cache URL resolution.
string customCacheUrl = System.Environment.GetEnvironmentVariable("CUSTOM_ACTIONS_CACHE_URL");

Comment on lines +58 to 66
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;
}

Copilot AI Jun 11, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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);

Copilot uses AI. Check for mistakes.
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");

Copilot AI Jun 11, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
string customCacheUrl = System.Environment.GetEnvironmentVariable("CUSTOM_ACTIONS_CACHE_URL");
string customCacheUrl = System.Environment.GetEnvironmentVariable(CustomActionsCacheUrlKey);

Copilot uses AI. Check for mistakes.
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.

3 participants