Skip to content

Commit ad61c67

Browse files
committed
Cancel old workflow runs for the same PR or ref
1 parent a408856 commit ad61c67

7 files changed

+24
-2
lines changed

.github/workflows/check-action-typing.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ name: 'Check Action Typing'
2020
on:
2121
push: {}
2222
pull_request: {}
23+
concurrency:
24+
group: '${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}'
25+
cancel-in-progress: true
2326
jobs:
2427
check_yaml_consistency:
2528
name: 'Check YAML consistency'

.github/workflows/check-all-workflow-yaml-consistency.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ name: 'Check all Workflow YAML Consistency'
2020
on:
2121
push: {}
2222
pull_request: {}
23+
concurrency:
24+
group: '${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}'
25+
cancel-in-progress: true
2326
jobs:
2427
check_yaml_consistency:
2528
name: 'Check YAML consistency'

.github/workflows/check-dependency-versions.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ name: 'Check Dependency Versions'
2020
on:
2121
schedule:
2222
- cron: '0 0 * * FRI'
23+
concurrency:
24+
group: '${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}'
25+
cancel-in-progress: true
2326
jobs:
2427
check_yaml_consistency:
2528
name: 'Check YAML consistency'

.github/workflows/test.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ on:
2222
pull_request: {}
2323
schedule:
2424
- cron: '0 0 * * *'
25+
concurrency:
26+
group: '${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}'
27+
cancel-in-progress: true
2528
jobs:
2629
check_yaml_consistency:
2730
name: 'Check YAML consistency'

.github/workflows/validate-gradle-wrapper.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ name: 'Validate Gradle Wrapper'
2020
on:
2121
push: {}
2222
pull_request: {}
23+
concurrency:
24+
group: '${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}'
25+
cancel-in-progress: true
2326
jobs:
2427
check_yaml_consistency:
2528
name: 'Check YAML consistency'

.github/workflows/verify-release.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ on:
2222
tags:
2323
- 'v*'
2424
workflow_dispatch: {}
25+
concurrency:
26+
group: '${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}'
27+
cancel-in-progress: true
2528
jobs:
2629
check_yaml_consistency:
2730
name: 'Check YAML consistency'

.github/workflows/workflow-with-copyright.main.kts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import io.github.typesafegithub.workflows.domain.Concurrency
2121
import io.github.typesafegithub.workflows.domain.triggers.Trigger
2222
import io.github.typesafegithub.workflows.dsl.WorkflowBuilder
23+
import io.github.typesafegithub.workflows.dsl.expressions.Contexts.github
24+
import io.github.typesafegithub.workflows.dsl.expressions.expr
2325
import io.github.typesafegithub.workflows.dsl.workflow
2426
import io.github.typesafegithub.workflows.yaml.Preamble.WithOriginalAfter
2527
import java.io.File
@@ -29,15 +31,17 @@ fun workflowWithCopyright(
2931
on: List<Trigger>,
3032
env: Map<String, String> = mapOf(),
3133
sourceFile: File,
32-
concurrency: Concurrency? = null,
3334
block: WorkflowBuilder.() -> Unit
3435
) {
3536
workflow(
3637
name = name,
3738
on = on,
3839
env = env,
3940
sourceFile = sourceFile,
40-
concurrency = concurrency,
41+
concurrency = Concurrency(
42+
group = "${expr { github.workflow }}-${expr("${github.eventPullRequest.pull_request.number} || ${github.ref}")}",
43+
cancelInProgress = true
44+
),
4145
preamble = WithOriginalAfter(
4246
"""
4347
Copyright 2020-2025 Björn Kautler

0 commit comments

Comments
 (0)