ci(molecule): fail the Molecule result when select's output is lost
An empty select output meant "nothing selected", so an output lost on the way from select to result also passed the required check. select now writes `none` for an empty selection; scenarios runs for neither `none` nor an empty output, and result passes a skipped scenarios only for `none`. The result-logic test runs under sh, as act runs a job container's step without a shell, and a new test parses what select writes to GITHUB_OUTPUT. The fork-guard test compares each job with the literal guard. Assisted-by: Claude Code
This commit is contained in:
1 parent
2d1f142662
commit
479efe1ddc
3 files changed
+61
-23
No files matched your search
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user