diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 35f77f3..7b57186 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,17 +13,16 @@ jobs: uses: druzsan/setup-matrix@feature/use-python-dockerfile with: matrix: | - fruit: [apple, pear] - animal: [cat, dog] + os: [ubuntu-latest, macos-latest] + python-version: [3.8, 3.10, 3.12] include: - - color: green - - color: pink - animal: cat - - fruit: apple - shape: circle - - fruit: banana - - fruit: banana - animal: cat + - os: windows-latest + python-version: 3.8 + - os: windows-latest + python-version: 3.10 + exclude: + - os: macos-latest + python-version: 3.8 # Setup python and print version setup-python: needs: setup-matrix diff --git a/main.py b/main.py index 081fd27..c557ee7 100755 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +import json import os from typing import Any @@ -97,15 +98,23 @@ def assert_valid_matrix(matrix: Any) -> None: f"Matrix values must be sequences (Python lists), but " f"Python {type(values)} received for variable '{variable}'." ) + if not values: + raise ValueError(f"No values received for variable '{variable}'.") for value in values: if not isinstance(value, str): raise TypeError( f"Each matrix value must be a string, but Python " f"{type(value)} received for variable '{variable}'." ) + # The whole matrix, one of or both include and exclude are empty. + if not matrix or all(not values for values in matrix.values()): + raise RuntimeError("Strategy matrix must define at least one combination.") def parse_matrix(input_matrix: str) -> dict: + """ + Parse strategy matrix from string and validate it. + """ # Parse every YAML scalar as a string matrix = yaml.load(input_matrix, Loader=yaml.loader.BaseLoader) print(matrix) @@ -120,8 +129,7 @@ def parse_matrix(input_matrix: str) -> dict: print(yaml.dump({"matrix": matrix})) - # output_matrix = json.dumps(matrix) - output_matrix = "{'os':[]}" + output_matrix = json.dumps(matrix) output("matrix", output_matrix) setenv("MATRIX", output_matrix)