diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index bb879d54b..d99b63e7f 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -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 diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json index 64c8bccf1..839100960 100644 --- a/.nuke/build.schema.json +++ b/.nuke/build.schema.json @@ -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" + } + ] } diff --git a/build/Build.CI.GitHubActions.cs b/build/Build.CI.GitHubActions.cs index 7b3097658..1d2847d54 100644 --- a/build/Build.CI.GitHubActions.cs +++ b/build/Build.CI.GitHubActions.cs @@ -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; \ No newline at end of file +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 relevantTargets) + { + var job = base.GetJobs(image, relevantTargets); + + var newSteps = new List(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); + } + } + } + } + } +} \ No newline at end of file diff --git a/build/_build.csproj b/build/_build.csproj index 66629bd30..acca9bc0d 100644 --- a/build/_build.csproj +++ b/build/_build.csproj @@ -19,7 +19,7 @@ - +