diff --git a/.gitea/workflows/AGENTS.md b/.gitea/workflows/AGENTS.md index 882da29..6fab069 100644 --- a/.gitea/workflows/AGENTS.md +++ b/.gitea/workflows/AGENTS.md @@ -79,10 +79,11 @@ issue. pin pull request. *Held:* review. - **Molecule has three jobs: `select`, `scenarios` and `result`.** `select` runs the selector in a job container on `kamino-docker`, in the `molecule-controller` pin (never the `ci` pin, whose - bumps would then select every scenario), and outputs the selected directories. `scenarios` - runs them on `kamino-molecule` and is skipped when the list is empty. `result` (check - `Molecule / Result (pull_request)`) is the required check: it runs `if: always()` and fails - unless `select` passed and `scenarios` passed or was skipped for an empty list. The + bumps would then select every scenario), and outputs the selected directories, or `none`. + `scenarios` runs them on `kamino-molecule` and is skipped for `none` or an empty output. + `result` (check `Molecule / Result (pull_request)`) is the required check: it runs + `if: always()` and fails unless `select` passed and `scenarios` passed or was skipped for + `none`, so a lost output fails it. The controller pin is written in all three jobs, because `container.image` cannot read `env`. *Why:* a pull request that selects nothing takes no Molecule runner slot, and a skipped job counts as passing in Gitea, so only a job that always runs can be required. *Held:* control: diff --git a/.gitea/workflows/molecule.yml b/.gitea/workflows/molecule.yml index 882726d..6c56d92 100644 --- a/.gitea/workflows/molecule.yml +++ b/.gitea/workflows/molecule.yml @@ -110,19 +110,18 @@ jobs: echo "::notice::no base copy of $sel; running this checkout's copy" fi selected="$(python3 -I "$sel" "$BASE_REF")" || exit 1 - # One directory per line. A random delimiter, so no line of the list can end the value; - # an empty selection writes no line, so the output is the empty string. + # `none` marks an empty selection, so a lost or empty output fails result, never passes. + if [ -z "$selected" ]; then selected=none; fi + # One directory per line; a random delimiter, so no line of the list can end the value. delim="scenarios-$(od -An -N16 -tx1 /dev/urandom | tr -d ' \n')" - { - echo "scenarios<<$delim" - if [ -n "$selected" ]; then printf '%s\n' "$selected"; fi - echo "$delim" - } >> "$GITHUB_OUTPUT" + printf 'scenarios<<%s\n%s\n%s\n' "$delim" "$selected" "$delim" >> "$GITHUB_OUTPUT" scenarios: needs: select - # Skipped, not failed, when select fails or selects nothing; result tells the two apart. + # Skipped, not failed, when select fails, selects nothing (`none`) or loses its output (empty); + # result passes only the second. if: >- + needs.select.outputs.scenarios != 'none' && needs.select.outputs.scenarios != '' && github.repository == 'mortis/kamino' && (github.event_name != 'pull_request' || @@ -248,7 +247,7 @@ jobs: github.event.pull_request.head.repo.full_name == github.repository) runs-on: kamino-docker timeout-minutes: 5 - # Any small image does; the controller pin is reused so there is no other pin to bump. + # The controller pin again, so this job adds no pin of its own to bump. container: image: git.rkdr.net/mortis/molecule-controller:0.1.1@sha256:94af071ecae858016f9a61afa6e45f8344f8fef7d22d1fe899e05f5f48f756e8 steps: @@ -261,8 +260,8 @@ jobs: if [ "$SELECT_RESULT" != success ]; then echo "::error::select ended as $SELECT_RESULT"; exit 1 fi - # A skip is a pass only for an empty selection: a cancelled or failed run is not. - if [ "$SCENARIOS_RESULT" = skipped ] && [ -z "$SELECTED" ]; then + # A skip is a pass only for select's `none`: an empty output means it was lost. + if [ "$SCENARIOS_RESULT" = skipped ] && [ "$SELECTED" = none ]; then echo "No scenario selected." elif [ "$SCENARIOS_RESULT" != success ]; then echo "::error::scenarios ended as $SCENARIOS_RESULT"; exit 1 diff --git a/tests/scripts/test_run_molecule_scenarios.py b/tests/scripts/test_run_molecule_scenarios.py index 8a9c235..d8981a0 100644 --- a/tests/scripts/test_run_molecule_scenarios.py +++ b/tests/scripts/test_run_molecule_scenarios.py @@ -540,12 +540,38 @@ class WorkflowJobsTest(unittest.TestCase): SELECTED=selected, ) return subprocess.run( - ["bash", "-e", "-c", step["run"]], + # act runs a job container's step with sh when the step sets no shell + ["sh", "-e", "-c", step["run"]], check=False, env=env, capture_output=True, ).returncode + def written_output(self, selected): + """The `scenarios` output select's run step writes for that selector output.""" + step = next(s for s in self.JOBS["select"]["steps"] if s.get("id") == "select") + block = step["run"].split("|| exit 1\n", 1)[1] + with tempfile.TemporaryDirectory() as tmp: + out = pathlib.Path(tmp, "output") + subprocess.run( + ["sh", "-e", "-c", 'selected="$1"\n' + block, "sh", selected], + check=True, + env=dict(os.environ, GITHUB_OUTPUT=str(out)), + ) + lines = out.read_text().splitlines() + # GITHUB_OUTPUT's `name<