Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add separate GH Actions root level concurrency group #1299

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ 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 }}
group: custom-job-group
cancel-in-progress: true
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -93,7 +97,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 30
concurrency:
group: ${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.run_id }}
group: custom-job-group
cancel-in-progress: true
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -136,7 +140,7 @@ jobs:
runs-on: windows-latest
timeout-minutes: 30
concurrency:
group: ${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.run_id }}
group: custom-job-group
cancel-in-progress: true
steps:
- uses: actions/checkout@v3
Expand Down
4 changes: 3 additions & 1 deletion source/Nuke.Common.Tests/CI/ConfigurationGenerationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ yield return
Lfs = true,
FetchDepth = 2,
TimeoutMinutes = 30,
JobConcurrencyCancelInProgress = true
ConcurrencyCancelInProgress = true,
JobConcurrencyCancelInProgress = true,
JobConcurrencyGroup = "custom-job-group"
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:");
Expand Down
5 changes: 5 additions & 0 deletions source/Nuke.Common/CI/GitHubActions/GitHubActionsAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public class GitHubActionsAttribute : ConfigurationAttributeBase

public int TimeoutMinutes { get; set; }

public string ConcurrencyGroup { get; set; }
public bool ConcurrencyCancelInProgress { get; set; }

public string JobConcurrencyGroup { get; set; }
public bool JobConcurrencyCancelInProgress { get; set; }

Expand Down Expand Up @@ -112,6 +115,8 @@ public override ConfigurationEntity GetConfiguration(IReadOnlyCollection<Executa
DetailedTriggers = GetTriggers().ToArray(),
Permissions = WritePermissions.Select(x => (x, "write"))
.Concat(ReadPermissions.Select(x => (x, "read"))).ToArray(),
ConcurrencyGroup = ConcurrencyGroup,
ConcurrencyCancelInProgress = ConcurrencyCancelInProgress,
Jobs = _images.Select(x => GetJobs(x, relevantTargets)).ToArray()
};

Expand Down
Loading