Skip to content

Commit c09a7fc

Browse files
committed
Bitrise patches
1 parent 6680090 commit c09a7fc

4 files changed

Lines changed: 292 additions & 4 deletions

File tree

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
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: Save patch assets
27+
run: |
28+
# Save CacheEnvironmentHelper.cs to RUNNER_TEMP so it survives detached checkouts
29+
cat > "${RUNNER_TEMP}/CacheEnvironmentHelper.cs" << 'CSHARP'
30+
using System;
31+
using System.Collections.Generic;
32+
33+
namespace GitHub.Runner.Worker.Handlers
34+
{
35+
/// <summary>
36+
/// Helper to override ACTIONS_CACHE_URL and ACTIONS_RESULTS_URL environment variables
37+
/// with values from the actual process environment (e.g. set by the cache proxy),
38+
/// while preserving the original values for downstream use.
39+
/// </summary>
40+
public static class CacheEnvironmentHelper
41+
{
42+
/// <summary>
43+
/// Saves the current values of ACTIONS_CACHE_URL and ACTIONS_RESULTS_URL into
44+
/// ACTIONS_CACHE_URL_ORIGINAL and ACTIONS_RESULTS_URL_ORIGINAL, then overrides
45+
/// them with values from the actual process environment variables.
46+
/// Also sets ACTIONS_CACHE_SERVICE_V2 to "true".
47+
/// </summary>
48+
public static void OverrideCacheEnvironment(Dictionary<string, string> environment)
49+
{
50+
// Save original values so the cache proxy (or other consumers) can reach the real backend
51+
if (environment.TryGetValue("ACTIONS_CACHE_URL", out var originalCacheUrl))
52+
{
53+
environment["ACTIONS_CACHE_URL_ORIGINAL"] = originalCacheUrl;
54+
}
55+
56+
if (environment.TryGetValue("ACTIONS_RESULTS_URL", out var originalResultsUrl))
57+
{
58+
environment["ACTIONS_RESULTS_URL_ORIGINAL"] = originalResultsUrl;
59+
}
60+
61+
// Override with values from the process environment (set by the cache proxy)
62+
var envCacheUrl = System.Environment.GetEnvironmentVariable("ACTIONS_CACHE_URL");
63+
if (!string.IsNullOrEmpty(envCacheUrl))
64+
{
65+
environment["ACTIONS_CACHE_URL"] = envCacheUrl;
66+
}
67+
68+
var envResultsUrl = System.Environment.GetEnvironmentVariable("ACTIONS_RESULTS_URL");
69+
if (!string.IsNullOrEmpty(envResultsUrl))
70+
{
71+
environment["ACTIONS_RESULTS_URL"] = envResultsUrl;
72+
}
73+
74+
// Enable cache service v2
75+
environment["ACTIONS_CACHE_SERVICE_V2"] = "true";
76+
}
77+
}
78+
}
79+
CSHARP
80+
81+
# Strip the leading 10-space YAML indentation from the heredoc
82+
sed -i 's/^ //' "${RUNNER_TEMP}/CacheEnvironmentHelper.cs"
83+
84+
- name: Find and patch new tags
85+
run: |
86+
git config user.name "bitrise-bot"
87+
git config user.email "bot@bitrise.io"
88+
89+
# Collect all upstream v* tags
90+
UPSTREAM_TAGS=$(git tag -l 'upstream/v*' | sed 's|^upstream/||' | sort -V)
91+
92+
PATCHED=0
93+
FAILED=0
94+
SKIPPED=0
95+
96+
for TAG in $UPSTREAM_TAGS; do
97+
PATCHED_TAG="${TAG}-bitrise"
98+
99+
# Check if we already have this patched tag
100+
if git rev-parse "refs/tags/${PATCHED_TAG}" >/dev/null 2>&1; then
101+
SKIPPED=$((SKIPPED + 1))
102+
continue
103+
fi
104+
105+
echo "::group::Patching ${TAG} -> ${PATCHED_TAG}"
106+
107+
# Clean slate and checkout the upstream tag
108+
git reset --hard
109+
git clean -fd
110+
git checkout "upstream/${TAG}" --detach 2>&1
111+
112+
HANDLER_DIR="src/Runner.Worker/Handlers"
113+
CONTAINER_FILE="${HANDLER_DIR}/ContainerActionHandler.cs"
114+
NODE_FILE="${HANDLER_DIR}/NodeScriptActionHandler.cs"
115+
HELPER_FILE="${HANDLER_DIR}/CacheEnvironmentHelper.cs"
116+
MARKER="CacheEnvironmentHelper.OverrideCacheEnvironment"
117+
118+
# Skip if the patch is already present (e.g. future upstream adoption)
119+
if grep -q "${MARKER}" "${CONTAINER_FILE}" 2>/dev/null; then
120+
echo "Patch already present in ${TAG} — skipping"
121+
SKIPPED=$((SKIPPED + 1))
122+
echo "::endgroup::"
123+
continue
124+
fi
125+
126+
# Check that anchor patterns exist
127+
if ! grep -q 'foreach (var variable in this\.Environment)' "${CONTAINER_FILE}" 2>/dev/null || \
128+
! grep -q '// Resolve the target script' "${NODE_FILE}" 2>/dev/null; then
129+
echo "::warning::Anchor pattern not found in ${TAG} — skipping"
130+
FAILED=$((FAILED + 1))
131+
echo "::endgroup::"
132+
continue
133+
fi
134+
135+
# 1. Create CacheEnvironmentHelper.cs
136+
cp "${RUNNER_TEMP}/CacheEnvironmentHelper.cs" "${HELPER_FILE}"
137+
138+
# 2. Insert cache override call into ContainerActionHandler.cs
139+
# Anchor: "foreach (var variable in this.Environment)"
140+
awk '/foreach \(var variable in this\.Environment\)/{
141+
print " // Apply Cache URL overrides"
142+
print " CacheEnvironmentHelper.OverrideCacheEnvironment(Environment);"
143+
print ""
144+
}1' "${CONTAINER_FILE}" > tmp && mv tmp "${CONTAINER_FILE}"
145+
146+
# 3. Insert cache override call into NodeScriptActionHandler.cs
147+
# Anchor: "// Resolve the target script."
148+
awk '/\/\/ Resolve the target script\./{
149+
print " // Apply Cache URL overrides"
150+
print " CacheEnvironmentHelper.OverrideCacheEnvironment(Environment);"
151+
print ""
152+
}1' "${NODE_FILE}" > tmp && mv tmp "${NODE_FILE}"
153+
154+
# 4. Remove .github/ so push doesn't require workflows permission
155+
rm -rf .github/
156+
157+
# 5. Commit, tag, push
158+
git add -A
159+
git commit -m "Bitrise cache integration (patched from ${TAG})"
160+
161+
git tag "${PATCHED_TAG}"
162+
163+
if git push origin "${PATCHED_TAG}"; then
164+
echo "Successfully tagged and pushed ${PATCHED_TAG}"
165+
PATCHED=$((PATCHED + 1))
166+
else
167+
echo "::warning::Push failed for ${PATCHED_TAG}"
168+
FAILED=$((FAILED + 1))
169+
fi
170+
171+
echo "::endgroup::"
172+
done
173+
174+
echo ""
175+
echo "=== Summary ==="
176+
echo "Patched: ${PATCHED}"
177+
echo "Skipped (already exist): ${SKIPPED}"
178+
echo "Failed: ${FAILED}"
179+
180+
if [ "${FAILED}" -gt 0 ]; then
181+
echo "::warning::${FAILED} tag(s) failed to patch. Check the log above for details."
182+
fi

.github/workflows/build.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
workflow_dispatch:
55
push:
66
branches:
7-
- main
87
- releases/*
98
paths-ignore:
109
- '**.md'

.github/workflows/codeql.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ permissions:
44
security-events: write
55

66
on:
7-
push:
8-
branches:
9-
- main
107
pull_request:
118
schedule:
129
- cron: '0 0 * * 0'

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)