Skip to content

Commit

Permalink
Allow to overwrite ACTIONS_CACHE_URL environment variable
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
enescakir committed Jul 31, 2024
1 parent 1250684 commit e80a28b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/Runner.Worker/Handlers/ContainerActionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,13 @@ public async Task RunAsync(ActionRunStage stage)
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))

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;
}
Expand Down
8 changes: 7 additions & 1 deletion src/Runner.Worker/Handlers/NodeScriptActionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ public async Task RunAsync(ActionRunStage stage)
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))

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;
}
Expand Down

0 comments on commit e80a28b

Please sign in to comment.