forked from GitTools/GitVersion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
199 lines (176 loc) · 6.92 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#tool "nuget:?package=NUnit.ConsoleRunner"
#tool "nuget:?package=GitReleaseNotes"
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
string version = null;
string nugetVersion = null;
string preReleaseTag = null;
string semVersion = null;
string milestone = null;
bool publishingError = false;
bool IsTagged = (BuildSystem.AppVeyor.Environment.Repository.Tag.IsTag &&
!string.IsNullOrWhiteSpace(BuildSystem.AppVeyor.Environment.Repository.Tag.Name));
bool IsMainGitVersionRepo = StringComparer.OrdinalIgnoreCase.Equals("gittools/gitversion", BuildSystem.AppVeyor.Environment.Repository.Name);
bool IsPullRequest = BuildSystem.AppVeyor.Environment.PullRequest.IsPullRequest;
bool IsMainGitVersionBranch = StringComparer.OrdinalIgnoreCase.Equals("master", BuildSystem.AppVeyor.Environment.Repository.Branch);
void Build(string configuration, string nugetVersion, string semVersion, string version, string preReleaseTag)
{
if(IsRunningOnUnix())
{
XBuild("./src/GitVersion.sln", new XBuildSettings()
.SetConfiguration(configuration)
.WithProperty("POSIX", "True")
.SetVerbosity(Verbosity.Minimal));
}
else
{
var msBuildSettings = new MSBuildSettings()
.SetConfiguration(configuration)
.SetPlatformTarget(PlatformTarget.MSIL)
.WithProperty("Windows", "True")
.UseToolVersion(MSBuildToolVersion.VS2015)
.SetVerbosity(Verbosity.Minimal)
.SetNodeReuse(false);
if (BuildSystem.AppVeyor.IsRunningOnAppVeyor)
{
msBuildSettings = msBuildSettings
.WithProperty("GitVersion_NuGetVersion", nugetVersion)
.WithProperty("GitVersion_SemVer", semVersion)
.WithProperty("GitVersion_MajorMinorPatch", version)
.WithProperty("GitVersion_PreReleaseTag", preReleaseTag);
}
MSBuild("./src/GitVersion.sln", msBuildSettings);
}
}
Task("DogfoodBuild")
.IsDependentOn("NuGet-Package-Restore")
.Does(() =>
{
Build(configuration, nugetVersion, semVersion, version, preReleaseTag);
});
Task("Version")
.IsDependentOn("DogfoodBuild")
.Does(() =>
{
GitVersion(new GitVersionSettings
{
UpdateAssemblyInfo = true,
LogFilePath = "console",
OutputType = GitVersionOutput.BuildServer,
ToolPath = @"src\GitVersionExe\bin\Release\GitVersion.exe"
});
GitVersion assertedVersions = GitVersion(new GitVersionSettings
{
OutputType = GitVersionOutput.Json,
ToolPath = @"src\GitVersionExe\bin\Release\GitVersion.exe"
});
version = assertedVersions.MajorMinorPatch;
nugetVersion = assertedVersions.NuGetVersion;
preReleaseTag = assertedVersions.PreReleaseTag;
semVersion = assertedVersions.LegacySemVerPadded;
});
Task("NuGet-Package-Restore")
.Does(() =>
{
NuGetRestore("./src/GitVersion.sln");
});
Task("Build")
.IsDependentOn("Version")
.IsDependentOn("NuGet-Package-Restore")
.Does(() =>
{
Build(configuration, nugetVersion, semVersion, version, preReleaseTag);
});
Task("Run-NUnit-Tests")
.IsDependentOn("Build")
.Does(() =>
{
var settings = new NUnit3Settings();
if(IsRunningOnUnix())
{
settings.Where = "cat != NoMono";
}
NUnit3(new [] {
"src/GitVersionCore.Tests/bin/" + configuration + "/GitVersionCore.Tests.dll",
"src/GitVersionExe.Tests/bin/" + configuration + "/GitVersionExe.Tests.dll",
"src/GitVersionTask.Tests/bin/" + configuration + "/GitVersionTask.Tests.dll" },
settings);
if (AppVeyor.IsRunningOnAppVeyor)
{
Information("Uploading test results");
AppVeyor.UploadTestResults("TestResult.xml", AppVeyorTestResultsType.NUnit3);
}
});
Task("Zip-Files")
.IsDependentOn("Run-NUnit-Tests")
.Does(() =>
{
Zip("./build/NuGetCommandLineBuild/Tools/", "build/GitVersion_" + nugetVersion + ".zip");
});
Task("Create-Release-Notes")
.IsDependentOn("Build")
.WithCriteria(() => IsMainGitVersionRepo && IsMainGitVersionBranch && !IsPullRequest)
.Does(() =>
{
var githubToken = EnvironmentVariable("GitHubToken");
if(!string.IsNullOrWhiteSpace(githubToken))
{
IEnumerable<string> redirectedOutput;
var releaseNotesExitCode = StartProcess(
@"tools\GitReleaseNotes\tools\gitreleasenotes.exe",
new ProcessSettings {
Arguments = ". /o build/releasenotes.md /repoToken " + githubToken,
RedirectStandardOutput = true
},
out redirectedOutput);
Information(string.Join("\n", redirectedOutput));
if (!System.IO.File.Exists("./build/releasenotes.md") || string.IsNullOrEmpty(System.IO.File.ReadAllText("./build/releasenotes.md"))) {
System.IO.File.WriteAllText("./build/releasenotes.md", "No issues closed since last release");
}
}
else
{
Information("Create-Release-Notes is being skipped, as GitHub Token is not present.");
}
});
Task("Package")
.IsDependentOn("Create-Release-Notes")
.IsDependentOn("Zip-Files");
Task("Upload-AppVeyor-Artifacts")
.IsDependentOn("Package")
.WithCriteria(() => AppVeyor.IsRunningOnAppVeyor)
.Does(() =>
{
var gem = string.IsNullOrEmpty(preReleaseTag) ?
"gitversion-" + version + ".gem" :
"gitversion-" + version + "." + preReleaseTag + ".gem";
System.IO.File.WriteAllLines("build/artifacts", new[]{
"NuGetExeBuild:GitVersion.Portable." + nugetVersion +".nupkg",
"NuGetCommandLineBuild:GitVersion.CommandLine." + nugetVersion +".nupkg",
"NuGetRefBuild:GitVersion." + nugetVersion +".nupkg",
"NuGetTaskBuild:GitVersionTask." + nugetVersion +".nupkg",
"GitVersionTfsTaskBuild:gittools.gitversion-" + semVersion +".vsix",
"GemBuild:" + gem,
"zip:GitVersion_" + nugetVersion + ".zip"
});
AppVeyor.UploadArtifact("build/NuGetExeBuild/GitVersion.Portable." + nugetVersion +".nupkg");
AppVeyor.UploadArtifact("build/NuGetCommandLineBuild/GitVersion.CommandLine." + nugetVersion +".nupkg");
AppVeyor.UploadArtifact("build/NuGetRefBuild/GitVersion." + nugetVersion +".nupkg");
AppVeyor.UploadArtifact("build/NuGetTaskBuild/GitVersionTask." + nugetVersion +".nupkg");
AppVeyor.UploadArtifact("build/GitVersionTfsTaskBuild/gittools.gitversion-" + semVersion + ".vsix");
AppVeyor.UploadArtifact("build/GitVersion_" + nugetVersion + ".zip");
AppVeyor.UploadArtifact("build/GemBuild/" + gem);
AppVeyor.UploadArtifact("build/artifacts");
if(IsMainGitVersionRepo && IsMainGitVersionBranch && !IsPullRequest)
{
if(FileExists("build/releasenotes.md"))
{
AppVeyor.UploadArtifact("build/releasenotes.md");
}
}
});
Task("Travis")
.IsDependentOn("Run-NUnit-Tests");
Task("Default")
.IsDependentOn("Upload-AppVeyor-Artifacts");
RunTarget(target);