Skip to content

Commit 249026e

Browse files
committed
updated scripts to allow stable and pre-release versions
1 parent 188cd0c commit 249026e

File tree

6 files changed

+45
-67
lines changed

6 files changed

+45
-67
lines changed

build/parameters.cake

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ public class BuildParameters
7272
IsLocalBuild = buildSystem.IsLocalBuild,
7373
IsRunningOnAppVeyor = buildSystem.IsRunningOnAppVeyor,
7474
IsRunningOnTravis = buildSystem.IsRunningOnTravisCI,
75-
IsRunningOnAzurePipeline = buildSystem.IsRunningOnVSTS
75+
IsRunningOnAzurePipeline = buildSystem.IsRunningOnVSTS,
76+
77+
IsMainRepo = IsOnMainRepo(context),
78+
IsMainBranch = IsOnMainBranch(context),
79+
IsPullRequest = IsPullRequestBuild(context),
80+
IsTagged = IsBuildTagged(context),
7681
};
7782
}
7883

@@ -106,11 +111,6 @@ public class BuildParameters
106111
};
107112

108113
Credentials = BuildCredentials.GetCredentials(context);
109-
110-
IsMainRepo = IsOnMainRepo(context);
111-
IsMainBranch = IsOnMainBranch(context);
112-
IsPullRequest = IsPullRequestBuild(context);
113-
IsTagged = IsBuildTagged(context, gitVersion);
114114
}
115115

116116
private static bool IsOnMainRepo(ICakeContext context)
@@ -176,10 +176,11 @@ public class BuildParameters
176176
return false;
177177
}
178178

179-
private static bool IsBuildTagged(ICakeContext context, GitVersion gitVersion)
179+
private static bool IsBuildTagged(ICakeContext context)
180180
{
181181
var gitPath = context.Tools.Resolve(context.IsRunningOnWindows() ? "git.exe" : "git");
182-
context.StartProcess(gitPath, new ProcessSettings { Arguments = "tag --points-at " + gitVersion.Sha, RedirectStandardOutput = true }, out var redirectedOutput);
182+
context.StartProcess(gitPath, new ProcessSettings { Arguments = "rev-parse --verify HEAD", RedirectStandardOutput = true }, out var sha);
183+
context.StartProcess(gitPath, new ProcessSettings { Arguments = "tag --points-at " + sha.Single(), RedirectStandardOutput = true }, out var redirectedOutput);
183184

184185
return redirectedOutput.Any();
185186
}

build/paths.cake

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,8 @@ public class BuildPaths
3939
var testCoverageOutputFilePath = buildArtifactDir.CombineWithFilePath("TestResult.xml");
4040
var releaseNotesOutputFilePath = buildArtifactDir.CombineWithFilePath("releasenotes.md");
4141

42-
var vsixVersion = version.DotNetVersion;
43-
var vsixOutputFilePath = buildArtifactDir.CombineWithFilePath("gittools.gitversion-" + vsixVersion + ".vsix");
44-
45-
var gemVersion = version.SemVersion.Replace("-", ".");
46-
var gemOutputFilePath = buildArtifactDir.CombineWithFilePath("gitversion-" + gemVersion + ".gem");
42+
var vsixOutputFilePath = buildArtifactDir.CombineWithFilePath("gittools.gitversion-" + semVersion + ".vsix");
43+
var gemOutputFilePath = buildArtifactDir.CombineWithFilePath("gitversion-" + version.GemVersion + ".gem");
4744

4845
// Directories
4946
var buildDirectories = new BuildDirectories(

build/utils.cake

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,6 @@ void Build(string configuration, GitVersion gitVersion)
7878
.SetVerbosity(Verbosity.Minimal)
7979
.WithTarget("Build")
8080
.WithProperty("POSIX", IsRunningOnUnix().ToString());
81-
82-
if (gitVersion != null) {
83-
Information("Building version {0} of GitVersion", gitVersion.LegacySemVerPadded);
84-
85-
if (!string.IsNullOrWhiteSpace(gitVersion.NuGetVersion)) {
86-
settings.WithProperty("GitVersion_NuGetVersion", gitVersion.NuGetVersion);
87-
}
88-
if (!string.IsNullOrWhiteSpace(gitVersion.LegacySemVerPadded)) {
89-
settings.WithProperty("GitVersion_SemVer", gitVersion.LegacySemVerPadded);
90-
}
91-
if (!string.IsNullOrWhiteSpace(gitVersion.MajorMinorPatch)) {
92-
settings.WithProperty("GitVersion_MajorMinorPatch", gitVersion.MajorMinorPatch);
93-
}
94-
if (!string.IsNullOrWhiteSpace(gitVersion.PreReleaseTag)) {
95-
settings.WithProperty("GitVersion_PreReleaseTag", gitVersion.PreReleaseTag);
96-
}
97-
}
9881
});
9982
}
10083

@@ -149,7 +132,7 @@ void PublishILRepackedGitVersionExe(bool includeLibGit2Sharp, DirectoryPath targ
149132
CopyFileToDirectory("./src/GitVersionExe/bin/" + configuration + "/" + dotnetVersion + "/GitVersion.xml", outputDir);
150133
}
151134

152-
void DockerBuild(GitVersion gitVersion, string platform, string variant, bool isStableRelease = false)
135+
void DockerBuild(string platform, string variant, BuildParameters parameters)
153136
{
154137
var workDir = DirectoryPath.FromString($"./src/Docker/{platform}/{variant}");
155138

@@ -161,7 +144,7 @@ void DockerBuild(GitVersion gitVersion, string platform, string variant, bool is
161144
}
162145
CopyDirectory(sourceDir, workDir.Combine("content"));
163146

164-
var tags = GetDockerTags(gitVersion, platform, variant, isStableRelease);
147+
var tags = GetDockerTags(platform, variant, parameters);
165148

166149
var buildSettings = new DockerImageBuildSettings
167150
{
@@ -176,26 +159,26 @@ void DockerBuild(GitVersion gitVersion, string platform, string variant, bool is
176159
DockerBuild(buildSettings, workDir.ToString());
177160
}
178161

179-
void DockerPush(GitVersion gitVersion, string platform, string variant, bool isStableRelease = false)
162+
void DockerPush(string platform, string variant, BuildParameters parameters)
180163
{
181-
var tags = GetDockerTags(gitVersion, platform, variant, isStableRelease);
164+
var tags = GetDockerTags(platform, variant, parameters);
182165

183166
foreach (var tag in tags)
184167
{
185168
DockerPush(tag);
186169
}
187170
}
188171

189-
string[] GetDockerTags(GitVersion gitVersion, string platform, string variant, bool isStableRelease = false) {
172+
string[] GetDockerTags(string platform, string variant, BuildParameters parameters) {
190173
var name = $"gittools/gitversion-{variant}";
191174

192175
var tags = new List<string> {
193-
$"{name}:{platform}-{gitVersion.LegacySemVerPadded}"
176+
$"{name}:{platform}-{parameters.Version.Version}"
194177
};
195178

196-
tags.Add($"{name}:{platform}-{gitVersion.LegacySemVerPadded}-{gitVersion.CommitsSinceVersionSource}");
179+
tags.Add($"{name}:{platform}-{parameters.Version.SemVersion}");
197180

198-
if (variant == "dotnetcore" && isStableRelease) {
181+
if (variant == "dotnetcore" && parameters.IsStableRelease()) {
199182
tags.Add($"{name}:latest");
200183
}
201184

build/version.cake

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,22 @@ public class BuildVersion
22
{
33
public string Version { get; private set; }
44
public string SemVersion { get; private set; }
5-
public string NuGetVersion { get; private set; }
6-
public string DotNetAsterix { get; private set; }
7-
public string DotNetVersion { get; private set; }
8-
public string PreReleaseTag { get; private set; }
5+
public string GemVersion { get; private set; }
96

107
public static BuildVersion Calculate(ICakeContext context, BuildParameters parameters, GitVersion gitVersion)
118
{
129
var version = gitVersion.MajorMinorPatch;
13-
var preReleaseTag = gitVersion.PreReleaseTag;
1410
var semVersion = gitVersion.LegacySemVerPadded;
15-
var dotnetVersion = version;
1611

17-
semVersion += "-" + gitVersion.CommitsSinceVersionSource;
18-
dotnetVersion += "." + gitVersion.CommitsSinceVersionSource;
12+
if (!string.IsNullOrWhiteSpace(gitVersion.BuildMetaDataPadded)) {
13+
semVersion += "-" + gitVersion.BuildMetaDataPadded;
14+
}
1915

2016
return new BuildVersion
2117
{
22-
Version = version,
23-
SemVersion = semVersion,
24-
NuGetVersion = gitVersion.NuGetVersion,
25-
DotNetAsterix = semVersion.Substring(version.Length).TrimStart('-'),
26-
DotNetVersion = dotnetVersion,
27-
PreReleaseTag = preReleaseTag
18+
Version = version,
19+
SemVersion = semVersion,
20+
GemVersion = semVersion.Replace("-", "."),
2821
};
2922
}
3023
}

run.cake

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ Task("Copy-Files")
217217
Framework = dotnetVersion,
218218
NoBuild = true,
219219
NoRestore = true,
220-
VersionSuffix = parameters.Version.DotNetAsterix,
221220
Configuration = parameters.Configuration,
222221
OutputDirectory = parameters.Paths.Directories.ArtifactsBinFullFx,
223222
MSBuildSettings = msBuildSettings
@@ -254,7 +253,7 @@ Task("Pack-Tfs")
254253
var workDir = "./src/GitVersionTfsTask";
255254

256255
// update version number
257-
ReplaceTextInFile(new FilePath(workDir + "/vss-extension.json"), "$version$", parameters.Version.DotNetVersion);
256+
ReplaceTextInFile(new FilePath(workDir + "/vss-extension.json"), "$version$", parameters.Version.SemVersion);
258257

259258
var taskJsonFile = new FilePath(workDir + "/GitVersionTask/task.json");
260259
var taskJson = ParseJsonFromFile(taskJsonFile);
@@ -285,7 +284,7 @@ Task("Pack-Gem")
285284

286285
var gemspecFile = new FilePath(workDir + "/gitversion.gemspec");
287286
// update version number
288-
ReplaceTextInFile(gemspecFile, "$version$", parameters.Version.SemVersion.Replace("-", "."));
287+
ReplaceTextInFile(gemspecFile, "$version$", parameters.Version.GemVersion);
289288

290289
var toolPath = FindToolInPath(IsRunningOnWindows() ? "gem.cmd" : "gem");
291290
GemBuild(gemspecFile, new Cake.Gem.Build.GemBuildSettings()
@@ -304,11 +303,15 @@ Task("Pack-Nuget")
304303
foreach(var package in parameters.Packages.Nuget)
305304
{
306305
if (FileExists(package.NuspecPath)) {
306+
var artifactPath = MakeAbsolute(parameters.PackagesBuildMap[package.Id]).FullPath;
307+
307308
var nugetSettings = new NuGetPackSettings
308309
{
309310
Version = parameters.Version.SemVersion,
310-
BasePath = parameters.PackagesBuildMap[package.Id],
311311
OutputDirectory = parameters.Paths.Directories.NugetRoot,
312+
Files = GetFiles(artifactPath + "/**/*.*")
313+
.Select(file => new NuSpecContent { Source = file.FullPath, Target = file.FullPath.Replace(artifactPath, "") })
314+
.ToArray()
312315
};
313316

314317
FixForMono(nugetSettings, "nuget.exe");
@@ -373,16 +376,15 @@ Task("Docker-Build")
373376
.IsDependentOn("Copy-Files")
374377
.Does(() =>
375378
{
376-
var version = gitVersion;
377379
if (parameters.IsRunningOnWindows)
378380
{
379-
DockerBuild(version, "windows", "dotnetcore", parameters.IsStableRelease());
380-
DockerBuild(version, "windows", "fullfx");
381+
DockerBuild("windows", "dotnetcore", parameters);
382+
DockerBuild("windows", "fullfx", parameters);
381383
}
382384
else if (parameters.IsRunningOnLinux)
383385
{
384-
DockerBuild(version, "linux", "dotnetcore", parameters.IsStableRelease());
385-
DockerBuild(version, "linux", "fullfx");
386+
DockerBuild("linux", "dotnetcore", parameters);
387+
DockerBuild("linux", "fullfx", parameters);
386388
}
387389
});
388390

@@ -481,7 +483,7 @@ Task("Publish-Tfs")
481483
.WithCriteria(() => parameters.EnabledPublishTfs, "Publish-Tfs was disabled.")
482484
.WithCriteria(() => parameters.IsRunningOnWindows, "Publish-Tfs works only on Windows agents.")
483485
.WithCriteria(() => parameters.IsRunningOnAppVeyor, "Publish-Tfs works only on AppVeyor.")
484-
.WithCriteria(() => parameters.IsStableRelease() || parameters.IsPreRelease(), "Publish-Tfs works only for releases.")
486+
.WithCriteria(() => parameters.IsStableRelease(), "Publish-Tfs works only for releases.")
485487
.IsDependentOn("Pack-Tfs")
486488
.Does(() =>
487489
{
@@ -551,18 +553,17 @@ Task("Publish-DockerHub")
551553
throw new InvalidOperationException("Could not resolve Docker password.");
552554
}
553555

554-
var version = gitVersion;
555556
DockerLogin(parameters.Credentials.Docker.UserName, parameters.Credentials.Docker.Password);
556557

557558
if (parameters.IsRunningOnWindows)
558559
{
559-
DockerPush(version, "windows", "dotnetcore", parameters.IsStableRelease());
560-
DockerPush(version, "windows", "fullfx");
560+
DockerPush("windows", "dotnetcore", parameters);
561+
DockerPush("windows", "fullfx", parameters);
561562
}
562563
else if (parameters.IsRunningOnLinux)
563564
{
564-
DockerPush(version, "linux", "dotnetcore", parameters.IsStableRelease());
565-
DockerPush(version, "linux", "fullfx");
565+
DockerPush("linux", "dotnetcore", parameters);
566+
DockerPush("linux", "fullfx", parameters);
566567
}
567568

568569
DockerLogout();

run.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,7 @@ Write-Host "Running build script..."
161161
$Cmd = "$CakeInstallPath/dotnet-cake $Script $Arguments"
162162
Invoke-Expression "& $Cmd"
163163

164+
if ($env:APPVEYOR) {
165+
$host.SetShouldExit($LASTEXITCODE)
166+
}
164167
exit $LASTEXITCODE

0 commit comments

Comments
 (0)