ci(molecule): isolate runs per run and drop the push trigger on main
Two Molecule runs could not overlap on one Docker daemon because every scenario's container name was fixed; only the runner's single slot kept them apart. Each platform is now named and labelled by KAMINO_RUN_ID (run id and attempt, "local" outside CI), the run script expands those names with molecule's own interpolator before removing them, and the workflow removes its own containers by label and only sweeps labelled leftovers older than the job timeout, so a run still going is never hit. Non-pull-request runs get a concurrency group of their own. Push to main no longer triggers Molecule, Lint or Build: a merged pull request was already tested, and the nightly and manual Molecule runs cover every scenario. Build keeps its v* tag trigger. Assisted-by: Claude Code:claude-opus-5-5
This commit is contained in:
1 parent
33fc3fd3a5
commit
96cb9246c6
23 files changed
+223
-160
No files matched your search
+21
-20
@@ -57,9 +57,9 @@ issue.
|
||||
`.pre-commit-config.yaml` takes the slow path, which installs the pinned tools and collections.
|
||||
*Why:* a pull request is tested on its own pins, and an unchanged one starts in seconds.
|
||||
*Held:* control: the "Check the baked tooling against the pins" step.
|
||||
- **Triggers:** both run on pull requests to `main`, on push to `main` until #166 removes that
|
||||
trigger, and on manual dispatch; Build also runs on `v*` tags, where it checks the tag against
|
||||
`galaxy.yml`. *Why:* the tag is what consumers install. *Held:* review.
|
||||
- **Triggers:** both run on pull requests to `main` and on manual dispatch; Build also runs on
|
||||
`v*` tags, where it checks the tag against `galaxy.yml`. *Why:* the tag is what consumers
|
||||
install. *Held:* review.
|
||||
|
||||
## Molecule
|
||||
|
||||
@@ -79,29 +79,30 @@ issue.
|
||||
belongs there only if no scenario reads it.** *Why:* a file a scenario reads but the selector
|
||||
ignores would let a breaking change through untested. *Held:* review.
|
||||
- **Every scenario runs on a manual dispatch and in the nightly run (04:43 UTC, after
|
||||
Renovate's).** A push to `main` that touches the `push:` `paths:` list runs every scenario
|
||||
too, until #166 removes that trigger. *Why:* a pull request runs only its selection, so
|
||||
drift in the other roles shows up here. *Held:* review.
|
||||
- **A new commit cancels the pull request's running Molecule run, and the run step first removes
|
||||
the containers a cancelled run left.** The scenarios of one run overlap
|
||||
(`scripts/run_molecule_scenarios.sh`, `MOLECULE_LANES` at a time), so no two scenarios may share a
|
||||
platform name. Two runs never overlap only because the runner has a single slot, and the
|
||||
scenarios' container names are fixed; raising the runner's capacity needs per-run container
|
||||
names first (#166). *Why:* a cancelled run is killed before it can remove its instances, and
|
||||
two overlapping scenarios or runs would collide on the same names. *Held:* review; that no two
|
||||
scenarios share a platform name is held by the test the `test_sequence` rule below names.
|
||||
Renovate's).** A push to `main` runs no Molecule. *Why:* a pull request runs only its
|
||||
selection, so drift in the other roles shows up here. *Held:* review.
|
||||
- **A new commit cancels the pull request's running Molecule run; every other run has a
|
||||
concurrency group of its own.** Runs may overlap on the runner's Docker daemon: every container
|
||||
is named and labelled by its run (`KAMINO_RUN_ID`). The job first removes labelled containers
|
||||
older than its timeout, which a cancelled run left, and finally its own. The scenarios of one
|
||||
run overlap (`scripts/run_molecule_scenarios.sh`, `MOLECULE_LANES` at a time), so no two
|
||||
scenarios may share a platform name. *Why:* a cancelled run is killed before it can remove its
|
||||
instances, and a younger container may belong to a run still going. *Held:* review; the names
|
||||
and labels are held by the test the `test_sequence` rule below names.
|
||||
- **Molecule tests the pull request's pins, as Lint and Build do.** It runs molecule in the pinned
|
||||
`ci` image and, when a pin file differs from `/opt/ci-pins.sha256`, installs the pull request's
|
||||
tools and the collections of `requirements.yml` and `extensions/molecule/requirements.yml` first.
|
||||
*Why:* a pull request that raises the ansible-core floor must run its scenarios on the new core
|
||||
before it automerges. *Held:* control: the pin comparison in `molecule.yml`.
|
||||
- **Every scenario sets `scenario.test_sequence` to molecule's default minus both `destroy`
|
||||
steps, and names its platforms literally in its `molecule.yml`;** copy it into a new scenario.
|
||||
*Why:* the workflow clears stale containers first and removes each scenario's containers by
|
||||
those names as soon as it ends, which skips the driver's destroy wait, and the molecule state
|
||||
lives in each scenario's own `ANSIBLE_HOME` in the job tree, so a killed run leaves none
|
||||
behind. *Held:* control: `tests/scripts/test_run_molecule_scenarios.py` fails a `destroy` in a
|
||||
sequence, and a platform name that is not unique or not matched by the stale-container filter.
|
||||
steps, names each platform `${KAMINO_RUN_ID:-local}-<name>` and labels it
|
||||
`net.rkdr.mortis.molecule-run: "${KAMINO_RUN_ID:-local}"` in its `molecule.yml`;** copy it into
|
||||
a new scenario. *Why:* the run script removes each scenario's containers by those names as soon
|
||||
as it ends, which skips the driver's destroy wait, the workflow finds a run's containers by the
|
||||
label, and the molecule state lives in each scenario's own `ANSIBLE_HOME` in the job tree, so a
|
||||
killed run leaves none behind. *Held:* control: `tests/scripts/test_run_molecule_scenarios.py`
|
||||
fails a `destroy` in a sequence, a platform name that is not unique or not per run, a missing
|
||||
label, and a workflow that does not filter by it.
|
||||
- **Scenarios live in `roles/*/molecule/*/` and `extensions/molecule/*/`.** A role scenario that
|
||||
must pass on Ubuntu 24.04 and 26.04 takes `image: ${MOLECULE_IMAGE}` or
|
||||
`${MOLECULE_IMAGE_2604}` per platform; the image-smoke scenarios are described in
|
||||
|
||||
@@ -9,8 +9,6 @@ on: # yamllint disable-line rule:truthy
|
||||
branches:
|
||||
- main
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- 'v*'
|
||||
workflow_dispatch: {}
|
||||
@@ -18,11 +16,10 @@ on: # yamllint disable-line rule:truthy
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
# A newer push to the same pull request cancels the running run; a push to main or a tag
|
||||
# never cancels another run. A tag run has its own group, so it never shares one with the
|
||||
# main run of the same commit.
|
||||
# A newer push to the same pull request cancels the running run. A tag's ref differs from every
|
||||
# branch's, so a tag run has a group of its own and is never cancelled.
|
||||
concurrency:
|
||||
group: build-${{ github.event_name == 'pull_request' && github.ref || (github.ref_type == 'tag' && github.ref || github.sha) }}
|
||||
group: build-${{ github.ref }}
|
||||
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
||||
|
||||
jobs:
|
||||
|
||||
@@ -12,19 +12,15 @@ on: # yamllint disable-line rule:truthy
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
workflow_dispatch: {}
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
# A newer push to the same pull request makes the running run obsolete. A push to main is
|
||||
# never cancelled: each merge commit keeps its own result, so its group is the commit SHA.
|
||||
# (This workflow has no tag trigger, so no tag branch in the group.)
|
||||
# A newer push to the same pull request makes the running run obsolete; a manual dispatch never
|
||||
# cancels another run.
|
||||
concurrency:
|
||||
group: lint-${{ github.event_name == 'pull_request' && github.ref || github.sha }}
|
||||
group: lint-${{ github.ref }}
|
||||
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
||||
|
||||
jobs:
|
||||
|
||||
@@ -20,20 +20,8 @@ on: # yamllint disable-line rule:truthy
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- 'roles/**'
|
||||
- 'extensions/**'
|
||||
- 'plugins/**'
|
||||
- 'meta/**'
|
||||
- 'galaxy.yml'
|
||||
- 'requirements.yml'
|
||||
- '.gitea/workflows/molecule.yml'
|
||||
# Every scenario, nightly: a pull request runs only the scenarios of the roles it changes, so
|
||||
# drift in the others (a package mirror) would otherwise wait for
|
||||
# the next push to main. After Renovate's 03:17 run, which can take 30 minutes of the one slot.
|
||||
# drift in the others (a package mirror) would otherwise go unseen. After Renovate's 03:17 run.
|
||||
schedule:
|
||||
- cron: "43 4 * * *"
|
||||
workflow_dispatch: {}
|
||||
@@ -41,21 +29,17 @@ on: # yamllint disable-line rule:truthy
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
# 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. The scenarios of one run overlap (scripts/run_molecule_scenarios.sh), which is safe
|
||||
# because no two share a container name; but the names are fixed 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. Raise the runner's capacity and this needs
|
||||
# per-run container names first (#166), or a lock or a shared group again.
|
||||
# A newer push to a pull request cancels its older run; every other run has a group of its own, so
|
||||
# none is cancelled. Runs may overlap on the runner's Docker daemon: every container is named and
|
||||
# labelled by its run (KAMINO_RUN_ID), and no two scenarios share a platform name.
|
||||
concurrency:
|
||||
group: molecule-${{ github.event_name == 'pull_request' && github.ref || github.sha }}
|
||||
group: molecule-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
|
||||
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
||||
|
||||
jobs:
|
||||
molecule:
|
||||
# Same-repo branches only (bot branches included: a Renovate pin pull request is what tests a new
|
||||
# image); a push to main or a manual dispatch always runs. No paths filter on pull requests, so
|
||||
# image); the nightly run and a manual dispatch always run. No paths filter on pull requests, so
|
||||
# that Molecule can be a required check: a required check that a pull request never starts would
|
||||
# block it. A fork pull request is skipped by the guard below.
|
||||
if: >-
|
||||
@@ -76,7 +60,9 @@ jobs:
|
||||
# `image: ${MOLECULE_IMAGE_2604}` in extensions/molecule/image-smoke-2604.
|
||||
MOLECULE_IMAGE_2604: >-
|
||||
git.rkdr.net/mortis/molecule-ubuntu2604:0.1.6@sha256:d7c216b33d18fa8f1ecbfee8795eb4adc867fe5ad8e7a73b7c67effe301cf771
|
||||
# The container molecule runs in, named and labelled by the run so the cleanup step finds it.
|
||||
# Names and labels this run's containers: the scenarios' as `${KAMINO_RUN_ID:-local}-<name>`
|
||||
# with the label net.rkdr.mortis.molecule-run, and the one molecule runs in.
|
||||
KAMINO_RUN_ID: ${{ github.run_id }}-${{ github.run_attempt }}
|
||||
RUN_CONTAINER: kamino-molecule-${{ github.run_id }}-${{ github.run_attempt }}
|
||||
steps:
|
||||
- name: Check the Docker daemon
|
||||
@@ -101,10 +87,23 @@ jobs:
|
||||
git checkout "$SHA" || { git fetch origin "$REF" && git checkout "$SHA"; }
|
||||
echo "Checked out $(git rev-parse HEAD)"
|
||||
|
||||
# A cancelled run is killed before it can remove its containers. Any labelled container older
|
||||
# than the job timeout is such a leftover; a younger one may belong to a run still going.
|
||||
- name: Remove the containers earlier runs left
|
||||
run: |
|
||||
# Assigned first so that a failing `docker ps` fails the step instead of looking empty.
|
||||
ids="$(docker ps -aq --filter 'label=net.rkdr.mortis.molecule-run')"
|
||||
cutoff="$(date -d '30 minutes ago' +%s)"
|
||||
for id in $ids; do
|
||||
# a container removed since the listing is skipped
|
||||
created="$(docker inspect --format '{{.Created}}' "$id")" || continue
|
||||
if [ "$(date -d "$created" +%s)" -lt "$cutoff" ]; then docker rm -f "$id"; fi
|
||||
done
|
||||
|
||||
# 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, a few at a time.
|
||||
# explains the rules); the nightly run and a manual dispatch run all of them, a few at a time.
|
||||
# scripts/run_molecule_scenarios.sh runs them and removes each scenario's containers as soon as
|
||||
# it ends; a cancelled run is killed before it can, so the step first removes what one left.
|
||||
# it ends.
|
||||
- name: Run the scenarios
|
||||
working-directory: ac/ansible_collections/mortis/kamino
|
||||
env:
|
||||
@@ -112,13 +111,6 @@ 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
|
||||
# The selector comes from the base branch, so a pull request cannot edit the rules it is
|
||||
# judged by (lint.yml does the same for check_bot_pr_diff.py); the first pull request that
|
||||
# adds it has no base copy yet and uses its own.
|
||||
@@ -144,18 +136,21 @@ jobs:
|
||||
printf 'root:x:0:0:root:/root:/bin/bash\n%s:x:%s:%s::%s:/bin/bash\n' \
|
||||
"$(id -un)" "$(id -u)" "$(id -g)" "$ac_root/home" > "$ac_root/passwd"
|
||||
docker run --rm -i --init --name "$RUN_CONTAINER" \
|
||||
--label "net.rkdr.mortis.molecule-run=$RUN_CONTAINER" \
|
||||
--label "net.rkdr.mortis.molecule-run=$KAMINO_RUN_ID" \
|
||||
--user "$(id -u):$(id -g)" --group-add "$sock_gid" \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock -v "$docker_cli:/usr/local/bin/docker:ro" \
|
||||
-v "$ac_root:$ac_root" -v "$ac_root/passwd:/etc/passwd:ro" -w "$PWD" \
|
||||
-e "AC_ROOT=$ac_root" -e "HOME=$ac_root/home" -e "USER=$(id -un)" \
|
||||
-e MOLECULE_IMAGE -e MOLECULE_IMAGE_2604 \
|
||||
-e MOLECULE_IMAGE -e MOLECULE_IMAGE_2604 -e KAMINO_RUN_ID \
|
||||
"$CI_IMAGE" scripts/run_molecule_in_ci_image.sh <<< "$selected"
|
||||
|
||||
# A cancelled run can leave the container running when the docker client is killed.
|
||||
- name: Remove the molecule container
|
||||
# A cancelled run can leave its containers running when the docker client is killed.
|
||||
- name: Remove this run's containers
|
||||
if: always()
|
||||
run: |
|
||||
if docker container inspect "$RUN_CONTAINER" >/dev/null 2>&1; then
|
||||
docker rm -f "$RUN_CONTAINER"
|
||||
# Assigned first so that a failing `docker ps` fails the step instead of looking empty.
|
||||
ids="$(docker ps -aq --filter "label=net.rkdr.mortis.molecule-run=$KAMINO_RUN_ID")"
|
||||
if [ -n "$ids" ]; then
|
||||
# shellcheck disable=SC2086 # container ids, one word each
|
||||
docker rm -f $ids
|
||||
fi
|
||||
Reference in new issue
Block a user