Skip to content

Commit

Permalink
Merge pull request #296 from Lombiq/issue/OSOE-743
Browse files Browse the repository at this point in the history
OSOE-743: Cancel ongoing runs of long-running workflows under a PR when new changes are pushed, vol.2
  • Loading branch information
BenedekFarkas authored Dec 10, 2023
2 parents 4342231 + 2d30008 commit 3f25d64
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 23 deletions.
40 changes: 36 additions & 4 deletions .github/workflows/build-and-test-dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,22 @@ on:
are used.
inputs:
cancel-in-progress-for-this-pr:
description: >
When set to "true", it will cancel the already running workflow for this pull request. See the concurrency
settings of the job for more details.
type: string
default: 'true'
parent-job-name:
description: >
An optional technical identifier that is used to construct the concurrency key to be able to distinguish
different jobs in the same parent workflow calling this one. This is necessary if you build multiple solutions
(as separate jobs) in the same workflow for these jobs not to conflict with each other.
type: string
default: 'parent-job'
required: false
cancel-workflow-on-failure:
description: When set to "true", will cancel the current workflow run with all jobs if this workflow fails.
description: When set to "true", it will cancel the current workflow run with all jobs if this workflow fails.
type: string
default: 'true'
# This needs to be stringified JSON because inputs don't support arrays, see
Expand Down Expand Up @@ -59,14 +73,14 @@ on:
default: 'false'
description: >
If set to "true", the NuGet packages will be cached by GitHub. This is faster if you have a lot of NuGet
packages, but negligible or even slower if you only have a handful. When run on BuildJet, will use the
packages, but negligible or even slower if you only have a handful. When run on BuildJet, it will use the
BuildJet cache instead of GitHub's, which is faster.
build-enable-npm-caching:
type: string
default: 'false'
description: >
If set to "true", the NPM packages will be cached by GitHub. This is faster if you have a lot of NPM packages,
packages, but negligible or even slower if you only have a handful. When run on BuildJet, will use the
packages, but negligible or even slower if you only have a handful. When run on BuildJet, it will use the
BuildJet cache instead of GitHub's, which is faster.
build-cache-version:
type: string
Expand Down Expand Up @@ -115,7 +129,7 @@ on:
dotnet-consolidation-exclude-version-regex:
type: string
required: false
default: "-alpha"
default: '-alpha'
description: >
A regular expression to match package versions that will be skipped during NuGet package consolidation.
warnings-as-errors:
Expand All @@ -135,9 +149,27 @@ jobs:
runs-on: ${{ matrix.machine-type }}
name: Build and Test
strategy:
# The parameters added to the strategy matrix should also be used to construct the concurrency key.
matrix:
machine-type: ${{ fromJson(inputs.machine-types) }}
timeout-minutes: ${{ inputs.timeout-minutes }}
concurrency:
# If "cancel-in-progress-for-this-pr" is set to "true" and this run is for a pull request, then the concurrency
# key will be constructed from a handful of parameters to produce a value that would evaluate to the same value on
# a subsequent push (while still allowing different solutions to be built with the same configuration), causing
# the already running job (with the same strategy) for this pull request to be cancelled. Otherwise it will be the
# ID of the workflow run combined with the strategy parameters, making it more unique so that parallel runs of
# this job aren't kept waiting. This workflow's technical name is also included in both cases, so that it doesn't
# conflict with other jobs calling a different workflow that are started by the same caller workflow. The caller
# job's technical name is optionally included in the concurrency key, so that different jobs in the same parent
# workflow calling this one don't conflict with each other.
group: |
${{
inputs.cancel-in-progress-for-this-pr == 'true' && github.event_name == 'pull_request'
&& format('{0}_build-and-test-dotnet_{1}_{2}_{3}', github.workflow, inputs.parent-job-name, matrix.machine-type, github.ref)
|| format('{0}_build-and-test-dotnet_{1}_{2}', github.run_id, inputs.parent-job-name, matrix.machine-type)
}}
cancel-in-progress: ${{ inputs.cancel-in-progress-for-this-pr == 'true' }}
steps:
- name: Checkout
uses: Lombiq/GitHub-Actions/.github/actions/checkout@dev
Expand Down
36 changes: 34 additions & 2 deletions .github/workflows/build-and-test-orchard-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,22 @@ on:
are used.
inputs:
cancel-in-progress-for-this-pr:
description: >
When set to "true", it will cancel the already running workflow for this pull request. See the concurrency
settings of the job for more details.
type: string
default: 'true'
parent-job-name:
description: >
An optional technical identifier that is used to construct the concurrency key to be able to distinguish
different jobs in the same parent workflow calling this one. This is necessary if you build multiple solutions
(as separate jobs) in the same workflow for these jobs not to conflict with each other.
type: string
default: 'parent-job'
required: false
cancel-workflow-on-failure:
description: If "true", will cancel the current workflow run with all jobs if this workflow fails.
description: When set to "true", it will cancel the current workflow run with all jobs if this workflow fails.
type: string
default: 'true'
# This needs to be stringified JSON, because inputs don't support arrays, see
Expand Down Expand Up @@ -142,7 +156,7 @@ on:
dotnet-consolidation-exclude-version-regex:
type: string
required: false
default: "-alpha"
default: '-alpha'
description: >
A regular expression to match package versions that will be skipped during NuGet package consolidation.
warnings-as-errors:
Expand All @@ -158,9 +172,27 @@ jobs:
runs-on: ${{ matrix.machine-type }}
name: Build and Test
strategy:
# The parameters added to the strategy matrix should also be used to construct the concurrency key.
matrix:
machine-type: ${{ fromJson(inputs.machine-types) }}
timeout-minutes: ${{ inputs.timeout-minutes }}
concurrency:
# If "cancel-in-progress-for-this-pr" is set to "true" and this run is for a pull request, then the concurrency
# key will be constructed from a handful of parameters to produce a value that would evaluate to the same value on
# a subsequent push (while still allowing different solutions to be built with the same configuration), causing
# the already running job (with the same strategy) for this pull request to be cancelled. Otherwise it will be the
# ID of the workflow run combined with the strategy parameters, making it more unique so that parallel runs of
# this job aren't kept waiting. This workflow's technical name is also included in both cases, so that it doesn't
# conflict with other jobs calling a different workflow that are started by the same caller workflow. The caller
# job's technical name is optionally included in the concurrency key, so that different jobs in the same parent
# workflow calling this one don't conflict with each other.
group: |
${{
inputs.cancel-in-progress-for-this-pr == 'true' && github.event_name == 'pull_request'
&& format('{0}_build-and-test-orchard-core_{1}_{2}_{3}', github.workflow, inputs.parent-job-name, matrix.machine-type, github.ref)
|| format('{0}_build-and-test-orchard-core_{1}_{2}', github.run_id, inputs.parent-job-name, matrix.machine-type)
}}
cancel-in-progress: ${{ inputs.cancel-in-progress-for-this-pr == 'true' }}
steps:
- name: Checkout
uses: Lombiq/GitHub-Actions/.github/actions/checkout@dev
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
inputs:
cancel-workflow-on-failure:
description: When set to "true", will cancel the current workflow run with all jobs if this workflow fails.
description: When set to "true", it will cancel the current workflow run with all jobs if this workflow fails.
type: string
default: 'true'
# This needs to be stringified JSON because inputs don't support arrays, see
Expand Down Expand Up @@ -44,7 +44,7 @@ on:
default: 'false'
description: >
If set to "true", the NuGet packages will be cached by GitHub. This is faster if you have a lot of NuGet
packages, but negligible or even slower if you only have a handful. When run on BuildJet, will use the
packages, but negligible or even slower if you only have a handful. When run on BuildJet, it will use the
BuildJet cache instead of GitHub's, which is faster.
build-enable-npm-caching:
type: string
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-orchard1-to-azure-app-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ on:

inputs:
cancel-workflow-on-failure:
description: When set to "true", will cancel the current workflow run with all jobs if this workflow fails.
description: When set to "true", it will cancel the current workflow run with all jobs if this workflow fails.
type: string
default: 'false'
timeout-minutes:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/deploy-to-azure-app-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ on:

inputs:
cancel-workflow-on-failure:
description: When set to "true", will cancel the current workflow run with all jobs if this workflow fails.
description: When set to "true", it will cancel the current workflow run with all jobs if this workflow fails.
type: string
default: 'false'
machine-type:
Expand Down Expand Up @@ -69,14 +69,14 @@ on:
default: 'false'
description: >
If set to "true", the NuGet packages will be cached by GitHub. This is faster if you have a lot of NuGet
packages, but negligible or even slower if you only have a handful. When run on BuildJet, will use the
packages, but negligible or even slower if you only have a handful. When run on BuildJet, it will use the
BuildJet cache instead of GitHub's, which is faster.
build-enable-npm-caching:
type: string
default: 'false'
description: >
If set to "true", the NPM packages will be cached by GitHub. This is faster if you have a lot of NPM packages,
packages, but negligible or even slower if you only have a handful. When run on BuildJet, will use the
packages, but negligible or even slower if you only have a handful. When run on BuildJet, it will use the
BuildJet cache instead of GitHub's, which is faster.
build-cache-version:
type: string
Expand Down
36 changes: 34 additions & 2 deletions .github/workflows/msbuild-and-test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
name: Build and Test .NET Solution with MSBuild

concurrency:
# If "cancel-in-progress-for-this-pr" is set to "true" and this run is for a pull request, then the concurrency
# key will be constructed from a handful of parameters to produce a value that would evaluate to the same value on
# a subsequent push (while still allowing different solutions to be built with the same configuration), causing
# the already running job (with the same strategy) for this pull request to be cancelled. Otherwise it will be the
# ID of the workflow run combined with the strategy parameters, making it more unique so that parallel runs of
# this job aren't kept waiting. This workflow's technical name is also included in both cases, so that it doesn't
# conflict with other jobs calling a different workflow that are started by the same caller workflow. The caller
# job's technical name is optionally included in the concurrency key, so that different jobs in the same parent
# workflow calling this one don't conflict with each other.
group: |
${{
inputs.cancel-in-progress-for-this-pr == 'true' && github.event_name == 'pull_request'
&& format('{0}_msbuild-and-test_{1}_{2}_{3}', github.workflow, inputs.parent-job-name, inputs.machine-type, github.ref)
|| format('{0}_msbuild-and-test_{1}_{2}', github.run_id, inputs.parent-job-name, inputs.machine-type)
}}
cancel-in-progress: ${{ inputs.cancel-in-progress-for-this-pr == 'true' }}

on:
workflow_call:
secrets:
Expand All @@ -10,8 +28,22 @@ on:
are used.
inputs:
cancel-in-progress-for-this-pr:
description: >
When set to "true", it will cancel the already running workflow for this pull request. See the concurrency
settings of the workflow above for more details.
type: string
default: 'true'
parent-job-name:
description: >
An optional technical identifier that is used to construct the concurrency key to be able to distinguish
different jobs in the same parent workflow calling this one. This is necessary if you build multiple solutions
(as separate jobs) in the same workflow for these jobs not to conflict with each other.
type: string
default: 'parent-job'
required: false
cancel-workflow-on-failure:
description: When set to "true", will cancel the current workflow run with all jobs if this workflow fails.
description: When set to "true", it will cancel the current workflow run with all jobs if this workflow fails.
type: string
default: 'true'
machine-type:
Expand Down Expand Up @@ -93,7 +125,7 @@ jobs:
build-directory: ${{ inputs.build-directory }}
test-verbosity: ${{ inputs.build-verbosity }}
test-filter: ${{ inputs.test-filter }}
test-configuration: "Release"
test-configuration: 'Release'

- name: Cancel Workflow on Failure
if: failure() && inputs.cancel-workflow-on-failure == 'true'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:

inputs:
cancel-workflow-on-failure:
description: When set to "true", will cancel the current workflow run with all jobs if this workflow fails.
description: When set to "true", it will cancel the current workflow run with all jobs if this workflow fails.
type: string
default: 'true'
source:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reset-azure-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ on:

inputs:
cancel-workflow-on-failure:
description: When set to "true", will cancel the current workflow run with all jobs if this workflow fails.
description: When set to "true", it will cancel the current workflow run with all jobs if this workflow fails.
type: string
default: 'false'
machine-type:
Expand Down
24 changes: 23 additions & 1 deletion .github/workflows/spelling.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
name: Spelling

concurrency:
# If "cancel-in-progress-for-this-pr" is set to "true" and this is running for a pull request, then the concurrency
# key will be constructed from the name of the workflow and the branch name, causing the already running job in this
# workflow for this pull request to be cancelled. Otherwise it will be the ID of the workflow run, making it globally
# unique and not cancel anything. Concurrency is defined for the whole workflow, because it has only two jobs
# (check-spelling and comment-pr) and the latter depends on the former, so they won't run in parallel. A technical
# name for this workflow is also included in both cases, so that it doesn't come into conflict with other jobs calling
# a different workflow that are started by the same caller workflow.
group: |
${{
inputs.cancel-in-progress-for-this-pr == 'true' && github.event_name == 'pull_request'
&& format('{0}_spell-checking_{1}', github.workflow, github.ref)
|| format('{0}_spell-checking', github.run_id)
}}
cancel-in-progress: ${{ inputs.cancel-in-progress-for-this-pr == 'true' }}

on:
workflow_call:
secrets:
Expand All @@ -11,8 +27,14 @@ on:
# When updating defaults here also update them in the `spelling` action.
inputs:
cancel-in-progress-for-this-pr:
description: >
When set to "true", it will cancel the already running workflow for this pull request. See the concurrency
settings of the workflow above for more details.
type: string
default: 'true'
cancel-workflow-on-failure:
description: When set to "true", will cancel the current workflow run with all jobs if this workflow fails.
description: When set to "true", it will cancel the current workflow run with all jobs if this workflow fails.
type: string
default: 'true'
merge-file-excludes:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/swap-azure-web-app-slots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ on:
inputs:
cancel-workflow-on-failure:
description: When set to "true", will cancel the current workflow run with all jobs if this workflow fails.
description: When set to "true", it will cancel the current workflow run with all jobs if this workflow fails.
type: string
default: 'false'
machine-type:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/swap-orchard1-azure-web-app-slots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ on:

inputs:
cancel-workflow-on-failure:
description: When set to "true", will cancel the current workflow run with all jobs if this workflow fails.
description: When set to "true", it will cancel the current workflow run with all jobs if this workflow fails.
type: string
default: 'false'
machine-type:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test-analysis-failure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
inputs:
cancel-workflow-on-failure:
description: When set to "true", will cancel the current workflow run with all jobs if this workflow fails.
description: When set to "true", it will cancel the current workflow run with all jobs if this workflow fails.
type: string
default: 'true'
# This needs to be stringified JSON because inputs don't support arrays, see
Expand All @@ -36,14 +36,14 @@ on:
default: 'false'
description: >
If set to "true", the NuGet packages will be cached by GitHub. This is faster if you have a lot of NuGet
packages, but negligible or even slower if you only have a handful. When run on BuildJet, will use the
packages, but negligible or even slower if you only have a handful. When run on BuildJet, it will use the
BuildJet cache instead of GitHub's, which is faster.
build-enable-npm-caching:
type: string
default: 'false'
description: >
If set to "true", the NPM packages will be cached by GitHub. This is faster if you have a lot of NPM packages,
packages, but negligible or even slower if you only have a handful. When run on BuildJet, will use the
packages, but negligible or even slower if you only have a handful. When run on BuildJet, it will use the
BuildJet cache instead of GitHub's, which is faster.
build-cache-version:
type: string
Expand Down
Loading

0 comments on commit 3f25d64

Please sign in to comment.