From 67d7736ed4aecb162f2732585b2c6badfd60fb14 Mon Sep 17 00:00:00 2001 From: Andrei Gherzan Date: Sun, 18 Oct 2026 20:32:58 +0100 Subject: [PATCH] ci: cancel superseded runs with native concurrency groups cancel-redundant-workflows.yml had some overhead as it was spawning an extra workflow_run job per workflow. With concurrency groups, a new push cancels the PR's previous run directly. A cancelled step can leave its docker container running against the shared sstate. Label containers with the runner name and remove them in the cleanup step. Rename docker-prune-images to docker-cleanup accordingly. Signed-off-by: Andrei Gherzan --- .github/actions/docker-build/action.yml | 2 +- .../action.yml | 11 ++++++++- .../workflows/cancel-redundant-workflows.yml | 23 ------------------- .github/workflows/compliance.yml | 9 ++++++-- .github/workflows/yocto-builds.yml | 9 ++++++-- .github/workflows/yocto-layer.yml | 9 ++++++-- 6 files changed, 32 insertions(+), 31 deletions(-) rename .github/actions/{docker-prune-images => docker-cleanup}/action.yml (52%) delete mode 100644 .github/workflows/cancel-redundant-workflows.yml diff --git a/.github/actions/docker-build/action.yml b/.github/actions/docker-build/action.yml index e844206..b4d1dec 100644 --- a/.github/actions/docker-build/action.yml +++ b/.github/actions/docker-build/action.yml @@ -26,7 +26,7 @@ runs: run: | # Images older than max_age_days are rebuilt so that base image and # package updates are picked up. - # Keep docker-prune-images at twice this. + # Keep docker-cleanup at twice this. max_age_days=7 tag="$(git rev-parse --short=12 HEAD:.github/workflows/docker-images)" image="${{ inputs.docker_image }}:$tag" diff --git a/.github/actions/docker-prune-images/action.yml b/.github/actions/docker-cleanup/action.yml similarity index 52% rename from .github/actions/docker-prune-images/action.yml rename to .github/actions/docker-cleanup/action.yml index d10e385..eef6162 100644 --- a/.github/actions/docker-prune-images/action.yml +++ b/.github/actions/docker-cleanup/action.yml @@ -2,11 +2,20 @@ # # SPDX-License-Identifier: MIT -name: "Prune old CI docker images" +name: "Cleanup CI docker containers and images" runs: using: "composite" steps: + - name: Remove CI containers left on this runner + shell: bash + # A runner executes one job at a time, so any container labelled with + # its name is left over from this job (e.g. after a cancellation) or a + # previous one. + run: | + echo "Removing CI containers left by runner $RUNNER_NAME..." + docker ps -aq --filter "label=meta-raspberrypi-ci.runner=$RUNNER_NAME" | + xargs -r docker rm -f - name: Prune old CI docker images shell: bash # Only images built by docker-build carry the label. Keep this at twice diff --git a/.github/workflows/cancel-redundant-workflows.yml b/.github/workflows/cancel-redundant-workflows.yml deleted file mode 100644 index 556317d..0000000 --- a/.github/workflows/cancel-redundant-workflows.yml +++ /dev/null @@ -1,23 +0,0 @@ -# SPDX-FileCopyrightText: Andrei Gherzan -# -# SPDX-License-Identifier: MIT - -name: Cancel redundant workflows - -on: - workflow_run: - workflows: - - "Builds" - - "Compliance" - - "Yocto Compatible" - types: - - requested - -jobs: - cancel-redundant-workflows: - runs-on: ubuntu-latest - steps: - - uses: styfle/cancel-workflow-action@0.10.0 - with: - all_but_latest: true - workflow_id: ${{ github.event.workflow.id }} diff --git a/.github/workflows/compliance.yml b/.github/workflows/compliance.yml index c87df1c..eba41ba 100644 --- a/.github/workflows/compliance.yml +++ b/.github/workflows/compliance.yml @@ -7,6 +7,10 @@ name: Compliance on: pull_request: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: dco: name: DCO @@ -25,12 +29,13 @@ jobs: - name: Do DCO check run: | docker run --rm --security-opt apparmor=unconfined \ + --label "meta-raspberrypi-ci.runner=$RUNNER_NAME" \ --security-opt seccomp=unconfined \ -v "$GITHUB_WORKSPACE:/work:ro" \ --env "BASE_REF=$GITHUB_BASE_REF" \ "${{ steps.docker.outputs.image }}" - - name: Prune old CI docker images - uses: ./.github/actions/docker-prune-images + - name: Cleanup CI docker containers and images + uses: ./.github/actions/docker-cleanup if: always() - name: Cleanup dangling docker images uses: ./.github/actions/docker-clean-dangling diff --git a/.github/workflows/yocto-builds.yml b/.github/workflows/yocto-builds.yml index 0bb390d..47d9a08 100644 --- a/.github/workflows/yocto-builds.yml +++ b/.github/workflows/yocto-builds.yml @@ -9,6 +9,10 @@ name: Builds on: pull_request: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: build: strategy: @@ -48,6 +52,7 @@ jobs: - name: Build the image run: | docker run --rm --security-opt apparmor=unconfined \ + --label "meta-raspberrypi-ci.runner=$RUNNER_NAME" \ --security-opt seccomp=unconfined \ -v "$GITHUB_WORKSPACE:/work:ro" \ -v "$DL_DIR:$DL_DIR:rw" \ @@ -62,8 +67,8 @@ jobs: "${{ steps.docker.outputs.image }}" \ /entrypoint-build.sh if: steps.changed-files-specific.outputs.any_changed == 'true' - - name: Prune old CI docker images - uses: ./.github/actions/docker-prune-images + - name: Cleanup CI docker containers and images + uses: ./.github/actions/docker-cleanup if: always() - name: Cleanup dangling docker images uses: ./.github/actions/docker-clean-dangling diff --git a/.github/workflows/yocto-layer.yml b/.github/workflows/yocto-layer.yml index 1b43b41..2ea0d6a 100644 --- a/.github/workflows/yocto-layer.yml +++ b/.github/workflows/yocto-layer.yml @@ -9,6 +9,10 @@ name: Yocto Compatible on: pull_request: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: yocto-check-layer: name: Validate with yocto-check-layer @@ -31,13 +35,14 @@ jobs: - name: Run yocto-check-layer run: | docker run --rm --security-opt apparmor=unconfined \ + --label "meta-raspberrypi-ci.runner=$RUNNER_NAME" \ -v "$GITHUB_WORKSPACE:/work:ro" \ --env "BASE_REF=$GITHUB_BASE_REF" \ "${{ steps.docker.outputs.image }}" \ /entrypoint-yocto-check-layer.sh if: steps.changed-files-specific.outputs.any_changed == 'true' - - name: Prune old CI docker images - uses: ./.github/actions/docker-prune-images + - name: Cleanup CI docker containers and images + uses: ./.github/actions/docker-cleanup if: always() - name: Cleanup dangling docker images uses: ./.github/actions/docker-clean-dangling