-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.cake
158 lines (135 loc) · 6 KB
/
build.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#tool "nuget:?package=GitVersion.CommandLine"
#addin nuget:?package=Cake.DoInDirectory
#addin Cake.Powershell
#addin "Cake.Npm"
#tool "nuget:?package=GitVersion.CommandLine"
#addin "nuget:?package=MagicChunks"
#tool "nuget:?package=gitreleasemanager"
#addin "Cake.Figlet"
#addin Cake.Twitter
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var isLocalBuild = Argument("isLocalBuild", false);
string semVersion = null;
Task("CalculateVersionNumber")
.Does(() => {
GitVersion assertedVersions = GitVersion(new GitVersionSettings { OutputType = GitVersionOutput.Json });
semVersion = assertedVersions.LegacySemVerPadded;
Information("Calculated Semantic Version: {0}", semVersion);
});
Task("UpdateSettingsJsonVersion")
.IsDependentOn("CalculateVersionNumber")
.WithCriteria(() => !isLocalBuild)
.Does(() => {
DoInDirectory(@"src/main", () => {
Information("Updating settings.json version to {0}", semVersion);
TransformConfig("settings.json", "settings.json", new TransformationCollection {
{ "version", semVersion }
});
});
});
Task("UpdateProjectJsonVersion")
.IsDependentOn("CalculateVersionNumber")
.WithCriteria(() => !isLocalBuild)
.Does(() => {
Information("Updating package.json version to {0}", semVersion);
TransformConfig("package.json", "package.json", new TransformationCollection {
{ "version", semVersion }
});
});
Task("NpmInstall")
.Does(() => {
NpmInstall();
});
Task("ElectronBuild")
.IsDependentOn("NpmInstall")
.IsDependentOn("UpdateProjectJsonVersion")
.IsDependentOn("UpdateSettingsJsonVersion")
.Does(() => {
NpmRunScript("build");
});
Task("ChocolateyUpdateVersionNumbers")
.IsDependentOn("CalculateVersionNumber")
.Does(() => {
DoInDirectory(@"chocolatey", () => {
TransformConfig("tomatoad.nuspec", "tomatoad.nuspec", new TransformationCollection {
{ "package/metadata/version", semVersion }
});
// Update chocolateyinstall.ps1
var content = $"Install-ChocolateyPackage 'Tomatoad' 'exe' '/S' 'https://github.com/dracan/tomatoad/releases/download/{semVersion}/Tomatoad.Setup.{semVersion}.exe'";
System.IO.File.WriteAllText("tools/chocolateyinstall.ps1", content);
});
});
Task("ChocolateyPack")
.IsDependentOn("ElectronBuild")
.IsDependentOn("ChocolateyUpdateVersionNumbers")
.Does(() => {
DoInDirectory(@"chocolatey", () => {
ChocolateyPack("tomatoad.nuspec", new ChocolateyPackSettings());
});
});
Task("ChocolateyPush")
.IsDependentOn("ChocolateyPack")
.IsDependentOn("GitHubRelease")
.Does(() => {
DoInDirectory(@"chocolatey", () => {
var apiKey = EnvironmentVariable("TomatoadChocolateyApiKey");
if(apiKey == null) {
throw new NullReferenceException("TomatoadChocolateyApiKey environment variable must be set!");
}
ChocolateyPush($"tomatoad.{semVersion}.nupkg", new ChocolateyPushSettings {
ApiKey = apiKey,
});
});
});
Task("UpdateGit")
.IsDependentOn("UpdateProjectJsonVersion")
.IsDependentOn("ChocolateyUpdateVersionNumbers")
.Does(() => {
// Using StartProcess instead of Cake.Git because its GitCommit requires an explicit name and email.
// As this isn't yet going through a build server - I don't this hardcoded.
StartProcess("git", new ProcessSettings { Arguments = "add -A ." });
StartProcess("git", new ProcessSettings { Arguments = $"commit -m \"Updated version info to {semVersion}\"" });
StartProcess("git", new ProcessSettings { Arguments = $"tag {semVersion}" });
StartProcess("git", new ProcessSettings { Arguments = "push" });
StartProcess("git", new ProcessSettings { Arguments = "push --tags" });
});
Task("GitHubRelease")
.IsDependentOn("CalculateVersionNumber")
.IsDependentOn("ElectronBuild")
.IsDependentOn("UpdateGit")
.Does(() => {
var gitHubUsername = EnvironmentVariable("TomatoadGitHubUsername");
var gitHubPassword = EnvironmentVariable("TomatoadGitHubPassword");
GitReleaseManagerCreate(gitHubUsername, gitHubPassword, "dracan", "tomatoad", new GitReleaseManagerCreateSettings {
Milestone = semVersion,
Name = semVersion,
Prerelease = true,
TargetCommitish = "master"
});
var packageFile = File($"dist/Tomatoad Setup {semVersion}.exe");
GitReleaseManagerAddAssets(gitHubUsername, gitHubPassword, "dracan", "tomatoad", semVersion, packageFile);
GitReleaseManagerClose(gitHubUsername, gitHubPassword, "dracan", "tomatoad", semVersion);
GitReleaseManagerPublish(gitHubUsername, gitHubPassword, "dracan", "tomatoad", semVersion);
});
Task("Publish")
.IsDependentOn("ChocolateyPush")
.Does(() => {
});
Task("SendTweet")
.IsDependentOn("CalculateVersionNumber")
.IsDependentOn("Publish")
.Does(() => {
var oAuthConsumerKey = EnvironmentVariable("TomatoadTwitterConsumerKey");
var oAuthConsumerSecret = EnvironmentVariable("TomatoadTwitterConsumerSecret");
var accessToken = EnvironmentVariable("TomatoadTwitterAccessToken");
var accessTokenSecret = EnvironmentVariable("TomatoadTwitterAccessTokenSecret");
var tweetContent = $"Version {semVersion} of Tomatoad has now been released and is available from either the Github release page, or via @chocolateynuget using 'cinst tomatoad' https://github.com/dracan/tomatoad/releases/tag/{semVersion} #PomodoroTechnique";
TwitterSendTweet(oAuthConsumerKey, oAuthConsumerSecret, accessToken, accessTokenSecret, tweetContent);
});
Task("Default")
.IsDependentOn("SendTweet")
.Does(() => {
Information(Figlet("Success"));
});
RunTarget(target);