Skip to content

Commit 430a5e0

Browse files
committed
Add auto-patch workflow and bitrise-cache.patch
1 parent 15cb558 commit 430a5e0

2 files changed

Lines changed: 190 additions & 0 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Auto-patch upstream runner tags
2+
3+
on:
4+
schedule:
5+
- cron: '0 6 * * *' # daily at 06:00 UTC
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
patch-and-tag:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout repo with full history and tags
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
fetch-tags: true
20+
21+
- name: Sync upstream tags
22+
run: |
23+
git remote add upstream https://github.com/actions/runner.git
24+
git fetch upstream 'refs/tags/*:refs/tags/upstream/*'
25+
26+
- name: Find and patch new tags
27+
run: |
28+
git config user.name "bitrise-bot"
29+
git config user.email "bot@bitrise.io"
30+
31+
# Collect all upstream v* tags
32+
UPSTREAM_TAGS=$(git tag -l 'upstream/v*' | sed 's|^upstream/||' | sort -V)
33+
34+
PATCHED=0
35+
FAILED=0
36+
SKIPPED=0
37+
38+
for TAG in $UPSTREAM_TAGS; do
39+
PATCHED_TAG="${TAG}-bitrise"
40+
41+
# Check if we already have this patched tag
42+
if git rev-parse "refs/tags/${PATCHED_TAG}" >/dev/null 2>&1; then
43+
SKIPPED=$((SKIPPED + 1))
44+
continue
45+
fi
46+
47+
echo "::group::Patching ${TAG} -> ${PATCHED_TAG}"
48+
49+
# Checkout the upstream tag in a detached HEAD
50+
git checkout "upstream/${TAG}" --detach 2>&1
51+
52+
# Apply the Bitrise cache patch
53+
if git am "${{ github.workspace }}/bitrise-cache.patch"; then
54+
git tag "${PATCHED_TAG}"
55+
56+
if git push origin "${PATCHED_TAG}"; then
57+
echo "Successfully tagged and pushed ${PATCHED_TAG}"
58+
PATCHED=$((PATCHED + 1))
59+
else
60+
echo "::warning::Push failed for ${PATCHED_TAG}"
61+
FAILED=$((FAILED + 1))
62+
fi
63+
else
64+
echo "::warning::Patch failed to apply on ${TAG} — manual intervention required"
65+
git am --abort || true
66+
FAILED=$((FAILED + 1))
67+
fi
68+
69+
echo "::endgroup::"
70+
done
71+
72+
echo ""
73+
echo "=== Summary ==="
74+
echo "Patched: ${PATCHED}"
75+
echo "Skipped (already exist): ${SKIPPED}"
76+
echo "Failed: ${FAILED}"
77+
78+
if [ "${FAILED}" -gt 0 ]; then
79+
echo "::warning::${FAILED} tag(s) failed to patch. Check the log above for details."
80+
fi

bitrise-cache.patch

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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

Comments
 (0)