diff --git a/source/Nuke.Common.Tests/CI/ConfigurationGenerationTest.Test_testName=detailed-triggers_attribute=GitHubActionsAttribute.verified.txt b/source/Nuke.Common.Tests/CI/ConfigurationGenerationTest.Test_testName=detailed-triggers_attribute=GitHubActionsAttribute.verified.txt index 09545feca..558551259 100644 --- a/source/Nuke.Common.Tests/CI/ConfigurationGenerationTest.Test_testName=detailed-triggers_attribute=GitHubActionsAttribute.verified.txt +++ b/source/Nuke.Common.Tests/CI/ConfigurationGenerationTest.Test_testName=detailed-triggers_attribute=GitHubActionsAttribute.verified.txt @@ -44,14 +44,15 @@ on: schedule: - cron: '* 0 * * *' +concurrency: + group: ${{{{ github.workflow }}}} @ ${{{{ github.event.pull_request.head.label || github.head_ref || github.run_id }}}} + cancel-in-progress: true + jobs: macos-latest: name: macos-latest runs-on: macos-latest timeout-minutes: 30 - concurrency: - group: ${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.run_id }} - cancel-in-progress: true steps: - uses: actions/checkout@v3 with: @@ -92,9 +93,6 @@ jobs: name: ubuntu-latest runs-on: ubuntu-latest timeout-minutes: 30 - concurrency: - group: ${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.run_id }} - cancel-in-progress: true steps: - uses: actions/checkout@v3 with: @@ -135,9 +133,6 @@ jobs: name: windows-latest runs-on: windows-latest timeout-minutes: 30 - concurrency: - group: ${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.run_id }} - cancel-in-progress: true steps: - uses: actions/checkout@v3 with: diff --git a/source/Nuke.Common/CI/GitHubActions/Configuration/GitHubActionsConfiguration.cs b/source/Nuke.Common/CI/GitHubActions/Configuration/GitHubActionsConfiguration.cs index bd1425827..233a05b2a 100644 --- a/source/Nuke.Common/CI/GitHubActions/Configuration/GitHubActionsConfiguration.cs +++ b/source/Nuke.Common/CI/GitHubActions/Configuration/GitHubActionsConfiguration.cs @@ -18,6 +18,8 @@ public class GitHubActionsConfiguration : ConfigurationEntity public GitHubActionsTrigger[] ShortTriggers { get; set; } public GitHubActionsDetailedTrigger[] DetailedTriggers { get; set; } public (GitHubActionsPermissions Type, string Permission)[] Permissions { get; set; } + public string ConcurrencyGroup { get; set; } + public bool ConcurrencyCancelInProgress { get; set; } public GitHubActionsJob[] Jobs { get; set; } public override void Write(CustomFileWriter writer) @@ -46,6 +48,28 @@ public override void Write(CustomFileWriter writer) } } + if (!ConcurrencyGroup.IsNullOrWhiteSpace() || ConcurrencyCancelInProgress) + { + writer.WriteLine(); + writer.WriteLine("concurrency:"); + using (writer.Indent()) + { + var group = ConcurrencyGroup; + if (group.IsNullOrWhiteSpace()) + { + // create a default value that only cancels in-progress runs of the same workflow + // we don't fall back to github.ref which would disable multiple runs in main/master which is usually what is wanted + group = "${{{{ github.workflow }}}} @ ${{{{ github.event.pull_request.head.label || github.head_ref || github.run_id }}}}"; + } + + writer.WriteLine($"group: {group}"); + if (ConcurrencyCancelInProgress) + { + writer.WriteLine("cancel-in-progress: true"); + } + } + } + writer.WriteLine(); writer.WriteLine("jobs:"); diff --git a/source/Nuke.Common/CI/GitHubActions/Configuration/GitHubActionsJob.cs b/source/Nuke.Common/CI/GitHubActions/Configuration/GitHubActionsJob.cs index 61dc3e4e8..d2bf59089 100644 --- a/source/Nuke.Common/CI/GitHubActions/Configuration/GitHubActionsJob.cs +++ b/source/Nuke.Common/CI/GitHubActions/Configuration/GitHubActionsJob.cs @@ -17,8 +17,6 @@ public class GitHubActionsJob : ConfigurationEntity public string Name { get; set; } public GitHubActionsImage Image { get; set; } public int TimeoutMinutes { get; set; } - public string ConcurrencyGroup { get; set; } - public bool ConcurrencyCancelInProgress { get; set; } public GitHubActionsStep[] Steps { get; set; } public override void Write(CustomFileWriter writer) @@ -35,27 +33,6 @@ public override void Write(CustomFileWriter writer) writer.WriteLine($"timeout-minutes: {TimeoutMinutes}"); } - if (!ConcurrencyGroup.IsNullOrWhiteSpace() || ConcurrencyCancelInProgress) - { - writer.WriteLine("concurrency:"); - using (writer.Indent()) - { - var group = ConcurrencyGroup; - if (group.IsNullOrWhiteSpace()) - { - // create a default value that only cancels in-progress runs of the same workflow - // we don't fall back to github.ref which would disable multiple runs in main/master which is usually what is wanted - group = "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.run_id }}"; - } - - writer.WriteLine($"group: {group}"); - if (ConcurrencyCancelInProgress) - { - writer.WriteLine("cancel-in-progress: true"); - } - } - } - writer.WriteLine("steps:"); using (writer.Indent()) { diff --git a/source/Nuke.Common/CI/GitHubActions/GitHubActionsAttribute.cs b/source/Nuke.Common/CI/GitHubActions/GitHubActionsAttribute.cs index 497702c69..c298e11f8 100644 --- a/source/Nuke.Common/CI/GitHubActions/GitHubActionsAttribute.cs +++ b/source/Nuke.Common/CI/GitHubActions/GitHubActionsAttribute.cs @@ -112,6 +112,8 @@ public override ConfigurationEntity GetConfiguration(IReadOnlyCollection (x, "write")) .Concat(ReadPermissions.Select(x => (x, "read"))).ToArray(), + ConcurrencyGroup = JobConcurrencyGroup, + ConcurrencyCancelInProgress = JobConcurrencyCancelInProgress, Jobs = _images.Select(x => GetJobs(x, relevantTargets)).ToArray() }; @@ -130,9 +132,7 @@ protected virtual GitHubActionsJob GetJobs(GitHubActionsImage image, IReadOnlyCo Name = image.GetValue().Replace(".", "_"), Steps = GetSteps(image, relevantTargets).ToArray(), Image = image, - TimeoutMinutes = TimeoutMinutes, - ConcurrencyGroup = JobConcurrencyGroup, - ConcurrencyCancelInProgress = JobConcurrencyCancelInProgress + TimeoutMinutes = TimeoutMinutes }; }