mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-16 14:33:24 +09:00
[Fix] (CI): merge Arch WSL runner and prefer it over hosted runners
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Choose one execution platform for the entire Test artifact dependency graph."""
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
|
||||
NAME = "minipc-8845-arch-wsl-gpu"
|
||||
LABELS = ["self-hosted", "Linux", "X64", "arch", "wsl", "gpu", "gles", "vulkan"]
|
||||
|
||||
|
||||
def choose(runners):
|
||||
for runner in runners:
|
||||
labels = {label["name"].lower() for label in runner.get("labels", [])}
|
||||
if runner.get("name") == NAME and set(map(str.lower, LABELS)) <= labels:
|
||||
if runner.get("status") == "online":
|
||||
# Busy is still available: queue behind its current job.
|
||||
return LABELS, "arch-wsl", "preferred runner online (busy=%s)" % runner.get("busy", False)
|
||||
return ["ubuntu-latest"], "github", "preferred runner offline, absent, or missing required labels"
|
||||
|
||||
|
||||
def runner_inventory(repository, token):
|
||||
if not token:
|
||||
raise ValueError("Set RUNNER_STATUS_TOKEN with repository Administration: read; runner availability is unknown")
|
||||
runners = []
|
||||
page = 1
|
||||
while True:
|
||||
url = f"https://api.github.com/repos/{repository}/actions/runners?per_page=100&page={page}"
|
||||
request = urllib.request.Request(url, headers={
|
||||
"Authorization": "Bearer " + token,
|
||||
"Accept": "application/vnd.github+json",
|
||||
"X-GitHub-Api-Version": "2022-11-28",
|
||||
"User-Agent": "MobileGL-test-runner-selector",
|
||||
})
|
||||
with urllib.request.urlopen(request, timeout=20) as response:
|
||||
data = json.load(response)
|
||||
batch = data["runners"]
|
||||
runners.extend(batch)
|
||||
if len(batch) < 100:
|
||||
return runners
|
||||
page += 1
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
runners = runner_inventory(os.environ["GITHUB_REPOSITORY"], os.environ.get("RUNNER_STATUS_TOKEN", ""))
|
||||
labels, pool, reason = choose(runners)
|
||||
except (ValueError, KeyError, OSError, urllib.error.URLError) as error:
|
||||
# An API/auth error is not evidence that the machine is offline. Do not
|
||||
# silently send the whole matrix to GitHub when the status cannot be read.
|
||||
print(f"::error::Cannot determine runner availability: {error}", file=sys.stderr)
|
||||
return 1
|
||||
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as output:
|
||||
output.write("runner=" + json.dumps(labels) + "\npool=" + pool + "\n")
|
||||
print(f"Test runner: {pool}: {reason}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -44,7 +44,7 @@ def run_arm(build, out, case, forward):
|
||||
if Path('/usr/share/glvnd/egl_vendor.d/50_mesa.json').exists():
|
||||
env['__EGL_VENDOR_LIBRARY_FILENAMES'] = '/usr/share/glvnd/egl_vendor.d/50_mesa.json'
|
||||
if Path('/usr/share/vulkan/icd.d/lvp_icd.json').exists():
|
||||
env['VK_ICD_FILENAMES'] = '/usr/share/vulkan/icd.d/lvp_icd.json'
|
||||
env.setdefault('VK_ICD_FILENAMES', '/usr/share/vulkan/icd.d/lvp_icd.json')
|
||||
peer_env = dict(env, MOBILEGL_IPC_ROLE='server', MOBILEGL_IPC_DIAL='no',
|
||||
MOBILEGL_IPC_LOG_FORWARD=str(int(forward)), MOBILEGL_LOG_FILE_PATH=str(out / 'peer.log'))
|
||||
for name in ('MOBILEGL_TRANSPORT', 'MOBILEGL_IPC_SERVER_PATH', 'MOBILEGL_IPC_RING_MB', 'MOBILEGL_IPC_STAGE_MB'):
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env python3
|
||||
import contextlib
|
||||
import importlib.util
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
import urllib.error
|
||||
|
||||
spec = importlib.util.spec_from_file_location("selector", Path(__file__).with_name("select_test_runner.py"))
|
||||
selector = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(selector)
|
||||
|
||||
|
||||
def runner(status="online", busy=False):
|
||||
return {"name": selector.NAME, "status": status, "busy": busy,
|
||||
"labels": [{"name": label} for label in selector.LABELS]}
|
||||
|
||||
|
||||
class SelectRunnerTest(unittest.TestCase):
|
||||
def test_online_busy_and_idle_both_use_preferred(self):
|
||||
for busy in (False, True):
|
||||
labels, pool, _ = selector.choose([runner(busy=busy)])
|
||||
self.assertEqual(labels, selector.LABELS)
|
||||
self.assertEqual(pool, "arch-wsl")
|
||||
|
||||
def test_offline_or_absent_falls_back(self):
|
||||
for rows in ([], [runner("offline")]):
|
||||
self.assertEqual(selector.choose(rows)[:2], (["ubuntu-latest"], "github"))
|
||||
|
||||
def test_wrong_runner_or_missing_labels_cannot_queue_forever(self):
|
||||
wrong = runner()
|
||||
wrong["name"] = "another-machine"
|
||||
missing = runner()
|
||||
missing["labels"] = missing["labels"][:-1]
|
||||
for rows in ([wrong], [missing]):
|
||||
self.assertEqual(selector.choose(rows)[1], "github")
|
||||
|
||||
def test_inventory_reads_later_pages(self):
|
||||
pages = [io.StringIO(json.dumps({"runners": [{}] * 100})),
|
||||
io.StringIO(json.dumps({"runners": [runner()]}))]
|
||||
with patch.object(selector.urllib.request, "urlopen", side_effect=pages) as request:
|
||||
rows = selector.runner_inventory("owner/repo", "not-a-real-token")
|
||||
self.assertEqual(len(rows), 101)
|
||||
self.assertTrue(request.call_args.args[0].full_url.endswith("page=2"))
|
||||
|
||||
def test_auth_failure_does_not_masquerade_as_offline(self):
|
||||
for error in (ValueError("missing token"), urllib.error.HTTPError("url", 403, "Forbidden", {}, None)):
|
||||
with patch.dict(os.environ, {"GITHUB_REPOSITORY": "owner/repo"}), \
|
||||
patch.object(selector, "runner_inventory", side_effect=error), \
|
||||
contextlib.redirect_stderr(io.StringIO()):
|
||||
self.assertEqual(selector.main(), 1)
|
||||
|
||||
def test_outputs_are_valid_runs_on_json(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
path = Path(root) / "outputs"
|
||||
with patch.dict(os.environ, {"GITHUB_REPOSITORY": "owner/repo", "GITHUB_OUTPUT": str(path)}), \
|
||||
patch.object(selector, "runner_inventory", return_value=[runner()]), \
|
||||
contextlib.redirect_stdout(io.StringIO()):
|
||||
self.assertEqual(selector.main(), 0)
|
||||
values = dict(line.split("=", 1) for line in path.read_text().splitlines())
|
||||
self.assertEqual(json.loads(values["runner"]), selector.LABELS)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user