From 1f750173951c181f5d341740b00a38769df628a4 Mon Sep 17 00:00:00 2001 From: emil Date: Mon, 22 Jun 2026 02:31:20 +0000 Subject: [PATCH] fix: use 1-based runner indices for Gitea Actions compatibility --- scripts/ci/discover_runners.py | 12 +++++++----- scripts/ci/distribute_molecule.py | 9 ++++++--- tests/unit/test_discover_runners.py | 12 ++++++------ tests/unit/test_distribute_molecule.py | 3 ++- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/scripts/ci/discover_runners.py b/scripts/ci/discover_runners.py index 8371b32..baab120 100644 --- a/scripts/ci/discover_runners.py +++ b/scripts/ci/discover_runners.py @@ -112,13 +112,15 @@ def get_runner_count(api_url: str, token: str, owner: str, repo: str) -> int: def generate_indices(count: int) -> list[str]: - """Generate a list of runner indices ["0", "1", ..., "N-1"]. + """Generate a list of runner indices ["1", "2", ..., "N"]. - 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. + Uses 1-based string indices because Gitea Actions renders + integer 0 and string "0" as empty in ${{ matrix.runner-index }} + expressions, causing --runner-index to be passed without a value. + The distribute_molecule.py script converts these back to 0-based + internally. """ - return [str(i) for i in range(count)] + return [str(i + 1) for i in range(count)] @click.command() diff --git a/scripts/ci/distribute_molecule.py b/scripts/ci/distribute_molecule.py index 6c2b685..a1ce599 100644 --- a/scripts/ci/distribute_molecule.py +++ b/scripts/ci/distribute_molecule.py @@ -9,7 +9,7 @@ Each pair is printed as ``scenario|platform_name|platform_image|platform_command so the CI workflow can set the appropriate environment variables. Usage: - python3 scripts/distribute_molecule.py --runner-index 0 --max-runners 3 + python3 scripts/distribute_molecule.py --runner-index 1 --max-runners 3 # prints: default|ubuntu-2204|ubuntu:22.04| lifecycle|ubuntu-2204|ubuntu:22.04| ... python3 scripts/distribute_molecule.py --list # prints all scenarios, one per line @@ -105,7 +105,8 @@ def pairs_for_runner(pairs: list[TestPair], runner_index: int, max_runners: int) "--runner-index", type=int, default=None, - help="Zero-based runner index. If omitted, prints all groups.", + help="One-based runner index (Gitea Actions renders 0 as empty). " + "Converted to zero-based internally. If omitted, prints all groups.", ) @click.option( "--max-runners", @@ -143,7 +144,9 @@ def cli(runner_index: int | None, max_runners: int, list_all: bool, list_platfor labels = " ".join(p.encode() for p in group) if group else "(none)" click.echo(f"Runner {i}: {labels}") return - assigned = pairs_for_runner(pairs, runner_index, max_runners) + # Convert 1-based CLI index to 0-based internal index + zero_based = runner_index - 1 + assigned = pairs_for_runner(pairs, zero_based, max_runners) click.echo(" ".join(p.encode() for p in assigned)) diff --git a/tests/unit/test_discover_runners.py b/tests/unit/test_discover_runners.py index fbd3183..d525d72 100644 --- a/tests/unit/test_discover_runners.py +++ b/tests/unit/test_discover_runners.py @@ -19,13 +19,13 @@ class TestGenerateIndices: assert generate_indices(0) == [] def test_one(self) -> None: - assert generate_indices(1) == ["0"] + assert generate_indices(1) == ["1"] def test_three(self) -> None: - assert generate_indices(3) == ["0", "1", "2"] + assert generate_indices(3) == ["1", "2", "3"] def test_five(self) -> None: - assert generate_indices(5) == ["0", "1", "2", "3", "4"] + assert generate_indices(5) == ["1", "2", "3", "4", "5"] 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=["1", "2", "3"]' 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()) == ["1", "2", "3", "4"] @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()) == ["1"] diff --git a/tests/unit/test_distribute_molecule.py b/tests/unit/test_distribute_molecule.py index 15277d7..ef28c79 100644 --- a/tests/unit/test_distribute_molecule.py +++ b/tests/unit/test_distribute_molecule.py @@ -184,7 +184,8 @@ class TestCli: (root / "alpha").mkdir(parents=True) with patch("scripts.ci.distribute_molecule.MOLECULE_ROOT", root): runner = CliRunner() - result = runner.invoke(cli, ["--runner-index", "0", "--max-runners", "3"]) + # 1-based index: "1" maps to internal 0 + result = runner.invoke(cli, ["--runner-index", "1", "--max-runners", "3"]) assert result.exit_code == 0 # Output should contain encoded pairs with platform info assert "alpha|" in result.output