From 643d772babb9886f6a1c0d0944c008e52cfdb259 Mon Sep 17 00:00:00 2001 From: Austin Seipp Date: Tue, 5 Nov 2024 23:34:59 -0600 Subject: [PATCH] github: cancel in-progress builds on stale PRs When a pull request is pushed multiple times in sequence (e.g. to fix small errors that are noticed post-submission), a backlog of builds ends up needing to be cleared out before your new update can be built. If you push N times, N builds are queued and need to clear out first. This can cause higher latency for *every* PR since the pool of public runners is shared, and in general seems uneconomical and inefficient since 99% of the time you want to build the new version ASAP. Luckily GHA has a universal solution to this: use the `concurrency` directive to group all builds for a PR under a name, and when a new build appears in that group, cancel all builds in the group that are in-progress. Taken from this useful blog post: "Simple trick to save environment and money when using GitHub Actions" https://turso.tech/blog/simple-trick-to-save-environment-and-money-when-using-github-actions Signed-off-by: Austin Seipp --- .github/workflows/build-nix.yml | 4 ++++ .github/workflows/build.yml | 4 ++++ .github/workflows/codespell.yml | 4 ++++ .github/workflows/dependabot.yml | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/.github/workflows/build-nix.yml b/.github/workflows/build-nix.yml index 380c67a94e..73f1fb4a84 100644 --- a/.github/workflows/build-nix.yml +++ b/.github/workflows/build-nix.yml @@ -6,6 +6,10 @@ on: - main pull_request: +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + permissions: read-all jobs: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 118f48a702..2447c7f8de 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,6 +4,10 @@ on: push: pull_request: +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + permissions: read-all env: diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml index 03e097c028..37870813be 100644 --- a/.github/workflows/codespell.yml +++ b/.github/workflows/codespell.yml @@ -6,6 +6,10 @@ on: - main pull_request: +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + permissions: read-all jobs: diff --git a/.github/workflows/dependabot.yml b/.github/workflows/dependabot.yml index 41ccb0598a..7b935d2e98 100644 --- a/.github/workflows/dependabot.yml +++ b/.github/workflows/dependabot.yml @@ -3,6 +3,10 @@ name: Enable auto-merge for Dependabot PRs on: pull_request: +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + permissions: read-all jobs: