Skip to content

Commit

Permalink
Cancel old workflow runs for the same PR or ref
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed Feb 3, 2025
1 parent a408856 commit ad61c67
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/check-action-typing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ name: 'Check Action Typing'
on:
push: {}
pull_request: {}
concurrency:
group: '${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}'
cancel-in-progress: true
jobs:
check_yaml_consistency:
name: 'Check YAML consistency'
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/check-all-workflow-yaml-consistency.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ name: 'Check all Workflow YAML Consistency'
on:
push: {}
pull_request: {}
concurrency:
group: '${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}'
cancel-in-progress: true
jobs:
check_yaml_consistency:
name: 'Check YAML consistency'
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/check-dependency-versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ name: 'Check Dependency Versions'
on:
schedule:
- cron: '0 0 * * FRI'
concurrency:
group: '${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}'
cancel-in-progress: true
jobs:
check_yaml_consistency:
name: 'Check YAML consistency'
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ on:
pull_request: {}
schedule:
- cron: '0 0 * * *'
concurrency:
group: '${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}'
cancel-in-progress: true
jobs:
check_yaml_consistency:
name: 'Check YAML consistency'
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/validate-gradle-wrapper.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ name: 'Validate Gradle Wrapper'
on:
push: {}
pull_request: {}
concurrency:
group: '${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}'
cancel-in-progress: true
jobs:
check_yaml_consistency:
name: 'Check YAML consistency'
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/verify-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ on:
tags:
- 'v*'
workflow_dispatch: {}
concurrency:
group: '${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}'
cancel-in-progress: true
jobs:
check_yaml_consistency:
name: 'Check YAML consistency'
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/workflow-with-copyright.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import io.github.typesafegithub.workflows.domain.Concurrency
import io.github.typesafegithub.workflows.domain.triggers.Trigger
import io.github.typesafegithub.workflows.dsl.WorkflowBuilder
import io.github.typesafegithub.workflows.dsl.expressions.Contexts.github
import io.github.typesafegithub.workflows.dsl.expressions.expr
import io.github.typesafegithub.workflows.dsl.workflow
import io.github.typesafegithub.workflows.yaml.Preamble.WithOriginalAfter
import java.io.File
Expand All @@ -29,15 +31,17 @@ fun workflowWithCopyright(
on: List<Trigger>,
env: Map<String, String> = mapOf(),
sourceFile: File,
concurrency: Concurrency? = null,
block: WorkflowBuilder.() -> Unit
) {
workflow(
name = name,
on = on,
env = env,
sourceFile = sourceFile,
concurrency = concurrency,
concurrency = Concurrency(
group = "${expr { github.workflow }}-${expr("${github.eventPullRequest.pull_request.number} || ${github.ref}")}",
cancelInProgress = true
),
preamble = WithOriginalAfter(
"""
Copyright 2020-2025 Björn Kautler
Expand Down

0 comments on commit ad61c67

Please sign in to comment.