ci: parse changed files as JSON (#37372)

Avoid interpolating changed file names directly into shell scripts when
building CI matrices.
This commit is contained in:
Mason Daugherty
2026-05-12 22:25:19 -07:00
committed by GitHub
parent d0d78f1aeb
commit c4c91d9cd3
3 changed files with 45 additions and 3 deletions

View File

@@ -242,8 +242,42 @@ def _get_configs_for_multi_dirs(
]
def _get_changed_files(args: list[str]) -> list[str]:
"""Parse changed files from command-line arguments.
Args:
args: Either a legacy list of filename arguments or a single JSON array
produced by `Ana06/get-changed-files` with `format: json`.
Returns:
List of changed files.
Raises:
ValueError: If a single argument looks like JSON but is not a string array.
"""
if len(args) != 1:
return args
value = args[0].strip()
if not value.startswith("[") or not value.endswith("]"):
return args
try:
parsed = json.loads(value)
except json.JSONDecodeError as e:
msg = "Expected changed files JSON to be a list of strings."
raise ValueError(msg) from e
if not isinstance(parsed, list) or not all(
isinstance(file, str) for file in parsed
):
msg = "Expected changed files JSON to be a list of strings."
raise ValueError(msg)
return parsed
if __name__ == "__main__":
files = sys.argv[1:]
files = _get_changed_files(sys.argv[1:])
dirs_to_run: Dict[str, set] = {
"lint": set(),