Skip to content

Commit

Permalink
Move GH Actions concurrency group to root level
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma committed Feb 19, 2024
1 parent 59bdf80 commit 4b799cc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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())
{
Expand Down
6 changes: 3 additions & 3 deletions source/Nuke.Common/CI/GitHubActions/GitHubActionsAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ public override ConfigurationEntity GetConfiguration(IReadOnlyCollection<Executa
DetailedTriggers = GetTriggers().ToArray(),
Permissions = WritePermissions.Select(x => (x, "write"))
.Concat(ReadPermissions.Select(x => (x, "read"))).ToArray(),
ConcurrencyGroup = JobConcurrencyGroup,
ConcurrencyCancelInProgress = JobConcurrencyCancelInProgress,
Jobs = _images.Select(x => GetJobs(x, relevantTargets)).ToArray()
};

Expand All @@ -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
};
}

Expand Down

0 comments on commit 4b799cc

Please sign in to comment.