|
| 1 | +From b799451657f1666717f6661ca8079da95ade7922 Mon Sep 17 00:00:00 2001 |
| 2 | +From: ramil-bitrise <ramil.ianbulatov@bitrise.io> |
| 3 | +Date: Wed, 11 Feb 2026 19:01:24 +0200 |
| 4 | +Subject: [PATCH] Bitrise cache integration |
| 5 | + |
| 6 | +--- |
| 7 | + .../Handlers/CacheEnvironmentHelper.cs | 49 +++++++++++++++++++ |
| 8 | + .../Handlers/ContainerActionHandler.cs | 5 +- |
| 9 | + .../Handlers/NodeScriptActionHandler.cs | 5 +- |
| 10 | + 3 files changed, 57 insertions(+), 2 deletions(-) |
| 11 | + create mode 100644 src/Runner.Worker/Handlers/CacheEnvironmentHelper.cs |
| 12 | + |
| 13 | +diff --git a/src/Runner.Worker/Handlers/CacheEnvironmentHelper.cs b/src/Runner.Worker/Handlers/CacheEnvironmentHelper.cs |
| 14 | +new file mode 100644 |
| 15 | +index 00000000..9db97b65 |
| 16 | +--- /dev/null |
| 17 | ++++ b/src/Runner.Worker/Handlers/CacheEnvironmentHelper.cs |
| 18 | +@@ -0,0 +1,49 @@ |
| 19 | ++using System; |
| 20 | ++using System.Collections.Generic; |
| 21 | ++ |
| 22 | ++namespace GitHub.Runner.Worker.Handlers |
| 23 | ++{ |
| 24 | ++ /// <summary> |
| 25 | ++ /// Helper to override ACTIONS_CACHE_URL and ACTIONS_RESULTS_URL environment variables |
| 26 | ++ /// with values from the actual process environment (e.g. set by the cache proxy), |
| 27 | ++ /// while preserving the original values for downstream use. |
| 28 | ++ /// </summary> |
| 29 | ++ public static class CacheEnvironmentHelper |
| 30 | ++ { |
| 31 | ++ /// <summary> |
| 32 | ++ /// Saves the current values of ACTIONS_CACHE_URL and ACTIONS_RESULTS_URL into |
| 33 | ++ /// ACTIONS_CACHE_URL_ORIGINAL and ACTIONS_RESULTS_URL_ORIGINAL, then overrides |
| 34 | ++ /// them with values from the actual process environment variables. |
| 35 | ++ /// Also sets ACTIONS_CACHE_SERVICE_V2 to "true". |
| 36 | ++ /// </summary> |
| 37 | ++ public static void OverrideCacheEnvironment(Dictionary<string, string> environment) |
| 38 | ++ { |
| 39 | ++ // Save original values so the cache proxy (or other consumers) can reach the real backend |
| 40 | ++ if (environment.TryGetValue("ACTIONS_CACHE_URL", out var originalCacheUrl)) |
| 41 | ++ { |
| 42 | ++ environment["ACTIONS_CACHE_URL_ORIGINAL"] = originalCacheUrl; |
| 43 | ++ } |
| 44 | ++ |
| 45 | ++ if (environment.TryGetValue("ACTIONS_RESULTS_URL", out var originalResultsUrl)) |
| 46 | ++ { |
| 47 | ++ environment["ACTIONS_RESULTS_URL_ORIGINAL"] = originalResultsUrl; |
| 48 | ++ } |
| 49 | ++ |
| 50 | ++ // Override with values from the process environment (set by the cache proxy) |
| 51 | ++ var envCacheUrl = System.Environment.GetEnvironmentVariable("ACTIONS_CACHE_URL"); |
| 52 | ++ if (!string.IsNullOrEmpty(envCacheUrl)) |
| 53 | ++ { |
| 54 | ++ environment["ACTIONS_CACHE_URL"] = envCacheUrl; |
| 55 | ++ } |
| 56 | ++ |
| 57 | ++ var envResultsUrl = System.Environment.GetEnvironmentVariable("ACTIONS_RESULTS_URL"); |
| 58 | ++ if (!string.IsNullOrEmpty(envResultsUrl)) |
| 59 | ++ { |
| 60 | ++ environment["ACTIONS_RESULTS_URL"] = envResultsUrl; |
| 61 | ++ } |
| 62 | ++ |
| 63 | ++ // Enable cache service v2 |
| 64 | ++ environment["ACTIONS_CACHE_SERVICE_V2"] = "true"; |
| 65 | ++ } |
| 66 | ++ } |
| 67 | ++} |
| 68 | +diff --git a/src/Runner.Worker/Handlers/ContainerActionHandler.cs b/src/Runner.Worker/Handlers/ContainerActionHandler.cs |
| 69 | +index 1f67c9dd..6aa872a3 100644 |
| 70 | +--- a/src/Runner.Worker/Handlers/ContainerActionHandler.cs |
| 71 | ++++ b/src/Runner.Worker/Handlers/ContainerActionHandler.cs |
| 72 | +@@ -1,4 +1,4 @@ |
| 73 | +-using System; |
| 74 | ++using System; |
| 75 | + using System.Collections.Generic; |
| 76 | + using System.IO; |
| 77 | + using System.Linq; |
| 78 | +@@ -247,6 +247,9 @@ namespace GitHub.Runner.Worker.Handlers |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | ++ // Apply Cache URL overrides |
| 83 | ++ CacheEnvironmentHelper.OverrideCacheEnvironment(Environment); |
| 84 | ++ |
| 85 | + foreach (var variable in this.Environment) |
| 86 | + { |
| 87 | + container.ContainerEnvironmentVariables[variable.Key] = container.TranslateToContainerPath(variable.Value); |
| 88 | +diff --git a/src/Runner.Worker/Handlers/NodeScriptActionHandler.cs b/src/Runner.Worker/Handlers/NodeScriptActionHandler.cs |
| 89 | +index 668ca95f..7f07ec79 100644 |
| 90 | +--- a/src/Runner.Worker/Handlers/NodeScriptActionHandler.cs |
| 91 | ++++ b/src/Runner.Worker/Handlers/NodeScriptActionHandler.cs |
| 92 | +@@ -1,4 +1,4 @@ |
| 93 | +-using System; |
| 94 | ++using System; |
| 95 | + using System.Collections.Generic; |
| 96 | + using System.IO; |
| 97 | + using System.Linq; |
| 98 | +@@ -85,6 +85,9 @@ namespace GitHub.Runner.Worker.Handlers |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | ++ // Apply Cache URL overrides |
| 103 | ++ CacheEnvironmentHelper.OverrideCacheEnvironment(Environment); |
| 104 | ++ |
| 105 | + // Resolve the target script. |
| 106 | + string target = null; |
| 107 | + if (stage == ActionRunStage.Main) |
| 108 | +-- |
| 109 | +2.39.5 (Apple Git-154) |
| 110 | + |
0 commit comments