Skip to content

Commit f1c37e0

Browse files
committed
Setup deploy script
1 parent e27ed30 commit f1c37e0

File tree

4 files changed

+288
-47
lines changed

4 files changed

+288
-47
lines changed

appveyor.deploy.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
install:
2+
npm i -g tfx-cli
3+
4+
assembly_info:
5+
patch: false
6+
7+
build_script:
8+
- ps: .\deploy.ps1
9+
10+
test: off
11+
skip_non_tags: true

build.cake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ bool IsTagged = (BuildSystem.AppVeyor.Environment.Repository.Tag.IsTag &&
1515
bool IsMainGitVersionRepo = StringComparer.OrdinalIgnoreCase.Equals("gittools/gitversion", BuildSystem.AppVeyor.Environment.Repository.Name);
1616
bool IsPullRequest = BuildSystem.AppVeyor.Environment.PullRequest.IsPullRequest;
1717

18-
void Build()
18+
void Build(string configuration)
1919
{
2020
if(IsRunningOnUnix())
2121
{
@@ -49,7 +49,7 @@ Task("DogfoodBuild")
4949
.IsDependentOn("NuGet-Package-Restore")
5050
.Does(() =>
5151
{
52-
Build();
52+
Build(configuration);
5353
});
5454

5555
Task("Version")
@@ -86,7 +86,7 @@ Task("Build")
8686
.IsDependentOn("NuGet-Package-Restore")
8787
.Does(() =>
8888
{
89-
Build();
89+
Build(configuration);
9090
});
9191

9292
Task("Run-NUnit-Tests")
@@ -137,7 +137,7 @@ Task("Upload-AppVeyor-Artifacts")
137137
"NuGetCommandLineBuild:GitVersion.CommandLine." + nugetVersion +".nupkg",
138138
"NuGetRefBuild:GitVersion." + nugetVersion +".nupkg",
139139
"NuGetTaskBuild:GitVersionTask." + nugetVersion +".nupkg",
140-
"NuGetExeBuild:GitVersion.Portable." + nugetVersion +".nupkg",
140+
"GitVersionTfsTaskBuild:gittools.gitversion." + semVersion +".vsix",
141141
"GemBuild:" + gem,
142142
"zip:GitVersion_" + nugetVersion + ".zip",
143143
"releaseNotes:releasenotes.md"

deploy.cake

Lines changed: 128 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,174 @@
1+
#addin "Cake.Json"
12

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)
88
{
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+
}
922

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+
});
1075
})
1176
.OnError(exception =>
1277
{
13-
Information("Publish-MyGet Task failed, but continuing with next Task...");
78+
Information("Publish-NuGet Task failed, but continuing with next Task...");
1479
publishingError = true;
1580
});
1681

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")
2384
.Does(() =>
2485
{
25-
86+
NuGetPush(
87+
"./releaseArtifacts/" + artifactLookup["NuGetCommandLineBuild"],
88+
new NuGetPushSettings {
89+
ApiKey = EnvironmentVariable("NuGetApiKey"),
90+
Source = "https://www.nuget.org/api/v2/package"
91+
});
2692
})
2793
.OnError(exception =>
2894
{
2995
Information("Publish-NuGet Task failed, but continuing with next Task...");
3096
publishingError = true;
3197
});
3298

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")
39102
.Does(() =>
40103
{
41-
104+
NuGetPush(
105+
"./releaseArtifacts/" + artifactLookup["NuGetTaskBuild"],
106+
new NuGetPushSettings {
107+
ApiKey = EnvironmentVariable("NuGetApiKey"),
108+
Source = "https://www.nuget.org/api/v2/package"
109+
});
42110
})
43111
.OnError(exception =>
44112
{
45-
Information("Publish-Chocolatey Task failed, but continuing with next Task...");
113+
Information("Publish-NuGet Task failed, but continuing with next Task...");
46114
publishingError = true;
47115
});
48116

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")
55119
.Does(() =>
56120
{
57-
121+
NuGetPush(
122+
"./releaseArtifacts/" + artifactLookup["NuGetExeBuild"],
123+
new NuGetPushSettings {
124+
ApiKey = EnvironmentVariable("ChocolateyApiKey"),
125+
Source = "https://chocolatey.org/api/v2/package"
126+
});
58127
})
59128
.OnError(exception =>
60129
{
61-
Information("Publish-Gem Task failed, but continuing with next Task...");
130+
Information("Publish-Chocolatey Task failed, but continuing with next Task...");
62131
publishingError = true;
63132
});
64133

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")
71136
.Does(() =>
72137
{
138+
var returnCode = StartProcess("gem", new ProcessSettings
139+
{
140+
Arguments = "push ./releaseArtifacts/" + artifactLookup["NuGetExeBuild"] + " --key " + EnvironmentVariable("GemApiKey")
141+
});
73142

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(() =>
76153
{
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+
}
79163
});
80164

81165
Task("Deploy")
82-
.IsDependentOn("Publish-MyGet")
83-
.IsDependentOn("Publish-NuGet")
166+
.IsDependentOn("Publish-NuGetPackage")
167+
.IsDependentOn("Publish-NuGetCommandLine")
168+
.IsDependentOn("Publish-MsBuildTask")
84169
.IsDependentOn("Publish-Chocolatey")
85170
.IsDependentOn("Publish-Gem")
86-
.IsDependentOn("Publish-GitHub-Release")
171+
.IsDependentOn("Publish-VstsTask")
87172
.Finally(() =>
88173
{
89174
if(publishingError)

0 commit comments

Comments
 (0)