Skip to content

Commit ef873ed

Browse files
ci: offload owner server tests to isolated Linux capacity
1 parent 4a4a480 commit ef873ed

3 files changed

Lines changed: 172 additions & 12 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Server CI
2+
description: Run the server suite on a hosted shard or an isolated Linux worker.
3+
inputs:
4+
shard:
5+
description: Optional Vitest shard, such as 1/8
6+
default: ""
7+
max-workers:
8+
description: Optional Vitest worker limit
9+
default: ""
10+
runs:
11+
using: composite
12+
steps:
13+
- uses: ./.github/actions/setup-ci-deps
14+
- name: Setup Rust
15+
uses: dtolnay/rust-toolchain@6bed0761d98439e5a578e2877258200ad565ba87
16+
with:
17+
toolchain: stable
18+
- name: Install Chromium
19+
shell: bash
20+
run: node apps/server/node_modules/playwright-core/cli.js install --with-deps --only-shell chromium
21+
- name: Test server
22+
shell: bash
23+
env:
24+
TEST_SHARD: ${{ inputs.shard }}
25+
MAX_WORKERS: ${{ inputs.max-workers }}
26+
run: |
27+
args=()
28+
if [[ -n "$TEST_SHARD" ]]; then
29+
[[ "$TEST_SHARD" =~ ^[1-9][0-9]*/[1-9][0-9]*$ ]]
30+
args+=(--shard "$TEST_SHARD")
31+
fi
32+
if [[ -n "$MAX_WORKERS" ]]; then
33+
[[ "$MAX_WORKERS" =~ ^[1-9][0-9]*$ ]]
34+
args+=(--maxWorkers "$MAX_WORKERS")
35+
fi
36+
vp run --filter t3 test "${args[@]}"
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import json
2+
import os
3+
from pathlib import Path
4+
import re
5+
import subprocess
6+
import tempfile
7+
import textwrap
8+
import unittest
9+
10+
WORKFLOW = Path(__file__).parents[1] / 'workflows' / 'fork-ci.yml'
11+
TEXT = WORKFLOW.read_text()
12+
13+
14+
def job(name):
15+
return re.search(rf'^ {name}:\n(.*?)(?=^ [\w-]+:|\Z)', TEXT, re.M | re.S)[1]
16+
17+
18+
def run_block(text):
19+
return textwrap.dedent(text.split(' run: |\n')[-1])
20+
21+
22+
class RoutingTests(unittest.TestCase):
23+
def request(self, server_tests, exit_code):
24+
with tempfile.TemporaryDirectory() as directory:
25+
output = Path(directory) / 'output'
26+
output.touch()
27+
script = f'gh() {{ return {exit_code}; }}\n' + run_block(job('private-linux-status'))
28+
result = subprocess.run(['bash', '-e', '-c', script], capture_output=True, text=True,
29+
env={**os.environ, 'SERVER_TESTS': server_tests, 'SOURCE_SHA': 'a' * 40,
30+
'GITHUB_OUTPUT': str(output), 'GITHUB_REPOSITORY': 'ScriptedAlchemy/t3code',
31+
'GITHUB_RUN_ID': '123', 'GITHUB_RUN_ATTEMPT': '1',
32+
'GITHUB_SERVER_URL': 'https://github.com'})
33+
return result.returncode, output.read_text()
34+
35+
def test_request_publishes_only_after_success(self):
36+
self.assertEqual(self.request('true', 0), (0, 'enabled=true\n'))
37+
code, output = self.request('true', 1)
38+
self.assertNotEqual(code, 0)
39+
self.assertEqual(output, '')
40+
self.assertEqual(self.request('false', 0), (0, 'enabled=false\n'))
41+
42+
def test_hosted_server_falls_back_on_failed_or_skipped_request(self):
43+
expression = re.search(r' if: >-\n(.*?)(?= runs-on:)', job('server'), re.S)[1].strip()
44+
expression = expression.replace('needs.private-linux-status', 'needs["private-linux-status"]')
45+
for result, enabled, tests, cancelled, expected in [
46+
('success', 'true', 'true', False, False),
47+
('failure', '', 'true', False, True),
48+
('failure', 'true', 'true', False, True),
49+
('skipped', '', 'true', False, True),
50+
('success', 'false', 'true', False, True),
51+
('skipped', '', 'false', False, False),
52+
('failure', '', 'true', True, False),
53+
]:
54+
with self.subTest(result=result, enabled=enabled, tests=tests, cancelled=cancelled):
55+
needs = {'changes': {'outputs': {'test_server': tests}},
56+
'private-linux-status': {'result': result, 'outputs': {'enabled': enabled}}}
57+
script = f'const needs={json.dumps(needs)}; const cancelled=()=>{str(cancelled).lower()}; console.log(Boolean({expression}));'
58+
actual = subprocess.check_output(['node', '-e', script], text=True).strip()
59+
self.assertEqual(actual, str(expected).lower())
60+
61+
def test_aggregate_requires_server_or_acknowledged_private_route(self):
62+
for private_result, enabled, server_result, expected in [
63+
('success', 'true', 'skipped', True),
64+
('skipped', '', 'success', True),
65+
('success', 'false', 'skipped', False),
66+
('failure', 'true', 'skipped', False),
67+
('success', 'true', 'failure', False),
68+
]:
69+
with self.subTest(private=private_result, enabled=enabled, server=server_result):
70+
needs = {k: {'result': 'success'} for k in ['checks', 'clients', 'rust', 'mobile_native']}
71+
needs['changes'] = {'result': 'success', 'outputs': {'test_server': 'true'}}
72+
needs['private-linux-status'] = {'result': private_result, 'outputs': {'enabled': enabled}}
73+
needs['server'] = {'result': server_result}
74+
result = subprocess.run(['bash', '-e', '-c', run_block(job('check'))],
75+
env={**os.environ, 'RESULTS': json.dumps(needs)}, capture_output=True)
76+
self.assertEqual(result.returncode == 0, expected)
77+
78+
def test_privileged_request_never_checks_out_source(self):
79+
request = job('private-linux-status')
80+
self.assertNotRegex(request, r'(?m)^\s+-?\s*uses:')
81+
self.assertIn("github.actor_id == '25274700'", request)
82+
self.assertIn("github.triggering_actor == 'ScriptedAlchemy'", request)
83+
self.assertIn('github.event.pull_request.head.repo.full_name == github.repository', request)
84+
self.assertNotIn('statuses: write', job('changes'))
85+
86+
87+
if __name__ == '__main__':
88+
unittest.main()

‎.github/workflows/fork-ci.yml‎

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ jobs:
4545
- name: Check workflow runner labels
4646
run: |
4747
python3 -B .github/scripts/check-runner-labels.test.py
48+
python3 -B .github/scripts/private-linux-routing.test.py
4849
python3 -B .github/scripts/check-runner-labels.py
4950
5051
- name: Detect affected jobs
@@ -143,10 +144,48 @@ jobs:
143144
if: needs.changes.outputs.test_web != 'false'
144145
run: vp run --filter @t3tools/web test
145146

147+
private-linux-status:
148+
name: Request private server tests
149+
needs: changes
150+
runs-on: ubuntu-24.04
151+
timeout-minutes: 5
152+
permissions:
153+
contents: read
154+
statuses: write
155+
outputs:
156+
enabled: ${{ steps.request.outputs.enabled }}
157+
if: >-
158+
!cancelled() && vars.PRIVATE_LINUX_CI == 'true' &&
159+
github.actor_id == '25274700' && github.triggering_actor == 'ScriptedAlchemy' &&
160+
(github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
161+
steps:
162+
- name: Request private server capacity
163+
id: request
164+
env:
165+
GH_TOKEN: ${{ github.token }}
166+
SERVER_TESTS: ${{ needs.changes.outputs.test_server }}
167+
SOURCE_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
168+
run: |
169+
set -euo pipefail
170+
enabled=false
171+
state=success
172+
description='Hosted Linux CI selected'
173+
if [[ "$SERVER_TESTS" != false ]]; then
174+
enabled=true
175+
state=pending
176+
description="Requested private-linux:$GITHUB_REPOSITORY:$GITHUB_RUN_ID:$GITHUB_RUN_ATTEMPT:full"
177+
fi
178+
gh api --method POST "repos/$GITHUB_REPOSITORY/statuses/$SOURCE_SHA" \
179+
-f state="$state" -f context='Private Linux CI' -f description="$description" \
180+
-f target_url="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
181+
echo "enabled=$enabled" >> "$GITHUB_OUTPUT"
182+
146183
server:
147184
name: Server tests ${{ matrix.shard }}
148-
needs: changes
149-
if: needs.changes.outputs.test_server != 'false'
185+
needs: [changes, private-linux-status]
186+
if: >-
187+
!cancelled() && needs.changes.outputs.test_server != 'false' &&
188+
!(needs.private-linux-status.result == 'success' && needs.private-linux-status.outputs.enabled == 'true')
150189
runs-on: ubuntu-24.04
151190
timeout-minutes: 30
152191
strategy:
@@ -163,15 +202,9 @@ jobs:
163202
git fetch --no-tags --depth=2 origin "$GITHUB_SHA"
164203
git sparse-checkout set --no-cone '/*' '!/.repos/' '!/apps/mobile/modules/t3-terminal/Vendor/**/*.a'
165204
git checkout --detach FETCH_HEAD
166-
- uses: ./.github/actions/setup-ci-deps
167-
- name: Setup Rust
168-
uses: dtolnay/rust-toolchain@6bed0761d98439e5a578e2877258200ad565ba87 # stable
205+
- uses: ./.github/actions/server-ci
169206
with:
170-
toolchain: stable
171-
- name: Install Chromium
172-
run: node apps/server/node_modules/playwright-core/cli.js install --with-deps --only-shell chromium
173-
- name: Test server shard
174-
run: vp run --filter t3 test --shard ${{ matrix.shard }}/${{ strategy.job-total }}
207+
shard: ${{ matrix.shard }}/${{ strategy.job-total }}
175208

176209
rust:
177210
name: Rust
@@ -237,7 +270,7 @@ jobs:
237270
check:
238271
name: Fork Check
239272
if: ${{ !cancelled() && github.repository != 'pingdotgg/t3code' }}
240-
needs: [changes, checks, clients, server, rust, mobile_native]
273+
needs: [changes, private-linux-status, checks, clients, server, rust, mobile_native]
241274
runs-on: ubuntu-24.04
242275
timeout-minutes: 5
243276
steps:
@@ -246,9 +279,12 @@ jobs:
246279
RESULTS: ${{ toJSON(needs) }}
247280
run: |
248281
echo "$RESULTS" | jq -r 'to_entries[] | "\(.key): \(.value.result)"'
249-
echo "$RESULTS" | jq -e '.changes.outputs as $gates
282+
echo "$RESULTS" | jq -e '(."private-linux-status".result == "success" and ."private-linux-status".outputs.enabled == "true") as $private
283+
| .changes.outputs as $gates
250284
| {clients: ["test", "test_web"], server: ["test_server"]} as $renamed
251285
| all(to_entries[];
252286
.value.result == "success"
287+
or (.key == "private-linux-status" and .value.result == "skipped")
288+
or (.key == "server" and .value.result == "skipped" and $private)
253289
or (.value.result == "skipped"
254290
and (($renamed[.key] // [.key]) | all(.[]; $gates[.] == "false"))))' > /dev/null

0 commit comments

Comments
 (0)