From 8116d650f89aea13a5617f6302c55d1e701f5d5d Mon Sep 17 00:00:00 2001 From: Erik van Oosten Date: Tue, 25 Jun 2024 10:41:41 +0200 Subject: [PATCH] Prevent concurrent builds on branches (#406) Prevent multiple builds at the same time from the same branch by cancelling the earlier builds. The default branch (e.g. master) is exempted, that is, builds from the default branch may run concurrently. --- .github/workflows/ci.yml | 3 +++ .../src/main/scala/zio/sbt/githubactions/model.scala | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5eb34202..b177da0f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,6 +15,9 @@ env: pull_request: branches-ignore: - gh-pages +concurrency: + group: ${{ github.workflow }}-${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && github.run_id || github.ref }} + cancel-in-progress: true jobs: build: name: Build diff --git a/zio-sbt-githubactions/src/main/scala/zio/sbt/githubactions/model.scala b/zio-sbt-githubactions/src/main/scala/zio/sbt/githubactions/model.scala index 8f2da7dd..a3a6d142 100644 --- a/zio-sbt-githubactions/src/main/scala/zio/sbt/githubactions/model.scala +++ b/zio-sbt-githubactions/src/main/scala/zio/sbt/githubactions/model.scala @@ -316,6 +316,12 @@ object Workflow { .map(_.toKeyValuePair): _* ) }), + "concurrency" := Json.obj( + "group" := Json.fromString( + "${{ github.workflow }}-${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && github.run_id || github.ref }}" + ), + "cancel-in-progress" := true + ), "jobs" := Json.obj(wf.jobs.map(job => job.id := job): _*) ) }