|
| 1 | +#addin "nuget:?package=Cake.MinVer&version=1.0.1" |
| 2 | +#addin "nuget:?package=Cake.Args&version=1.0.1" |
| 3 | + |
| 4 | +var target = ArgumentOrDefault<string>("target") ?? "pack"; |
| 5 | +var buildVersion = MinVer(s => s.WithTagPrefix("v").WithDefaultPreReleasePhase("preview")); |
| 6 | + |
| 7 | +Task("clean") |
| 8 | + .Does(() => |
| 9 | +{ |
| 10 | + CleanDirectories("./artifacts/**"); |
| 11 | + CleanDirectories("./**/^{bin,obj}"); |
| 12 | +}); |
| 13 | + |
| 14 | +Task("restore") |
| 15 | + .IsDependentOn("clean") |
| 16 | + .Does(() => |
| 17 | +{ |
| 18 | + DotNetCoreRestore("./serilog-enrichers-globallogcontext.sln", new DotNetCoreRestoreSettings |
| 19 | + { |
| 20 | + LockedMode = true, |
| 21 | + }); |
| 22 | +}); |
| 23 | + |
| 24 | +Task("build") |
| 25 | + .IsDependentOn("restore") |
| 26 | + .DoesForEach(new[] { "Debug", "Release" }, (configuration) => |
| 27 | +{ |
| 28 | + DotNetCoreBuild("./serilog-enrichers-globallogcontext.sln", new DotNetCoreBuildSettings |
| 29 | + { |
| 30 | + Configuration = configuration, |
| 31 | + NoRestore = true, |
| 32 | + NoIncremental = false, |
| 33 | + MSBuildSettings = new DotNetCoreMSBuildSettings() |
| 34 | + .WithProperty("Version", buildVersion.Version) |
| 35 | + .WithProperty("AssemblyVersion", buildVersion.AssemblyVersion) |
| 36 | + .WithProperty("FileVersion", buildVersion.FileVersion) |
| 37 | + .WithProperty("ContinuousIntegrationBuild", BuildSystem.IsLocalBuild ? "false" : "true") |
| 38 | + }); |
| 39 | +}); |
| 40 | + |
| 41 | +Task("test") |
| 42 | + .IsDependentOn("build") |
| 43 | + .Does(() => |
| 44 | +{ |
| 45 | + var settings = new DotNetCoreTestSettings |
| 46 | + { |
| 47 | + Configuration = "Release", |
| 48 | + NoRestore = true, |
| 49 | + NoBuild = true, |
| 50 | + }; |
| 51 | + |
| 52 | + var projectFiles = GetFiles("./test/**/*.csproj"); |
| 53 | + foreach (var file in projectFiles) |
| 54 | + { |
| 55 | + DotNetCoreTest(file.FullPath, settings); |
| 56 | + } |
| 57 | +}); |
| 58 | + |
| 59 | +Task("pack") |
| 60 | + .IsDependentOn("test") |
| 61 | + .Does(() => |
| 62 | +{ |
| 63 | + var releaseNotes = $"https://github.com/augustoproiete/serilog-enrichers-globallogcontext/releases/tag/v{buildVersion.Version}"; |
| 64 | + |
| 65 | + DotNetCorePack("./src/Serilog.Enrichers.GlobalLogContext/Serilog.Enrichers.GlobalLogContext.csproj", new DotNetCorePackSettings |
| 66 | + { |
| 67 | + Configuration = "Release", |
| 68 | + NoRestore = true, |
| 69 | + NoBuild = true, |
| 70 | + OutputDirectory = "./artifacts/nuget", |
| 71 | + MSBuildSettings = new DotNetCoreMSBuildSettings() |
| 72 | + .WithProperty("Version", buildVersion.Version) |
| 73 | + .WithProperty("PackageReleaseNotes", releaseNotes) |
| 74 | + }); |
| 75 | +}); |
| 76 | + |
| 77 | +Task("push") |
| 78 | + .IsDependentOn("pack") |
| 79 | + .Does(context => |
| 80 | +{ |
| 81 | + var url = context.EnvironmentVariable("NUGET_URL"); |
| 82 | + if (string.IsNullOrWhiteSpace(url)) |
| 83 | + { |
| 84 | + context.Information("No NuGet URL specified. Skipping publishing of NuGet packages"); |
| 85 | + return; |
| 86 | + } |
| 87 | + |
| 88 | + var apiKey = context.EnvironmentVariable("NUGET_API_KEY"); |
| 89 | + if (string.IsNullOrWhiteSpace(apiKey)) |
| 90 | + { |
| 91 | + context.Information("No NuGet API key specified. Skipping publishing of NuGet packages"); |
| 92 | + return; |
| 93 | + } |
| 94 | + |
| 95 | + var nugetPushSettings = new DotNetCoreNuGetPushSettings |
| 96 | + { |
| 97 | + Source = url, |
| 98 | + ApiKey = apiKey, |
| 99 | + }; |
| 100 | + |
| 101 | + foreach (var nugetPackageFile in GetFiles("./artifacts/nuget/*.nupkg")) |
| 102 | + { |
| 103 | + DotNetCoreNuGetPush(nugetPackageFile.FullPath, nugetPushSettings); |
| 104 | + } |
| 105 | +}); |
| 106 | + |
| 107 | +RunTarget(target); |
0 commit comments