|
| 1 | +using Bullseye; |
| 2 | +using static Bullseye.Targets; |
| 3 | +using static SimpleExec.Command; |
| 4 | + |
| 5 | +const string solution = "source/Slackbot.Net.sln"; |
| 6 | +const string releasesDir = "releases"; |
| 7 | + |
| 8 | +const string Restore = "restore"; |
| 9 | +const string Build = "build"; |
| 10 | +const string Test = "test"; |
| 11 | +const string Pack = "pack"; |
| 12 | +const string Publish = "publish"; |
| 13 | + |
| 14 | +Target(Restore, () => RunAsync("dotnet", $"restore {solution}")); |
| 15 | + |
| 16 | +Target(Build, new[] { Restore }, () => RunAsync("dotnet", $"build {solution} --no-restore")); |
| 17 | + |
| 18 | +Target(Test, new[] { Build }, () => RunAsync("dotnet", $"test {solution} --no-build")); |
| 19 | + |
| 20 | +Target(Pack, new[] { Build }, async () => |
| 21 | +{ |
| 22 | + var version = Environment.GetEnvironmentVariable("BUILD_VERSION"); |
| 23 | + var informationalVersion = Environment.GetEnvironmentVariable("BUILD_INFORMATIONAL_VERSION"); |
| 24 | + var releaseNotes = Environment.GetEnvironmentVariable("BUILD_RELEASE_NOTES"); |
| 25 | + |
| 26 | + var properties = ""; |
| 27 | + if (!string.IsNullOrWhiteSpace(version)) |
| 28 | + properties += $" /p:Version={version}"; |
| 29 | + if (!string.IsNullOrWhiteSpace(informationalVersion)) |
| 30 | + properties += $" /p:InformationalVersion={informationalVersion}"; |
| 31 | + if (!string.IsNullOrWhiteSpace(releaseNotes)) |
| 32 | + properties += $" /p:PackageReleaseNotes=\"{releaseNotes}\""; |
| 33 | + |
| 34 | + await RunAsync("dotnet", $"pack {solution} -c Release -o {releasesDir}{properties}"); |
| 35 | +}); |
| 36 | + |
| 37 | +Target(Publish, new[] { Pack }, async () => |
| 38 | +{ |
| 39 | + var apiKey = Environment.GetEnvironmentVariable("NUGET_API_KEY") |
| 40 | + ?? throw new InvalidOperationException("NUGET_API_KEY environment variable is required for publish"); |
| 41 | + |
| 42 | + foreach (var package in Directory.GetFiles(releasesDir, "*.nupkg", SearchOption.AllDirectories)) |
| 43 | + await RunAsync("dotnet", $"nuget push \"{package}\" -k {apiKey} -s https://api.nuget.org/v3/index.json --skip-duplicate"); |
| 44 | +}); |
| 45 | + |
| 46 | +Target("default", new[] { Test }); |
| 47 | + |
| 48 | +await RunTargetsAndExitAsync(args); |
0 commit comments