|
| 1 | +#addin "Cake.Json" |
1 | 2 |
|
2 |
| -Task("Publish-MyGet") |
3 |
| - .IsDependentOn("Package") |
4 |
| - .WithCriteria(() => !BuildSystem.IsLocalBuild) |
5 |
| - .WithCriteria(() => !IsPullRequest) |
6 |
| - .WithCriteria(() => IsMainGitVersionRepo) |
7 |
| - .Does(() => |
| 3 | +using System.Net; |
| 4 | +using System.Linq; |
| 5 | +using System.Collections.Generic; |
| 6 | + |
| 7 | +string Get(string url) |
8 | 8 | {
|
| 9 | + var assetsRequest = WebRequest.CreateHttp(url); |
| 10 | + assetsRequest.Method = "GET"; |
| 11 | + assetsRequest.Accept = "application/vnd.github.v3+json"; |
| 12 | + assetsRequest.UserAgent = "BuildScript"; |
| 13 | + |
| 14 | + using (var assetsResponse = assetsRequest.GetResponse()) |
| 15 | + { |
| 16 | + var assetsStream = assetsResponse.GetResponseStream(); |
| 17 | + var assetsReader = new StreamReader(assetsStream); |
| 18 | + var assetsBody = assetsReader.ReadToEnd(); |
| 19 | + return assetsBody; |
| 20 | + } |
| 21 | +} |
9 | 22 |
|
| 23 | +Task("EnsureRequirements") |
| 24 | + .Does(() => |
| 25 | + { |
| 26 | + if (!AppVeyor.IsRunningOnAppVeyor) |
| 27 | + throw new Exception("Deployment should happen via appveyor"); |
| 28 | + |
| 29 | + var isTag = |
| 30 | + AppVeyor.Environment.Repository.Tag.IsTag && |
| 31 | + !string.IsNullOrWhiteSpace(AppVeyor.Environment.Repository.Tag.Name); |
| 32 | + if (!isTag) |
| 33 | + throw new Exception("Deployment should happen from a published GitHub release"); |
| 34 | + }); |
| 35 | + |
| 36 | +var tag = ""; |
| 37 | +Dictionary<string, string> artifactLookup = null; |
| 38 | +Task("UpdateVersionInfo") |
| 39 | + .IsDependentOn("EnsureRequirements") |
| 40 | + .Does(() => |
| 41 | + { |
| 42 | + tag = AppVeyor.Environment.Repository.Tag.Name; |
| 43 | + AppVeyor.UpdateBuildVersion(tag); |
| 44 | + }); |
| 45 | + |
| 46 | +Task("DownloadGitHubReleaseArtifacts") |
| 47 | + .IsDependentOn("UpdateVersionInfo") |
| 48 | + .Does(() => |
| 49 | + { |
| 50 | + var assets_url = ParseJson(Get("https://api.github.com/repos/shouldly/shouldly/releases/tags/" + tag)) |
| 51 | + .GetValue("assets_url").Value<string>(); |
| 52 | + EnsureDirectoryExists("./releaseArtifacts"); |
| 53 | + foreach(var asset in DeserializeJson<JArray>(Get(assets_url))) |
| 54 | + { |
| 55 | + DownloadFile(asset.Value<string>("browser_download_url"), "./releaseArtifacts/" + asset.Value<string>("name")); |
| 56 | + } |
| 57 | + |
| 58 | + // Turns .artifacts file into a lookup |
| 59 | + artifactLookup = System.IO.File |
| 60 | + .ReadAllLines("./releaseArtifacts/artifacts") |
| 61 | + .Select(l => l.Split(':')) |
| 62 | + .ToDictionary(v => v[0], v => v[1]); |
| 63 | + }); |
| 64 | + |
| 65 | +Task("Publish-NuGetPackage") |
| 66 | + .IsDependentOn("DownloadGitHubReleaseArtifacts") |
| 67 | + .Does(() => |
| 68 | +{ |
| 69 | + NuGetPush( |
| 70 | + "./releaseArtifacts/" + artifactLookup["NuGetExeBuild"], |
| 71 | + new NuGetPushSettings { |
| 72 | + ApiKey = EnvironmentVariable("NuGetApiKey"), |
| 73 | + Source = "https://www.nuget.org/api/v2/package" |
| 74 | + }); |
10 | 75 | })
|
11 | 76 | .OnError(exception =>
|
12 | 77 | {
|
13 |
| - Information("Publish-MyGet Task failed, but continuing with next Task..."); |
| 78 | + Information("Publish-NuGet Task failed, but continuing with next Task..."); |
14 | 79 | publishingError = true;
|
15 | 80 | });
|
16 | 81 |
|
17 |
| -Task("Publish-NuGet") |
18 |
| - .IsDependentOn("Package") |
19 |
| - .WithCriteria(() => !BuildSystem.IsLocalBuild) |
20 |
| - .WithCriteria(() => !IsPullRequest) |
21 |
| - .WithCriteria(() => IsMainGitVersionRepo) |
22 |
| - .WithCriteria(() => IsTagged) |
| 82 | +Task("Publish-NuGetCommandLine") |
| 83 | + .IsDependentOn("DownloadGitHubReleaseArtifacts") |
23 | 84 | .Does(() =>
|
24 | 85 | {
|
25 |
| - |
| 86 | + NuGetPush( |
| 87 | + "./releaseArtifacts/" + artifactLookup["NuGetCommandLineBuild"], |
| 88 | + new NuGetPushSettings { |
| 89 | + ApiKey = EnvironmentVariable("NuGetApiKey"), |
| 90 | + Source = "https://www.nuget.org/api/v2/package" |
| 91 | + }); |
26 | 92 | })
|
27 | 93 | .OnError(exception =>
|
28 | 94 | {
|
29 | 95 | Information("Publish-NuGet Task failed, but continuing with next Task...");
|
30 | 96 | publishingError = true;
|
31 | 97 | });
|
32 | 98 |
|
33 |
| -Task("Publish-Chocolatey") |
34 |
| - .IsDependentOn("Package") |
35 |
| - .WithCriteria(() => !BuildSystem.IsLocalBuild) |
36 |
| - .WithCriteria(() => !IsPullRequest) |
37 |
| - .WithCriteria(() => IsMainGitVersionRepo) |
38 |
| - .WithCriteria(() => IsTagged) |
| 99 | + |
| 100 | +Task("Publish-MsBuildTask") |
| 101 | + .IsDependentOn("DownloadGitHubReleaseArtifacts") |
39 | 102 | .Does(() =>
|
40 | 103 | {
|
41 |
| - |
| 104 | + NuGetPush( |
| 105 | + "./releaseArtifacts/" + artifactLookup["NuGetTaskBuild"], |
| 106 | + new NuGetPushSettings { |
| 107 | + ApiKey = EnvironmentVariable("NuGetApiKey"), |
| 108 | + Source = "https://www.nuget.org/api/v2/package" |
| 109 | + }); |
42 | 110 | })
|
43 | 111 | .OnError(exception =>
|
44 | 112 | {
|
45 |
| - Information("Publish-Chocolatey Task failed, but continuing with next Task..."); |
| 113 | + Information("Publish-NuGet Task failed, but continuing with next Task..."); |
46 | 114 | publishingError = true;
|
47 | 115 | });
|
48 | 116 |
|
49 |
| -Task("Publish-Gem") |
50 |
| - .IsDependentOn("Package") |
51 |
| - .WithCriteria(() => !BuildSystem.IsLocalBuild) |
52 |
| - .WithCriteria(() => !IsPullRequest) |
53 |
| - .WithCriteria(() => IsMainGitVersionRepo) |
54 |
| - .WithCriteria(() => IsTagged) |
| 117 | +Task("Publish-Chocolatey") |
| 118 | + .IsDependentOn("DownloadGitHubReleaseArtifacts") |
55 | 119 | .Does(() =>
|
56 | 120 | {
|
57 |
| - |
| 121 | + NuGetPush( |
| 122 | + "./releaseArtifacts/" + artifactLookup["NuGetExeBuild"], |
| 123 | + new NuGetPushSettings { |
| 124 | + ApiKey = EnvironmentVariable("ChocolateyApiKey"), |
| 125 | + Source = "https://chocolatey.org/api/v2/package" |
| 126 | + }); |
58 | 127 | })
|
59 | 128 | .OnError(exception =>
|
60 | 129 | {
|
61 |
| - Information("Publish-Gem Task failed, but continuing with next Task..."); |
| 130 | + Information("Publish-Chocolatey Task failed, but continuing with next Task..."); |
62 | 131 | publishingError = true;
|
63 | 132 | });
|
64 | 133 |
|
65 |
| -Task("Publish-GitHub-Release") |
66 |
| - .IsDependentOn("Package") |
67 |
| - .WithCriteria(() => !BuildSystem.IsLocalBuild) |
68 |
| - .WithCriteria(() => !IsPullRequest) |
69 |
| - .WithCriteria(() => IsMainGitVersionRepo) |
70 |
| - .WithCriteria(() => IsTagged) |
| 134 | +Task("Publish-Gem") |
| 135 | + .IsDependentOn("DownloadGitHubReleaseArtifacts") |
71 | 136 | .Does(() =>
|
72 | 137 | {
|
| 138 | + var returnCode = StartProcess("gem", new ProcessSettings |
| 139 | + { |
| 140 | + Arguments = "push ./releaseArtifacts/" + artifactLookup["NuGetExeBuild"] + " --key " + EnvironmentVariable("GemApiKey") |
| 141 | + }); |
73 | 142 |
|
74 |
| -}) |
75 |
| -.OnError(exception => |
| 143 | + if (returnCode != 0) { |
| 144 | + Information("Publish-Gem Task failed, but continuing with next Task..."); |
| 145 | + publishingError = true; |
| 146 | + } |
| 147 | +}); |
| 148 | + |
| 149 | + |
| 150 | +Task("Publish-VstsTask") |
| 151 | + .IsDependentOn("DownloadGitHubReleaseArtifacts") |
| 152 | + .Does(() => |
76 | 153 | {
|
77 |
| - Information("Publish-GitHub-Release Task failed, but continuing with next Task..."); |
78 |
| - publishingError = true; |
| 154 | + var returnCode = StartProcess("tfx", new ProcessSettings |
| 155 | + { |
| 156 | + Arguments = "extension publish --vsix ./releaseArtifacts/" + artifactLookup["GitVersionTfsTaskBuild"] + " --no-prompt --auth-type pat --token " + EnvironmentVariable("GemApiKey") |
| 157 | + }); |
| 158 | + |
| 159 | + if (returnCode != 0) { |
| 160 | + Information("Publish-VstsTask Task failed, but continuing with next Task..."); |
| 161 | + publishingError = true; |
| 162 | + } |
79 | 163 | });
|
80 | 164 |
|
81 | 165 | Task("Deploy")
|
82 |
| - .IsDependentOn("Publish-MyGet") |
83 |
| - .IsDependentOn("Publish-NuGet") |
| 166 | + .IsDependentOn("Publish-NuGetPackage") |
| 167 | + .IsDependentOn("Publish-NuGetCommandLine") |
| 168 | + .IsDependentOn("Publish-MsBuildTask") |
84 | 169 | .IsDependentOn("Publish-Chocolatey")
|
85 | 170 | .IsDependentOn("Publish-Gem")
|
86 |
| - .IsDependentOn("Publish-GitHub-Release") |
| 171 | + .IsDependentOn("Publish-VstsTask") |
87 | 172 | .Finally(() =>
|
88 | 173 | {
|
89 | 174 | if(publishingError)
|
|
0 commit comments