Skip to content

Commit 7e092a1

Browse files
committed
Add GitHub actions/setup-dotnet support
1 parent a6ac068 commit 7e092a1

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

source/Nuke.Common.Tests/CI/ConfigurationGenerationTest.Test_testName=detailed-triggers_attribute=GitHubActionsAttribute.verified.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ jobs:
7474
.nuke/temp
7575
~/.nuget/packages
7676
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj', '**/Directory.Packages.props') }}
77+
- uses: actions/setup-dotnet@v5
78+
with:
79+
dotnet-version: |
80+
8.0
81+
9.0
82+
10.0
7783
- name: 'Run: Test'
7884
run: ./build.cmd Test
7985
env:
@@ -122,6 +128,12 @@ jobs:
122128
.nuke/temp
123129
~/.nuget/packages
124130
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj', '**/Directory.Packages.props') }}
131+
- uses: actions/setup-dotnet@v5
132+
with:
133+
dotnet-version: |
134+
8.0
135+
9.0
136+
10.0
125137
- name: 'Run: Test'
126138
run: ./build.cmd Test
127139
env:
@@ -170,6 +182,12 @@ jobs:
170182
.nuke/temp
171183
~/.nuget/packages
172184
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj', '**/Directory.Packages.props') }}
185+
- uses: actions/setup-dotnet@v5
186+
with:
187+
dotnet-version: |
188+
8.0
189+
9.0
190+
10.0
173191
- name: 'Run: Test'
174192
run: ./build.cmd Test
175193
env:

source/Nuke.Common.Tests/CI/ConfigurationGenerationTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ public class TestBuild : NukeBuild
165165
JobConcurrencyCancelInProgress = true,
166166
JobConcurrencyGroup = "custom-job-group",
167167
EnvironmentName = "environment-name",
168-
EnvironmentUrl = "environment-url"
168+
EnvironmentUrl = "environment-url",
169+
SetupDotNetVersions = new [] { "8.0", "9.0", "10.0" }
169170
}
170171
);
171172

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2025 Maintainers of NUKE.
2+
// Distributed under the MIT License.
3+
// https://github.com/nuke-build/nuke/blob/master/LICENSE
4+
5+
using JetBrains.Annotations;
6+
using Nuke.Common.Utilities;
7+
8+
namespace Nuke.Common.CI.GitHubActions.Configuration;
9+
10+
// https://github.com/actions/setup-dotnet
11+
[PublicAPI]
12+
public class GitHubActionsSetupDotNetStep : GitHubActionsStep
13+
{
14+
public string[] Versions { get; set; }
15+
16+
public override void Write(CustomFileWriter writer)
17+
{
18+
writer.WriteLine("- uses: actions/setup-dotnet@v5");
19+
20+
using (writer.Indent())
21+
{
22+
writer.WriteLine("with:");
23+
using (writer.Indent())
24+
{
25+
writer.WriteLine("dotnet-version: |");
26+
using (writer.Indent())
27+
{
28+
foreach (var version in Versions)
29+
{
30+
writer.WriteLine(version);
31+
}
32+
}
33+
}
34+
}
35+
}
36+
}

source/Nuke.Common/CI/GitHubActions/GitHubActionsAttribute.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ public GitHubActionsAttribute(
8686
public string JobConcurrencyGroup { get; set; }
8787
public bool JobConcurrencyCancelInProgress { get; set; }
8888

89+
public string[] SetupDotNetVersions { get; set; } = new string[0];
90+
8991
public string[] InvokedTargets { get; set; } = new string[0];
9092

9193
public GitHubActionsSubmodules Submodules
@@ -181,6 +183,14 @@ private IEnumerable<GitHubActionsStep> GetSteps(GitHubActionsImage image, IReadO
181183
};
182184
}
183185

186+
if (SetupDotNetVersions.Any())
187+
{
188+
yield return new GitHubActionsSetupDotNetStep
189+
{
190+
Versions = SetupDotNetVersions,
191+
};
192+
}
193+
184194
yield return new GitHubActionsRunStep
185195
{
186196
BuildCmdPath = BuildCmdPath,

0 commit comments

Comments
 (0)