Skip to content

Commit c18009c

Browse files
committed
Bitrise patches
1 parent 6680090 commit c18009c

6 files changed

Lines changed: 394 additions & 312 deletions

File tree

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
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+
token: ${{ secrets.RELEASE_PAT }}
21+
22+
- name: Sync upstream tags
23+
run: |
24+
git remote add upstream https://github.com/actions/runner.git
25+
git fetch upstream 'refs/tags/*:refs/tags/upstream/*'
26+
27+
- name: Save patch assets
28+
run: |
29+
# Copy CacheEnvironmentHelper.cs source to RUNNER_TEMP so it survives detached checkouts
30+
cp CacheEnvironmentHelper.cs "${RUNNER_TEMP}/CacheEnvironmentHelper.cs"
31+
cp bitrise.yml "${RUNNER_TEMP}/bitrise.yml"
32+
cp .github/workflows/release.yml "${RUNNER_TEMP}/release.yml"
33+
34+
- name: Find and patch new tags
35+
run: |
36+
git config user.name "bitrise-bot"
37+
git config user.email "bot@bitrise.io"
38+
39+
# Collect all upstream v* tags
40+
UPSTREAM_TAGS=$(git tag -l 'upstream/v*' | sed 's|^upstream/||' | sort -rV)
41+
42+
MAX_PATCHES=1
43+
PATCHED=0
44+
FAILED=0
45+
SKIPPED=0
46+
47+
for TAG in $UPSTREAM_TAGS; do
48+
if [ "${PATCHED}" -ge "${MAX_PATCHES}" ]; then
49+
echo "Reached patch limit (${MAX_PATCHES}), stopping. Remaining tags will be patched in the next run."
50+
break
51+
fi
52+
53+
PATCHED_TAG="${TAG}-bitrise"
54+
55+
# Check if we already have a release branch for this tag
56+
if git ls-remote --exit-code origin "refs/heads/releases/${PATCHED_TAG}" >/dev/null 2>&1; then
57+
SKIPPED=$((SKIPPED + 1))
58+
continue
59+
fi
60+
61+
echo "::group::Patching ${TAG} -> ${PATCHED_TAG}"
62+
63+
# Clean slate and checkout the upstream tag
64+
git reset --hard
65+
git clean -fd
66+
git checkout "upstream/${TAG}" --detach 2>&1
67+
68+
HANDLER_DIR="src/Runner.Worker/Handlers"
69+
CONTAINER_FILE="${HANDLER_DIR}/ContainerActionHandler.cs"
70+
NODE_FILE="${HANDLER_DIR}/NodeScriptActionHandler.cs"
71+
HELPER_FILE="${HANDLER_DIR}/CacheEnvironmentHelper.cs"
72+
MARKER="CacheEnvironmentHelper.OverrideCacheEnvironment"
73+
74+
# Skip if the patch is already present (e.g. future upstream adoption)
75+
if grep -q "${MARKER}" "${CONTAINER_FILE}" 2>/dev/null; then
76+
echo "Patch already present in ${TAG} — skipping"
77+
SKIPPED=$((SKIPPED + 1))
78+
echo "::endgroup::"
79+
continue
80+
fi
81+
82+
# Check that anchor patterns exist
83+
if ! grep -q 'foreach (var variable in this\.Environment)' "${CONTAINER_FILE}" 2>/dev/null || \
84+
! grep -q '// Resolve the target script' "${NODE_FILE}" 2>/dev/null; then
85+
echo "::warning::Anchor pattern not found in ${TAG} — skipping"
86+
FAILED=$((FAILED + 1))
87+
echo "::endgroup::"
88+
continue
89+
fi
90+
91+
# 1. Create CacheEnvironmentHelper.cs from the patch file
92+
cp "${RUNNER_TEMP}/CacheEnvironmentHelper.cs" "${HELPER_FILE}"
93+
cp "${RUNNER_TEMP}/bitrise.yml" .
94+
95+
# 2. Insert cache override call into ContainerActionHandler.cs
96+
# Anchor: "foreach (var variable in this.Environment)"
97+
awk '/foreach \(var variable in this\.Environment\)/{
98+
print " // Apply Cache URL overrides"
99+
print " CacheEnvironmentHelper.OverrideCacheEnvironment(Environment);"
100+
print ""
101+
}1' "${CONTAINER_FILE}" > tmp && mv tmp "${CONTAINER_FILE}"
102+
103+
# 3. Insert cache override call into NodeScriptActionHandler.cs
104+
# Anchor: "// Resolve the target script."
105+
awk '/\/\/ Resolve the target script\./{
106+
print " // Apply Cache URL overrides"
107+
print " CacheEnvironmentHelper.OverrideCacheEnvironment(Environment);"
108+
print ""
109+
}1' "${NODE_FILE}" > tmp && mv tmp "${NODE_FILE}"
110+
111+
# 4. Replace .github/workflows/release.yml with our version
112+
cp "${RUNNER_TEMP}/release.yml" .github/workflows/release.yml
113+
114+
# 5. Remove upstream CI/CD workflows
115+
rm -f .github/workflows/build.yml
116+
rm -f .github/workflows/release.yml
117+
118+
# 6. Commit, tag, push
119+
git add -A
120+
git commit -m "Bitrise cache integration (patched from ${TAG})"
121+
122+
git checkout -b "releases/${PATCHED_TAG}"
123+
124+
if git push origin "releases/${PATCHED_TAG}"; then
125+
echo "Successfully pushed to release/${PATCHED_TAG} branch"
126+
PATCHED=$((PATCHED + 1))
127+
else
128+
echo "::warning::Push failed for ${PATCHED_TAG}"
129+
FAILED=$((FAILED + 1))
130+
fi
131+
132+
echo "::endgroup::"
133+
done
134+
135+
echo ""
136+
echo "=== Summary ==="
137+
echo "Patched: ${PATCHED}"
138+
echo "Skipped (already exist): ${SKIPPED}"
139+
echo "Failed: ${FAILED}"
140+
141+
if [ "${FAILED}" -gt 0 ]; then
142+
echo "::warning::${FAILED} tag(s) failed to patch. Check the log above for details."
143+
fi

.github/workflows/build.yml

Lines changed: 0 additions & 130 deletions
This file was deleted.

.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'

0 commit comments

Comments
 (0)