|
| 1 | +import json |
| 2 | +import os |
| 3 | + |
| 4 | + |
| 5 | +class Target: |
| 6 | + # GitHub runner OS |
| 7 | + os_id: str |
| 8 | + # Rust target triple |
| 9 | + target: str |
| 10 | + |
| 11 | + def __init__(self, os_id: str, target: str): |
| 12 | + self.os_id = os_id |
| 13 | + self.target = target |
| 14 | + |
| 15 | + |
| 16 | +class Case: |
| 17 | + name: str |
| 18 | + filter: str |
| 19 | + n_partitions: int |
| 20 | + xplatform: bool |
| 21 | + |
| 22 | + def __init__(self, name: str, filter: str, n_partitions: int, xplatform: bool): |
| 23 | + self.name = name |
| 24 | + self.filter = filter |
| 25 | + self.n_partitions = n_partitions |
| 26 | + self.xplatform = xplatform |
| 27 | + |
| 28 | + |
| 29 | +class Expanded: |
| 30 | + os: str |
| 31 | + target: str |
| 32 | + name: str |
| 33 | + flags: str |
| 34 | + partition: int |
| 35 | + |
| 36 | + def __init__(self, os: str, target: str, name: str, flags: str, partition: int): |
| 37 | + self.os = os |
| 38 | + self.target = target |
| 39 | + self.name = name |
| 40 | + self.flags = flags |
| 41 | + self.partition = partition |
| 42 | + |
| 43 | + |
| 44 | +default_target = Target("ubuntu-latest", "x86_64-unknown-linux-gnu") |
| 45 | +if os.environ.get("EVENT_NAME") == "pull_request": |
| 46 | + targets = [default_target] |
| 47 | +else: |
| 48 | + targets = [ |
| 49 | + default_target, |
| 50 | + Target("ubuntu-latest", "aarch64-unknown-linux-gnu"), |
| 51 | + Target("macos-latest", "x86_64-apple-darwin"), |
| 52 | + Target("macos-latest", "aarch64-apple-darwin"), |
| 53 | + Target("windows-latest", "x86_64-pc-windows-msvc"), |
| 54 | + ] |
| 55 | + |
| 56 | +config = [ |
| 57 | + Case( |
| 58 | + name="unit", |
| 59 | + filter="kind(lib) | kind(bench) | kind(proc-macro)", |
| 60 | + n_partitions=1, |
| 61 | + xplatform=True, |
| 62 | + ), |
| 63 | + Case( |
| 64 | + name="integration", |
| 65 | + filter="kind(test) & !test(/issue|forge_std|ext_integration/)", |
| 66 | + n_partitions=3, |
| 67 | + xplatform=True, |
| 68 | + ), |
| 69 | + Case( |
| 70 | + name="integration/issue-repros", |
| 71 | + filter="package(=forge) & test(~issue)", |
| 72 | + n_partitions=2, |
| 73 | + xplatform=False, |
| 74 | + ), |
| 75 | + Case( |
| 76 | + name="integration/forge-std", |
| 77 | + filter="package(=forge) & test(~forge_std)", |
| 78 | + n_partitions=1, |
| 79 | + xplatform=False, |
| 80 | + ), |
| 81 | + Case( |
| 82 | + name="integration/external", |
| 83 | + filter="package(=forge) & test(~ext_integration)", |
| 84 | + n_partitions=2, |
| 85 | + xplatform=False, |
| 86 | + ), |
| 87 | +] |
| 88 | + |
| 89 | + |
| 90 | +def build_matrix(): |
| 91 | + os_ids = [] |
| 92 | + targets_ = [] |
| 93 | + for target in targets: |
| 94 | + os_ids.append(target.os_id) |
| 95 | + targets_.append(target.target) |
| 96 | + print(json.dumps({"os": os_ids, "target": targets_})) |
| 97 | + |
| 98 | + |
| 99 | +def test_matrix(): |
| 100 | + expanded = [] |
| 101 | + for target in targets: |
| 102 | + for case in config: |
| 103 | + if not case.xplatform and target != default_target: |
| 104 | + continue |
| 105 | + |
| 106 | + for partition in range(1, case.n_partitions + 1): |
| 107 | + os_str = "" |
| 108 | + if len(targets) > 1: |
| 109 | + os_str = f" ({target.target})" |
| 110 | + |
| 111 | + name = case.name |
| 112 | + flags = f"-E '{case.filter}'" |
| 113 | + if case.n_partitions > 1: |
| 114 | + s = f"{partition}/{case.n_partitions}" |
| 115 | + name += f" ({s})" |
| 116 | + flags += f" --partition count:{s}" |
| 117 | + name += os_str |
| 118 | + |
| 119 | + obj = Expanded( |
| 120 | + os=target.os_id, |
| 121 | + target=target.target, |
| 122 | + name=name, |
| 123 | + flags=flags, |
| 124 | + partition=partition, |
| 125 | + ) |
| 126 | + expanded.append(vars(obj)) |
| 127 | + |
| 128 | + print(json.dumps({"include": expanded}), end="", flush=True) |
| 129 | + |
| 130 | + |
| 131 | +if __name__ == "__main__": |
| 132 | + if int(os.environ.get("TEST", "0")) == 0: |
| 133 | + build_matrix() |
| 134 | + else: |
| 135 | + test_matrix() |
0 commit comments