fix: molecule-tests matrix runner-index renders as empty for 0
This commit is contained in:
@@ -142,7 +142,9 @@ jobs:
|
||||
run: |
|
||||
set -euo pipefail
|
||||
. .venv/bin/activate
|
||||
PAIRS=$(python3 scripts/ci/distribute_molecule.py --runner-index ${{ matrix.runner-index }} --max-runners ${{ needs.discover-runners.outputs.runner-count }})
|
||||
RUNNER_INDEX="${{ matrix.runner-index }}"
|
||||
MAX_RUNNERS="${{ needs.discover-runners.outputs.runner-count }}"
|
||||
PAIRS=$(python3 scripts/ci/distribute_molecule.py --runner-index "$RUNNER_INDEX" --max-runners "$MAX_RUNNERS")
|
||||
echo "Assigned pairs: $PAIRS"
|
||||
echo "TEST_PAIRS=$PAIRS" >> $GITHUB_ENV
|
||||
- name: Run molecule tests
|
||||
|
||||
@@ -111,9 +111,14 @@ def get_runner_count(api_url: str, token: str, owner: str, repo: str) -> int:
|
||||
return DEFAULT_MAX_RUNNERS
|
||||
|
||||
|
||||
def generate_indices(count: int) -> list[int]:
|
||||
"""Generate a list of runner indices [0, 1, ..., count-1]."""
|
||||
return list(range(count))
|
||||
def generate_indices(count: int) -> list[str]:
|
||||
"""Generate a list of runner indices ["0", "1", ..., "N-1"].
|
||||
|
||||
Uses strings instead of ints because Gitea Actions renders
|
||||
integer 0 as empty in ${{ matrix.runner-index }} expressions,
|
||||
causing --runner-index to be passed without a value.
|
||||
"""
|
||||
return [str(i) for i in range(count)]
|
||||
|
||||
|
||||
@click.command()
|
||||
|
||||
@@ -19,13 +19,13 @@ class TestGenerateIndices:
|
||||
assert generate_indices(0) == []
|
||||
|
||||
def test_one(self) -> None:
|
||||
assert generate_indices(1) == [0]
|
||||
assert generate_indices(1) == ["0"]
|
||||
|
||||
def test_three(self) -> None:
|
||||
assert generate_indices(3) == [0, 1, 2]
|
||||
assert generate_indices(3) == ["0", "1", "2"]
|
||||
|
||||
def test_five(self) -> None:
|
||||
assert generate_indices(5) == [0, 1, 2, 3, 4]
|
||||
assert generate_indices(5) == ["0", "1", "2", "3", "4"]
|
||||
|
||||
|
||||
class TestQueryRunners:
|
||||
@@ -166,7 +166,7 @@ class TestMain:
|
||||
result = runner.invoke(main, [])
|
||||
assert result.exit_code == 0
|
||||
assert "count=3" in result.output
|
||||
assert "indices=[0, 1, 2]" in result.output
|
||||
assert 'indices=["0", "1", "2"]' in result.output
|
||||
|
||||
@patch("scripts.ci.discover_runners.get_runner_count", return_value=5)
|
||||
def test_count_only(self, mock_count: MagicMock) -> None:
|
||||
@@ -180,11 +180,11 @@ class TestMain:
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(main, ["--indices"])
|
||||
assert result.exit_code == 0
|
||||
assert json.loads(result.output.strip()) == [0, 1, 2, 3]
|
||||
assert json.loads(result.output.strip()) == ["0", "1", "2", "3"]
|
||||
|
||||
@patch("scripts.ci.discover_runners.get_runner_count", return_value=1)
|
||||
def test_single_runner(self, mock_count: MagicMock) -> None:
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(main, ["--indices"])
|
||||
assert result.exit_code == 0
|
||||
assert json.loads(result.output.strip()) == [0]
|
||||
assert json.loads(result.output.strip()) == ["0"]
|
||||
|
||||
Reference in New Issue
Block a user