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.
This commit is contained in:
Trevor Gross 2025-01-14 07:46:20 +00:00
parent 5e65179a39
commit f63ef37218
2 changed files with 26 additions and 7 deletions

View file

@ -7,7 +7,6 @@ on:
env:
CARGO_TERM_COLOR: always
CARGO_TERM_VERBOSE: true
RUSTDOCFLAGS: -Dwarnings
RUSTFLAGS: -Dwarnings
RUST_BACKTRACE: full
@ -202,7 +201,7 @@ jobs:
- name: Fetch pull request ref
run: git fetch origin "$GITHUB_REF:$GITHUB_REF"
if: github.event_name == 'pull_request'
- run: python3 ci/calculate-exhaustive-matrix.py >> "$GITHUB_OUTPUT"
- run: python3 ci/ci-util.py generate-matrix >> "$GITHUB_OUTPUT"
id: script
extensive:

View file

@ -1,18 +1,30 @@
#!/usr/bin/env python3
"""Calculate which exhaustive tests should be run as part of CI.
"""Utilities for CI.
This dynamically prepares a list of routines that had a source file change based on
git history.
"""
import json
import subprocess as sp
import sys
import json
from dataclasses import dataclass
from inspect import cleandoc
from os import getenv
from pathlib import Path
from typing import TypedDict
USAGE = cleandoc(
"""
usage:
./ci/ci-util.py <SUBCOMMAND>
SUBCOMMAND:
generate-matrix Calculate a matrix of which functions had source change,
print that as JSON object.
"""
)
REPO_ROOT = Path(__file__).parent.parent
GIT = ["git", "-C", REPO_ROOT]
@ -139,9 +151,17 @@ def eprint(*args, **kwargs):
def main():
ctx = Context()
output = ctx.make_workflow_output()
print(f"matrix={output}")
match sys.argv[1:]:
case ["generate-matrix"]:
ctx = Context()
output = ctx.make_workflow_output()
print(f"matrix={output}")
case ["--help" | "-h"]:
print(USAGE)
exit()
case _:
eprint(USAGE)
exit(1)
if __name__ == "__main__":