|
| 1 | +using System; |
| 2 | +using System.Linq; |
| 3 | +using Nuke.Common; |
| 4 | +using Nuke.Common.CI; |
| 5 | +using Nuke.Common.Execution; |
| 6 | +using Nuke.Common.IO; |
| 7 | +using Nuke.Common.ProjectModel; |
| 8 | +using Nuke.Common.Tooling; |
| 9 | +using Nuke.Common.Tools.DotNet; |
| 10 | +using Nuke.Common.Utilities.Collections; |
| 11 | +using Serilog; |
| 12 | +using static Nuke.Common.EnvironmentInfo; |
| 13 | +using static Nuke.Common.IO.FileSystemTasks; |
| 14 | +using static Nuke.Common.IO.PathConstruction; |
| 15 | + |
| 16 | +class Build : NukeBuild |
| 17 | +{ |
| 18 | + /// Support plugins are available for: |
| 19 | + /// - JetBrains ReSharper https://nuke.build/resharper |
| 20 | + /// - JetBrains Rider https://nuke.build/rider |
| 21 | + /// - Microsoft VisualStudio https://nuke.build/visualstudio |
| 22 | + /// - Microsoft VSCode https://nuke.build/vscode |
| 23 | + |
| 24 | + public static int Main () => Execute<Build>(x => x.Compile); |
| 25 | + |
| 26 | + [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] |
| 27 | + readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; |
| 28 | + |
| 29 | + readonly AbsolutePath CliProjectFolder = RootDirectory / "Source" / "MarkdownUtil"; |
| 30 | + readonly AbsolutePath PackagePath = RootDirectory / "Source" / "MarkdownUtil" / "nupkg"; |
| 31 | + |
| 32 | + [Parameter("NuGet Api key for publishing to nuget.org")] [Secret] readonly string NuGetApiKey; |
| 33 | + |
| 34 | + Target Clean => _ => _ |
| 35 | + .Before(Restore) |
| 36 | + .Executes(() => |
| 37 | + { |
| 38 | + DotNetTasks.DotNetClean(_ => _ |
| 39 | + .SetConfiguration(Configuration)); |
| 40 | + }); |
| 41 | + |
| 42 | + Target Info => _ => _ |
| 43 | + .Executes(() => |
| 44 | + { |
| 45 | + Log.Information("Configuration: {Configuration}", Configuration); |
| 46 | + }); |
| 47 | + |
| 48 | + Target Restore => _ => _ |
| 49 | + .DependsOn(Info) |
| 50 | + .Executes(() => |
| 51 | + { |
| 52 | + DotNetTasks.DotNetRestore(); |
| 53 | + }); |
| 54 | + |
| 55 | + Target Compile => _ => _ |
| 56 | + .DependsOn(Restore) |
| 57 | + .Executes(() => |
| 58 | + { |
| 59 | + DotNetTasks.DotNetBuild(_ => _ |
| 60 | + .SetConfiguration(Configuration) |
| 61 | + .EnableNoRestore()); |
| 62 | + }); |
| 63 | + |
| 64 | + // Test are always executed in Release configuration |
| 65 | + Target Test => _ => _ |
| 66 | + .DependsOn(Compile) |
| 67 | + .Executes(() => |
| 68 | + { |
| 69 | + DotNetTasks.DotNetTest(_ => _ |
| 70 | + .When(Configuration == global::Configuration.Release, _ => _ |
| 71 | + .EnableNoRestore() |
| 72 | + .EnableNoBuild()) |
| 73 | + .SetConfiguration(global::Configuration.Release)); |
| 74 | + }); |
| 75 | + |
| 76 | + // We are forcing Release configuration for packaging, because we do not want any debug builds in the wild |
| 77 | + Target Pack => _ => _ |
| 78 | + .DependsOn(Test) |
| 79 | + .Executes(() => |
| 80 | + { |
| 81 | + PackagePath.GlobFiles("*.nupkg").ForEach(DeleteFile); |
| 82 | + DotNetTasks.DotNetPack(_ => _ |
| 83 | + .SetProject(CliProjectFolder) |
| 84 | + .SetOutputDirectory(PackagePath) |
| 85 | + .When(Configuration == global::Configuration.Release, _ => _ |
| 86 | + .EnableNoRestore() |
| 87 | + .EnableNoBuild()) |
| 88 | + .SetConfiguration(Configuration.Release)); |
| 89 | + }); |
| 90 | + |
| 91 | + Target Deploy => _ => _ |
| 92 | + .DependsOn(Pack) |
| 93 | + .Requires(() => NuGetApiKey) |
| 94 | + .Executes(() => |
| 95 | + { |
| 96 | + DotNetTasks.DotNetNuGetPush(_ => _ |
| 97 | + .SetTargetPath(PackagePath / "*.nupkg") |
| 98 | + .SetApiKey(NuGetApiKey) |
| 99 | + .SetSource("https://api.nuget.org/v3/index.json") |
| 100 | + .EnableSkipDuplicate() |
| 101 | + ); |
| 102 | + }); |
| 103 | +} |
0 commit comments