-
Notifications
You must be signed in to change notification settings - Fork 84
/
deploy.cake
89 lines (74 loc) · 2.55 KB
/
deploy.cake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#addin "Cake.Json"
using System.Net;
using System.Linq;
var target = Argument("target", "Default");
string Get(string url)
{
var assetsRequest = WebRequest.CreateHttp(url);
assetsRequest.Method = "GET";
assetsRequest.Accept = "application/vnd.github.v3+json";
assetsRequest.UserAgent = "BuildScript";
using (var assetsResponse = assetsRequest.GetResponse())
{
var assetsStream = assetsResponse.GetResponseStream();
var assetsReader = new StreamReader(assetsStream);
var assetsBody = assetsReader.ReadToEnd();
return assetsBody;
}
}
Task("EnsureRequirements")
.Does(() =>
{
if (!AppVeyor.IsRunningOnAppVeyor)
throw new Exception("Deployment should happen via appveyor");
var isTag =
AppVeyor.Environment.Repository.Tag.IsTag &&
!string.IsNullOrWhiteSpace(AppVeyor.Environment.Repository.Tag.Name);
if (!isTag)
throw new Exception("Deployment should happen from a published GitHub release");
});
var tag = "";
Task("UpdateVersionInfo")
.IsDependentOn("EnsureRequirements")
.Does(() =>
{
tag = AppVeyor.Environment.Repository.Tag.Name;
AppVeyor.UpdateBuildVersion(tag);
});
Task("DownloadGitHubReleaseArtifacts")
.IsDependentOn("UpdateVersionInfo")
.Does(() =>
{
var assets_url = ParseJson(Get("https://api.github.com/repos/teststack/teststack.bddfy/releases/tags/" + tag))
.GetValue("assets_url").Value<string>();
EnsureDirectoryExists("./releaseArtifacts");
foreach(var asset in DeserializeJson<JArray>(Get(assets_url)))
{
DownloadFile(asset.Value<string>("browser_download_url"), "./releaseArtifacts/" + asset.Value<string>("name"));
}
});
Task("DeployNuget")
.IsDependentOn("DownloadGitHubReleaseArtifacts")
.Does(() =>
{
// Turns .artifacts file into a lookup
var fileLookup = System.IO.File
.ReadAllLines("./releaseArtifacts/artifacts")
.Select(l => l.Split(':'))
.ToDictionary(v => v[0], v => v[1]);
NuGetPush(
"./releaseArtifacts/" + fileLookup["nuget"],
new NuGetPushSettings {
ApiKey = EnvironmentVariable("NuGetApiKey"),
Source = "https://www.nuget.org/api/v2/package"
});
});
Task("Deploy")
.IsDependentOn("DeployNuget");
Task("Default")
.IsDependentOn("Deploy");
Task("Verify")
.Does(() => {
// Nothing, used to make sure the script compiles
});
RunTarget(target);