ci(molecule): cancel superseded pull request runs

A new commit on a pull request now cancels its running Molecule run, as for
Lint and Build; a run on main is never cancelled (its group is the commit SHA).

The old global concurrency group kept two runs off the runner's shared Docker
daemon, whose container names are fixed. That is now the runner's single slot
(gitea_runner_capacity: 1), as the workflow comment and CLAUDE.md say. A
cancelled run is killed before molecule can destroy its container, so the run
step first removes the containers of every scenario by their exact platform
names, whether or not this run selects that scenario.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNmHMc85bomfevwUDG
This commit is contained in:
Defame1297andClaude Sonnet 5.5 committed 2026-11-14 11:06:17 +00:00
1 parent 4d330d41c7
commit db52adcb81
2 files changed
+21 -5

No files matched your search

+18 -4
View File
@@ -41,10 +41,15 @@ on: # yamllint disable-line rule:truthy
permissions:
contents: read
# Scenarios use fixed container names on the runner's shared Docker daemon.
# A pull request run is cancelled when a newer commit is pushed to the same pull request (the
# same rule as lint.yml and build.yml); a run on main is never cancelled, so its group is the
# commit SHA. Scenarios use fixed container names on the runner's shared Docker daemon, so two
# runs must not overlap. The group no longer guarantees that (it is per pull request now): the
# runner's single slot does (gitea_runner_capacity: 1 in the maintainer's environment
# repository). Raise that capacity and this needs a lock or a shared group again.
concurrency:
group: molecule
cancel-in-progress: false
group: molecule-${{ github.event_name == 'pull_request' && github.ref || github.sha }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
molecule:
@@ -100,7 +105,9 @@ jobs:
# A pull request runs only the scenarios of the roles it changes (scripts/select_molecule_scenarios.py
# explains the rules); a push to main and a manual dispatch run all of them.
# molecule test destroys its instance on success and on failure.
# molecule test destroys its instance on success and on failure; a cancelled run is killed
# before it can, so the step first removes what such a run left, since the next run may not
# select the same scenarios.
- name: Run the scenarios
working-directory: ac/ansible_collections/mortis/kamino
env:
@@ -108,6 +115,13 @@ jobs:
# The workflow only runs for pull requests to main; lint.yml uses the same constant.
BASE_REF: origin/main
run: |
# The platform names of every scenario, anchored: <role>-instance and image-smoke[-2604].
# Assigned first so that a failing `docker ps` fails the step instead of looking empty.
stale="$(docker ps -aq --filter 'name=^/[a-z0-9-]+-instance$' --filter 'name=^/image-smoke(-2604)?$')"
if [ -n "$stale" ]; then
# shellcheck disable=SC2086 # container ids, one word each
docker rm -f $stale
fi
# molecule calls ansible-config and ansible-playbook by name
export PATH="$MOLECULE_VENV/bin:$PATH"
# The collection under test first, then what the roles use. molecule also
+3 -1
View File
@@ -64,7 +64,9 @@ Single-context: `GLOSSARY.md` and `docs/adr/` at the root, both created lazily.
(a pull request cannot edit its own rules): only the scenarios of the roles it changes, none for a diff of
only its IGNORED paths, a failure for a changed role with no scenario, and every scenario for any other file,
for every push to `main` and for manual dispatch. A new file outside `roles/<role>/` runs everything until it
is added to IGNORED, which is right only when no scenario reads it.
is added to IGNORED, which is right only when no scenario reads it. A new commit cancels the pull request's
running Molecule run, and the step first removes containers a cancelled run left; two runs never overlap
because the runner has a single slot, so raising its capacity needs a lock or a shared concurrency group.
- Molecule discovers `extensions/molecule/*/` and `roles/*/molecule/*/`. The `image-smoke`
and `image-smoke-2604` scenarios test the molecule images themselves (24.04 and 26.04); a role scenario that
must pass on both takes `image: ${MOLECULE_IMAGE}` or `${MOLECULE_IMAGE_2604}` per platform.