Created
September 21, 2022 08:45
-
-
Save Structed/86be378554005a7c9389718d46d086bc to your computer and use it in GitHub Desktop.
Example Nuke Build.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.IO; | |
using Nuke.Common; | |
using Nuke.Common.CI.GitHubActions; | |
using Nuke.Common.IO; | |
using Nuke.Common.ProjectModel; | |
using Nuke.Common.Tools.DotNet; | |
using Nuke.Common.Utilities.Collections; | |
using static Nuke.Common.Tools.DotNet.DotNetTasks; | |
using static Nuke.Common.IO.FileSystemTasks; | |
[GitHubActions( | |
"continuous", | |
GitHubActionsImage.UbuntuLatest, | |
On = new[] { GitHubActionsTrigger.Push }, | |
InvokedTargets = new[] { nameof(Push) }, | |
EnableGitHubToken = true)] | |
class Build : NukeBuild | |
{ | |
/// Support plugins are available for: | |
/// - JetBrains ReSharper https://nuke.build/resharper | |
/// - JetBrains Rider https://nuke.build/rider | |
/// - Microsoft VisualStudio https://nuke.build/visualstudio | |
/// - Microsoft VSCode https://nuke.build/vscode | |
public static int Main () => Execute<Build>(x => x.Pack); | |
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] | |
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; | |
[Solution(GenerateProjects = true)] | |
readonly Solution Solution; | |
AbsolutePath OutputDirectory => RootDirectory / "export"; | |
GitHubActions GitHubActions => GitHubActions.Instance; | |
Target Clean => _ => _ | |
.Before(Restore) | |
.Executes(() => | |
{ | |
EnsureCleanDirectory(OutputDirectory); | |
}); | |
Target Restore => _ => _ | |
.DependsOn(Clean) | |
.Executes(() => | |
{ | |
DotNetRestore(_ => _ | |
.SetProjectFile(Solution)); | |
}); | |
Target Compile => _ => _ | |
.DependsOn(Restore) | |
.Executes(() => | |
{ | |
DotNetBuild(_ => _ | |
.EnableNoRestore() | |
.SetConfiguration(Configuration) | |
.SetProjectFile(Solution)); | |
}); | |
Target Pack => _ => _ | |
.DependsOn(Compile) | |
.Produces(OutputDirectory / "*.nupkg") | |
.Executes(() => | |
{ | |
DotNetPack(_ => _ | |
.EnableNoRestore() | |
.SetConfiguration(Configuration) | |
.SetProject(Solution) | |
.SetOutputDirectory(OutputDirectory)); | |
}); | |
Target Push => _ => _ | |
.DependsOn(Pack) | |
.Executes(() => | |
{ | |
Directory.GetFiles(OutputDirectory).ForEach(path => | |
{ | |
DotNetNuGetPush(_ => _ | |
.SetSource("https://nuget.pkg.github.com/structed/index.json") | |
.SetApiKey(GitHubActions.Token) | |
.SetTargetPath(OutputDirectory) | |
.SetTargetPath(path) | |
.EnableSkipDuplicate()); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment