Upgrade to NUKE 9.0.4 and fix automatic workflow generation

This commit is contained in:
Marko Lahma 2025-01-26 19:29:19 +02:00
parent adea7fa666
commit 6945eb191a
4 changed files with 92 additions and 30 deletions

View file

@ -5,7 +5,7 @@
#
# - To turn off auto-generation set:
#
# [GitHubActions (AutoGenerate = false)]
# [CustomGitHubActions (AutoGenerate = false)]
#
# - To trigger manual generation invoke:
#
@ -32,9 +32,10 @@ jobs:
name: ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.x
dotnet-version: |
9.x
- uses: actions/checkout@v4
- name: 'Run: Compile, Test, Pack'
run: ./build.cmd Compile Test Pack

View file

@ -1,28 +1,5 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"properties": {
"AnalyseCode": {
"type": "boolean"
},
"Configuration": {
"type": "string",
"enum": [
"Debug",
"Release"
]
},
"IgnoreFailedSources": {
"type": "boolean",
"description": "Ignore unreachable sources during Restore"
},
"Solution": {
"type": "string",
"description": "Path to a solution file that is automatically loaded"
},
"Version": {
"type": "string"
}
},
"definitions": {
"Host": {
"type": "string",
@ -122,5 +99,34 @@
}
}
},
"$ref": "#/definitions/NukeBuild"
"allOf": [
{
"properties": {
"AnalyseCode": {
"type": "boolean"
},
"Configuration": {
"type": "string",
"enum": [
"Debug",
"Release"
]
},
"IgnoreFailedSources": {
"type": "boolean",
"description": "Ignore unreachable sources during Restore"
},
"Solution": {
"type": "string",
"description": "Path to a solution file that is automatically loaded"
},
"Version": {
"type": "string"
}
}
},
{
"$ref": "#/definitions/NukeBuild"
}
]
}

View file

@ -1,7 +1,11 @@
using System.Collections.Generic;
using Nuke.Common.CI.GitHubActions;
using Nuke.Common.CI.GitHubActions.Configuration;
using Nuke.Common.Execution;
using Nuke.Common.Utilities;
using Nuke.Components;
[GitHubActions(
[CustomGitHubActions(
"pr",
GitHubActionsImage.UbuntuLatest,
OnPullRequestBranches = ["main"],
@ -12,4 +16,55 @@ using Nuke.Components;
ConcurrencyCancelInProgress = true
)
]
public partial class Build;
public partial class Build;
class CustomGitHubActionsAttribute : GitHubActionsAttribute
{
public CustomGitHubActionsAttribute(string name, GitHubActionsImage image, params GitHubActionsImage[] images) : base(name, image, images)
{
}
protected override GitHubActionsJob GetJobs(GitHubActionsImage image, IReadOnlyCollection<ExecutableTarget> relevantTargets)
{
var job = base.GetJobs(image, relevantTargets);
var newSteps = new List<GitHubActionsStep>(job.Steps);
// only need to list the ones that are missing from default image
newSteps.Insert(0, new GitHubActionsSetupDotNetStep(["9.x"]));
job.Steps = newSteps.ToArray();
return job;
}
}
class GitHubActionsSetupDotNetStep : GitHubActionsStep
{
public GitHubActionsSetupDotNetStep(string[] versions)
{
Versions = versions;
}
string[] Versions { get; }
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);
}
}
}
}
}
}

View file

@ -19,7 +19,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Nuke.Components" Version="9.0.3" />
<PackageReference Include="Nuke.Components" Version="9.0.4" />
</ItemGroup>
<!--Overridden for vulnerability reasons with dependencies referencing older versions.-->