Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit e116e0c

Browse files
committed
Slightly restructure ci/calculate-exhaustive-matrix.py
Change this script into a generic CI utility that we will be able to expand in the future.
1 parent 6d8b850 commit e116e0c

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

libm/.github/workflows/main.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ on:
77

88
env:
99
CARGO_TERM_COLOR: always
10-
CARGO_TERM_VERBOSE: true
1110
RUSTDOCFLAGS: -Dwarnings
1211
RUSTFLAGS: -Dwarnings
1312
RUST_BACKTRACE: full
@@ -202,7 +201,7 @@ jobs:
202201
- name: Fetch pull request ref
203202
run: git fetch origin "$GITHUB_REF:$GITHUB_REF"
204203
if: github.event_name == 'pull_request'
205-
- run: python3 ci/calculate-exhaustive-matrix.py >> "$GITHUB_OUTPUT"
204+
- run: python3 ci/ci-util.py generate-matrix >> "$GITHUB_OUTPUT"
206205
id: script
207206

208207
extensive:

libm/ci/calculate-exhaustive-matrix.py renamed to libm/ci/ci-util.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
11
#!/usr/bin/env python3
2-
"""Calculate which exhaustive tests should be run as part of CI.
2+
"""Utilities for CI.
33
44
This dynamically prepares a list of routines that had a source file change based on
55
git history.
66
"""
77

8+
import json
89
import subprocess as sp
910
import sys
10-
import json
1111
from dataclasses import dataclass
12+
from inspect import cleandoc
1213
from os import getenv
1314
from pathlib import Path
1415
from typing import TypedDict
1516

17+
USAGE = cleandoc(
18+
"""
19+
usage:
20+
21+
./ci/ci-util.py <SUBCOMMAND>
22+
23+
SUBCOMMAND:
24+
generate-matrix Calculate a matrix of which functions had source change,
25+
print that as JSON object.
26+
"""
27+
)
1628

1729
REPO_ROOT = Path(__file__).parent.parent
1830
GIT = ["git", "-C", REPO_ROOT]
@@ -139,9 +151,17 @@ def eprint(*args, **kwargs):
139151

140152

141153
def main():
142-
ctx = Context()
143-
output = ctx.make_workflow_output()
144-
print(f"matrix={output}")
154+
match sys.argv[1:]:
155+
case ["generate-matrix"]:
156+
ctx = Context()
157+
output = ctx.make_workflow_output()
158+
print(f"matrix={output}")
159+
case ["--help" | "-h"]:
160+
print(USAGE)
161+
exit()
162+
case _:
163+
eprint(USAGE)
164+
exit(1)
145165

146166

147167
if __name__ == "__main__":

0 commit comments

Comments
 (0)