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 GitHub actions/setup-dotnet support #1505

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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 @@ -74,6 +74,11 @@ jobs:
.nuke/temp
~/.nuget/packages
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj', '**/Directory.Packages.props') }}
- uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0
9.0
- name: 'Run: Test'
run: ./build.cmd Test
env:
Expand Down Expand Up @@ -122,6 +127,11 @@ jobs:
.nuke/temp
~/.nuget/packages
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj', '**/Directory.Packages.props') }}
- uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0
9.0
- name: 'Run: Test'
run: ./build.cmd Test
env:
Expand Down Expand Up @@ -170,6 +180,11 @@ jobs:
.nuke/temp
~/.nuget/packages
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj', '**/Directory.Packages.props') }}
- uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0
9.0
- name: 'Run: Test'
run: ./build.cmd Test
env:
Expand Down
3 changes: 2 additions & 1 deletion source/Nuke.Common.Tests/CI/ConfigurationGenerationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ public class TestBuild : NukeBuild
JobConcurrencyCancelInProgress = true,
JobConcurrencyGroup = "custom-job-group",
EnvironmentName = "environment-name",
EnvironmentUrl = "environment-url"
EnvironmentUrl = "environment-url",
SetupDotNetVersions = new [] { "8.0", "9.0" }
}
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2025 Maintainers of NUKE.
// Distributed under the MIT License.
// https://github.com/nuke-build/nuke/blob/master/LICENSE

using JetBrains.Annotations;
using Nuke.Common.Utilities;

namespace Nuke.Common.CI.GitHubActions.Configuration;

// https://github.com/actions/setup-dotnet
[PublicAPI]
public class GitHubActionsSetupDotNetStep : GitHubActionsStep
{
public string[] Versions { get; set; }

public override void Write(CustomFileWriter writer)
{
writer.WriteLine("- uses: actions/setup-dotnet@v4");

using (writer.Indent())
{
writer.WriteLine("with:");
using (writer.Indent())
{
writer.WriteLine("dotnet-version: |");
using (writer.Indent())
{
foreach (var version in Versions)
{
writer.WriteLine(version);
}
}
}
}
}
}
10 changes: 10 additions & 0 deletions source/Nuke.Common/CI/GitHubActions/GitHubActionsAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public GitHubActionsAttribute(
public string JobConcurrencyGroup { get; set; }
public bool JobConcurrencyCancelInProgress { get; set; }

public string[] SetupDotNetVersions { get; set; } = new string[0];

public string[] InvokedTargets { get; set; } = new string[0];

public GitHubActionsSubmodules Submodules
Expand Down Expand Up @@ -181,6 +183,14 @@ private IEnumerable<GitHubActionsStep> GetSteps(GitHubActionsImage image, IReadO
};
}

if (SetupDotNetVersions.Any())
{
yield return new GitHubActionsSetupDotNetStep
{
Versions = SetupDotNetVersions,
};
}

yield return new GitHubActionsRunStep
{
BuildCmdPath = BuildCmdPath,
Expand Down
Loading