fix: use 1-based runner indices for Gitea Actions compatibility

This commit is contained in:
2026-06-22 02:31:20 +00:00
parent 8c16703106
commit 1f75017395
4 changed files with 21 additions and 15 deletions
+7 -5
View File
@@ -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()
+6 -3
View File
@@ -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))