Skip to content

Commit

Permalink
Test action
Browse files Browse the repository at this point in the history
  • Loading branch information
druzsan committed Feb 7, 2024
1 parent 17edfe9 commit 867c6e3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
19 changes: 9 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
import json
import os
from typing import Any

Expand Down Expand Up @@ -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)
Expand All @@ -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)

0 comments on commit 867c6e3

Please sign in to comment.