Skip to content

Commit 4265865

Browse files
committed
IsStableRelease and IsPreRelease should be true only if it's master branch and not PR, reviewed the versioning of artifacts
1 parent 5eca897 commit 4265865

File tree

6 files changed

+119
-71
lines changed

6 files changed

+119
-71
lines changed

build/parameters.cake

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ public class BuildParameters
88
public string Target { get; private set; }
99
public string Configuration { get; private set; }
1010

11-
public bool DisableUnitTests { get; private set; }
12-
public bool DisablePublishGem { get; private set; }
13-
public bool DisablePublishTfs { get; private set; }
14-
public bool DisablePublishNuget { get; private set; }
15-
public bool DisablePublishChocolatey { get; private set; }
16-
public bool DisablePublishDocker { get; private set; }
11+
public bool EnabledUnitTests { get; private set; }
12+
public bool EnabledPublishGem { get; private set; }
13+
public bool EnabledPublishTfs { get; private set; }
14+
public bool EnabledPublishNuget { get; private set; }
15+
public bool EnabledPublishChocolatey { get; private set; }
16+
public bool EnabledPublishDocker { get; private set; }
17+
public bool EnabledPullRequestPublish { get; private set; }
1718

1819
public bool IsRunningOnUnix { get; private set; }
1920
public bool IsRunningOnWindows { get; private set; }
@@ -28,6 +29,7 @@ public class BuildParameters
2829
public bool IsMainRepo { get; private set; }
2930
public bool IsMainBranch { get; private set; }
3031
public bool IsTagged { get; private set; }
32+
public bool IsPullRequest { get; private set; }
3133

3234
public BuildCredentials Credentials { get; private set; }
3335
public BuildVersion Version { get; private set; }
@@ -36,8 +38,8 @@ public class BuildParameters
3638
public BuildArtifacts Artifacts { get; private set; }
3739
public Dictionary<string, DirectoryPath> PackagesBuildMap { get; private set; }
3840

39-
public bool IsStableRelease() => !IsLocalBuild && IsMainRepo && IsMainBranch && IsTagged;
40-
public bool IsPreRelease() => !IsLocalBuild && IsMainRepo && IsMainBranch && !IsTagged;
41+
public bool IsStableRelease() => !IsLocalBuild && IsMainRepo && IsMainBranch && !IsPullRequest && IsTagged;
42+
public bool IsPreRelease() => !IsLocalBuild && IsMainRepo && IsMainBranch && !IsPullRequest && !IsTagged;
4143

4244
public bool CanPostToGitter => !string.IsNullOrWhiteSpace(Credentials.Gitter.Token) && !string.IsNullOrWhiteSpace(Credentials.Gitter.RoomId);
4345

@@ -55,12 +57,13 @@ public class BuildParameters
5557
Target = target,
5658
Configuration = context.Argument("configuration", "Release"),
5759

58-
DisableUnitTests = IsDisabled(context, "DISABLE_UNIT_TESTS"),
59-
DisablePublishGem = IsDisabled(context, "DISABLE_PUBLISH_GEM"),
60-
DisablePublishTfs = IsDisabled(context, "DISABLE_PUBLISH_TFS"),
61-
DisablePublishNuget = IsDisabled(context, "DISABLE_PUBLISH_NUGET"),
62-
DisablePublishChocolatey = IsDisabled(context, "DISABLE_PUBLISH_CHOCOLATEY"),
63-
DisablePublishDocker = IsDisabled(context, "DISABLE_PUBLISH_DOCKER"),
60+
EnabledUnitTests = IsEnabled(context, "ENABLED_UNIT_TESTS"),
61+
EnabledPublishGem = IsEnabled(context, "ENABLED_PUBLISH_GEM"),
62+
EnabledPublishTfs = IsEnabled(context, "ENABLED_PUBLISH_TFS"),
63+
EnabledPublishNuget = IsEnabled(context, "ENABLED_PUBLISH_NUGET"),
64+
EnabledPublishChocolatey = IsEnabled(context, "ENABLED_PUBLISH_CHOCOLATEY"),
65+
EnabledPublishDocker = IsEnabled(context, "ENABLED_PUBLISH_DOCKER"),
66+
EnabledPullRequestPublish = IsEnabled(context, "ENABLED_PULL_REQUEST_PUBLISH", false),
6467

6568
IsRunningOnUnix = context.IsRunningOnUnix(),
6669
IsRunningOnWindows = context.IsRunningOnWindows(),
@@ -105,9 +108,10 @@ public class BuildParameters
105108

106109
Credentials = BuildCredentials.GetCredentials(context);
107110

108-
IsMainRepo = IsOnMainRepo(context);
109-
IsMainBranch = IsOnMainBranch(context);
110-
IsTagged = IsBuildTagged(context, gitVersion);
111+
IsMainRepo = IsOnMainRepo(context);
112+
IsMainBranch = IsOnMainBranch(context);
113+
IsPullRequest = IsPullRequestBuild(context);
114+
IsTagged = IsBuildTagged(context, gitVersion);
111115
}
112116

113117
private static bool IsOnMainRepo(ICakeContext context)
@@ -154,6 +158,25 @@ public class BuildParameters
154158
return !string.IsNullOrWhiteSpace(repositoryBranch) && StringComparer.OrdinalIgnoreCase.Equals("master", repositoryBranch);
155159
}
156160

161+
private static bool IsPullRequestBuild(ICakeContext context)
162+
{
163+
var buildSystem = context.BuildSystem();
164+
if (buildSystem.IsRunningOnAppVeyor)
165+
{
166+
return buildSystem.AppVeyor.Environment.PullRequest.IsPullRequest;
167+
}
168+
if (buildSystem.IsRunningOnTravisCI)
169+
{
170+
return !string.IsNullOrWhiteSpace(buildSystem.TravisCI.Environment.Repository.PullRequest)
171+
&& !string.Equals(buildSystem.TravisCI.Environment.Repository.PullRequest, false.ToString(), StringComparison.InvariantCultureIgnoreCase);
172+
}
173+
else if (buildSystem.IsRunningOnVSTS)
174+
{
175+
return false; // need a way to check if it is from a PR on azure pipelines
176+
}
177+
return false;
178+
}
179+
157180
private static bool IsBuildTagged(ICakeContext context, GitVersion gitVersion)
158181
{
159182
var gitPath = context.Tools.Resolve(context.IsRunningOnWindows() ? "git.exe" : "git");
@@ -162,10 +185,10 @@ public class BuildParameters
162185
return redirectedOutput.Any();
163186
}
164187

165-
private static bool IsDisabled(ICakeContext context, string envVar)
188+
private static bool IsEnabled(ICakeContext context, string envVar, bool nullOrEmptyAsEnabled = true)
166189
{
167190
var value = context.EnvironmentVariable(envVar);
168191

169-
return !string.IsNullOrWhiteSpace(value) && bool.Parse(value);
192+
return string.IsNullOrWhiteSpace(value) ? nullOrEmptyAsEnabled : bool.Parse(value);
170193
}
171194
}

build/paths.cake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ public class BuildPaths
3939

4040
var testCoverageOutputFilePath = buildArtifactDir.CombineWithFilePath("TestResult.xml");
4141
var releaseNotesOutputFilePath = buildArtifactDir.CombineWithFilePath("releasenotes.md");
42-
var vsixOutputFilePath = buildArtifactDir.CombineWithFilePath("gittools.gitversion-" + version.Version + ".vsix");
42+
var vsixOutputFilePath = buildArtifactDir.CombineWithFilePath("gittools.gitversion-" + semVersion + ".vsix");
4343

44-
var gemVersion = version.GemVersion.Replace("-", ".pre.");
45-
var gemOutputFilePath = buildArtifactDir.CombineWithFilePath("testgw-" + gemVersion + ".gem");
44+
var gemVersion = version.SemVersion.Replace("-", ".pre.");
45+
var gemOutputFilePath = buildArtifactDir.CombineWithFilePath("gitversion-" + gemVersion + ".gem");
4646

4747
// Directories
4848
var buildDirectories = new BuildDirectories(

build/utils.cake

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,8 @@ void PublishILRepackedGitVersionExe(bool includeLibGit2Sharp, DirectoryPath targ
149149
CopyFileToDirectory("./src/GitVersionExe/bin/" + configuration + "/" + dotnetVersion + "/GitVersion.xml", outputDir);
150150
}
151151

152-
void DockerBuild(GitVersion version, string platform, string variant)
152+
void DockerBuild(GitVersion gitVersion, string platform, string variant, bool isStableRelease = false)
153153
{
154-
var name = $"gittools/gitversion-{variant}";
155154
var workDir = DirectoryPath.FromString($"./src/Docker/{platform}/{variant}");
156155

157156
DirectoryPath sourceDir;
@@ -162,10 +161,12 @@ void DockerBuild(GitVersion version, string platform, string variant)
162161
}
163162
CopyDirectory(sourceDir, workDir.Combine("content"));
164163

164+
var tags = GetDockerTags(gitVersion, platform, variant, isStableRelease);
165+
165166
var buildSettings = new DockerImageBuildSettings
166167
{
167168
Rm = true,
168-
Tag = new []{ $"{name}:{platform}-{version.MajorMinorPatch}" },
169+
Tag = tags,
169170
File = $"{workDir}/Dockerfile",
170171
BuildArg = new []{ $"contentFolder=/content" },
171172
Pull = true,
@@ -175,13 +176,32 @@ void DockerBuild(GitVersion version, string platform, string variant)
175176
DockerBuild(buildSettings, workDir.ToString());
176177
}
177178

178-
void DockerPush(GitVersion version, string platform, string variant)
179+
void DockerPush(GitVersion gitVersion, string platform, string variant, bool isStableRelease = false)
179180
{
181+
var tags = GetDockerTags(gitVersion, platform, variant, isStableRelease);
182+
183+
foreach (var tag in tags)
184+
{
185+
DockerPush(tag);
186+
}
187+
}
188+
189+
string[] GetDockerTags(GitVersion gitVersion, string platform, string variant, bool isStableRelease = false) {
180190
var name = $"gittools/gitversion-{variant}";
181-
var tag = $"{name}:{platform}-{version.MajorMinorPatch}";
182191

183-
Information("Tag Name {0}", tag);
184-
DockerPush(tag);
192+
var tags = new List<string> {
193+
$"{name}:{platform}-{gitVersion.LegacySemVerPadded}"
194+
};
195+
196+
if (!string.IsNullOrWhiteSpace(gitVersion.BuildMetaDataPadded)) {
197+
tags.Add($"{name}:{platform}-{gitVersion.LegacySemVerPadded}.{gitVersion.BuildMetaDataPadded}");
198+
}
199+
200+
if (variant == "dotnetcore" && isStableRelease) {
201+
tags.Add($"{name}:latest");
202+
}
203+
204+
return tags.ToArray();
185205
}
186206

187207
void GetReleaseNotes(FilePath outputPath, DirectoryPath workDir, string repoToken)

build/version.cake

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,24 @@ public class BuildVersion
55
public string NuGetVersion { get; private set; }
66
public string DotNetAsterix { get; private set; }
77
public string PreReleaseTag { get; private set; }
8-
public string GemVersion { get; private set; }
98

109
public static BuildVersion Calculate(ICakeContext context, BuildParameters parameters, GitVersion gitVersion)
1110
{
12-
var semVersion = gitVersion.LegacySemVerPadded;
1311
var version = gitVersion.MajorMinorPatch;
1412
var preReleaseTag = gitVersion.PreReleaseTag;
13+
var semVersion = gitVersion.LegacySemVerPadded;
1514

16-
var gemVersion = string.IsNullOrEmpty(preReleaseTag)
17-
? version
18-
: version + "." + preReleaseTag + "." + gitVersion.BuildMetaDataPadded;
15+
if (!string.IsNullOrWhiteSpace(gitVersion.BuildMetaDataPadded)) {
16+
semVersion += "." + gitVersion.BuildMetaDataPadded;
17+
}
1918

2019
return new BuildVersion
2120
{
22-
Version = version,
23-
SemVersion = semVersion,
24-
NuGetVersion = gitVersion.NuGetVersion,
21+
Version = version,
22+
SemVersion = semVersion,
23+
NuGetVersion = gitVersion.NuGetVersion,
2524
DotNetAsterix = semVersion.Substring(version.Length).TrimStart('-'),
26-
PreReleaseTag = preReleaseTag,
27-
GemVersion = gemVersion.TrimEnd('.')
25+
PreReleaseTag = preReleaseTag
2826
};
2927
}
3028
}

0 commit comments

Comments
 (0)