Skip to content

Commit

Permalink
Add GitHub actions/setup-dotnet support
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma committed Jan 16, 2025
1 parent c78563a commit cca064d
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
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

0 comments on commit cca064d

Please sign in to comment.