Skip to content

Commit be16ab8

Browse files
committed
Merge branch 'feature/fix_fallback_branches' of https://github.com/pwiens/GitVersion into feature/fix_fallback_branches
2 parents 1c626b3 + 362a350 commit be16ab8

39 files changed

+881
-352
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,5 @@ src/GitVersionTfsTask/*.js
113113
/tools
114114
/*.zip
115115
GitVersion.CommandLine/*/
116+
117+
releaseArtifacts

BREAKING CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ v4.0.0
88
- The default keys are: master, develop, feature, release, pull-request, hotfix, support
99
- Just run GitVersion.exe in your project directory and it will tell you what to change your config keys to
1010
- For example, `dev(elop)?(ment)?$` is now just `develop`, we suggest not overring regex's unless you really want to use a different convention.
11+
- source-branches added as a configuration option for branches, it helps GitVersion pick the correct source branch
1112

1213
v3.0.0
1314
- NextVersion.txt has been deprecated, only GitVersionConfig.yaml is supported

Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ ARG GitVersionZip
66
# Add GitVersion
77

88
ADD ./releaseArtifacts/$GitVersionZip .
9-
RUN unzip -d /usr/lib/GitVersion/ $GitVersionZip
10-
RUN rm $GitVersionZip
9+
RUN unzip -d /usr/lib/GitVersion/ $GitVersionZip && rm $GitVersionZip
1110
WORKDIR /usr/lib/GitVersion/
1211

1312
# Libgit2 can't resolve relative paths, patch to absolute path
@@ -16,4 +15,4 @@ RUN sed -i 's|lib/linux/x86_64|/usr/lib/GitVersion/lib/linux/x86_64|g' /usr/lib/
1615
RUN mkdir /repo
1716
VOLUME /repo
1817

19-
ENTRYPOINT ["mono", "./GitVersion.exe", "/repo"]
18+
ENTRYPOINT ["mono", "./GitVersion.exe", "/repo"]

appveyor.deploy.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
image: Visual Studio 2017
2+
3+
environment:
4+
DOCKER_USERNAME:
5+
secure: EbFuNVc5k/p9AiaBmS839D4GqsNaMlJ3djyRR5b2fjM=
6+
DOCKER_PASSWORD:
7+
secure: kweTIFTVyAVyKlvcIvgffpNa6qK8wyWAekVgue8WFqI=
8+
19
install:
2-
npm i -g tfx-cli
10+
- npm i -g tfx-cli
11+
- docker version
312

413
assembly_info:
514
patch: false

deploy.cake

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#addin "Cake.Json"
2+
#addin "Cake.Docker"
23

34
var target = Argument("target", "Deploy");
5+
var tagOverride = Argument("TagOverride", "");
46

57
using System.Net;
68
using System.Linq;
@@ -25,6 +27,13 @@ string Get(string url)
2527
Task("EnsureRequirements")
2628
.Does(() =>
2729
{
30+
// This allows us to test deployments locally..
31+
if (!string.IsNullOrWhiteSpace(tagOverride))
32+
{
33+
tag = tagOverride;
34+
return;
35+
}
36+
2837
if (!AppVeyor.IsRunningOnAppVeyor)
2938
throw new Exception("Deployment should happen via appveyor");
3039

@@ -42,8 +51,12 @@ Task("UpdateVersionInfo")
4251
.IsDependentOn("EnsureRequirements")
4352
.Does(() =>
4453
{
45-
tag = AppVeyor.Environment.Repository.Tag.Name;
46-
AppVeyor.UpdateBuildVersion(tag);
54+
// Will not be empty if overriden
55+
if (tag == "")
56+
{
57+
tag = AppVeyor.Environment.Repository.Tag.Name;
58+
AppVeyor.UpdateBuildVersion(tag);
59+
}
4760
});
4861

4962
Task("DownloadGitHubReleaseArtifacts")
@@ -180,23 +193,43 @@ Task("Publish-DockerImage")
180193
.IsDependentOn("DownloadGitHubReleaseArtifacts")
181194
.Does(() =>
182195
{
196+
var username = EnvironmentVariable("DOCKER_USERNAME");
197+
var password = EnvironmentVariable("DOCKER_PASSWORD");
198+
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
199+
{
200+
Warning("Skipping docker publish due to missing credentials");
201+
return;
202+
}
203+
183204
var returnCode = StartProcess("docker", new ProcessSettings
184205
{
185-
Arguments = "build . --build-arg GitVersionZip=" + artifactLookup["zip"] + " --tag gittools/gitversion"
206+
Arguments = "build . --build-arg GitVersionZip=" + artifactLookup["zip"] + " --tag gittools/gitversion:" + tag
186207
});
187208
if (returnCode != 0) {
188209
Information("Publish-DockerImage Task failed to build image, but continuing with next Task...");
189210
publishingError = true;
211+
return;
212+
}
213+
214+
returnCode = StartProcess("docker", new ProcessSettings
215+
{
216+
Arguments = "run -v " + System.IO.Directory.GetCurrentDirectory() + ":/repo gittools/gitversion:" + tag
217+
});
218+
if (returnCode != 0) {
219+
Information("Publish-DockerImage Task failed to run built image, but continuing with next Task...");
220+
publishingError = true;
221+
return;
190222
}
191223

192224
// Login to dockerhub
193225
returnCode = StartProcess("docker", new ProcessSettings
194226
{
195-
Arguments = "login -u=\"" + EnvironmentVariable("DOCKER_USERNAME") +"\" -p=\"" + EnvironmentVariable("DOCKER_PASSWORD") +"\""
227+
Arguments = "login -u=\"" + username +"\" -p=\"" + password +"\""
196228
});
197229
if (returnCode != 0) {
198230
Information("Publish-DockerImage Task failed to login, but continuing with next Task...");
199231
publishingError = true;
232+
return;
200233
}
201234

202235
// Publish Tag
@@ -207,10 +240,19 @@ Task("Publish-DockerImage")
207240
if (returnCode != 0) {
208241
Information("Publish-DockerImage Task failed push version tag, but continuing with next Task...");
209242
publishingError = true;
243+
return;
210244
}
211245

212246
// Publish latest
213247
returnCode = StartProcess("docker", new ProcessSettings
248+
{
249+
Arguments = "tag gittools/gitversion:" + tag + " gittools/gitversion:latest"
250+
});
251+
if (returnCode != 0) {
252+
Information("Publish-DockerImage Task failed latest tag, but continuing with next Task...");
253+
publishingError = true;
254+
}
255+
returnCode = StartProcess("docker", new ProcessSettings
214256
{
215257
Arguments = "push gittools/gitversion:latest"
216258
});

docs/configuration.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,70 @@ values, but here they are if you need to:
243243
### regex
244244
This is the regex which is used to match the current branch to the correct branch configuration.
245245

246+
### source-branches
247+
Because git commits only refer to parent commits (not branches) GitVersion sometimes cannot tell which branch the current branch was branched from.
248+
249+
Take this commit graph
250+
251+
```
252+
* release/1.0.0 * feature/foo
253+
| ________________/
254+
|/
255+
*
256+
*
257+
* (master)
258+
```
259+
260+
By looking at this graph, you cannot tell which of these scenarios happened:
261+
262+
1. feature/foo branches off release/1.0.0
263+
- Branch release/1.0.0 from master
264+
- Branch feature/foo from release/1.0.0
265+
- Add a commit to both release/1.0.0 and feature/foo
266+
- release/1.0.0 is the base for feature/foo
267+
268+
2. release/1.0.0 branches off feature/foo
269+
- Branch feature/foo from master
270+
- Branch release/1.0.0 from feature/foo
271+
- Add a commit to both release/1.0.0 and feature/foo
272+
- feature/foo is the base for release/1.0.0
273+
274+
Or put more simply, you cannot tell which branch was created first, `release/1.0.0` or `feature/foo`.
275+
276+
To resolve this issue, we give GitVersion a hint about our branching workflows by telling it what types of branches a branch can be created from. For example, feature branches are, by default, configured to have the following source branches:
277+
278+
`source-branches: ['master', 'develop', 'feature', 'hotfix', 'support']`
279+
280+
This means that we will never bother to evaluate pull request branches as merge base options and being explicit in this way also improves the performance of GitVersion.
281+
282+
### is-source-branch-for
283+
The reverse of `source-branches`. This property was introduced to keep it easy to extend GitVersion's config.
284+
285+
It exists to make it easier to extend GitVersion's configuration. If only `source-branches` exists and you add a new branch type, for instance `unstable/`, you then need to re-define the `source-branches` configuration value for existing branches (like feature/) to now include the new unstable branch.
286+
287+
A complete example:
288+
289+
```
290+
branches:
291+
unstable:
292+
regex: ...
293+
is-source-branch-for: ['master', 'develop', 'feature', 'hotfix', 'support']
294+
```
295+
296+
Without this configuration value you would have to do:
297+
298+
299+
```
300+
branches:
301+
unstable:
302+
regex: ...
303+
feature:
304+
source-branches: ['unstable', 'develop', 'feature', 'hotfix', 'support']
305+
release:
306+
source-branches: ['unstable', 'develop']
307+
etc...
308+
```
309+
246310
### branches
247311
The header for all the individual branch configuration.
248312

docs/why.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ It solves:
66
- Rebuilding tags always produces the same version
77
- Not having to rebuild to increment versions
88
- Not duplicating version information in multiple places (branch release/2.0.0 already has the version in it, why do I need to change something else)
9-
- Each branch calculates it's SemVer and versions flow between branches when they are merged
9+
- Each branch calculates its SemVer and versions flow between branches when they are merged
1010
- Pull requests produce unique pre-release version numbers
1111
- NuGet semver issues
1212
- Build server integration

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@ pages:
5555
- Versioning modes:
5656
- Versioning modes: reference/versioning-mode.md
5757
- Mainline development: reference/mainline-development.md
58-
- Continous delivery: reference/continuous-delivery.md
58+
- Continuous delivery: reference/continuous-delivery.md
5959
- Continuous deployment: reference/continuous-deployment.md

src/DockerBase/Dockerfile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
FROM ubuntu
1+
FROM ubuntu:16.04
22

33
MAINTAINER GitTools Maintainers <[email protected]>
44

55
# Wheezy doesn't support glibc 2.15 which libgit2sharp requires
66
# So we are going to install mono on ubuntu instead
77
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
8-
RUN apt-get update
9-
RUN apt-get install libcurl3 tzdata unzip curl git-all -y
108
RUN echo "deb http://download.mono-project.com/repo/debian wheezy main" | tee /etc/apt/sources.list.d/mono-xamarin.list
11-
RUN apt-get update
12-
RUN apt-get install mono-complete -y
9+
RUN apt-get update && apt-get install libcurl3 tzdata unzip curl git-all mono-complete -y && apt-get -yqq clean
1310
RUN cp /usr/share/zoneinfo/GMT /etc/localtime
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System;
2+
using GitVersion;
3+
using GitVersionCore.Tests;
4+
using NUnit.Framework;
5+
using Shouldly;
6+
using System.Collections.Generic;
7+
8+
[TestFixture]
9+
public class VsoAgentBuildNumberTests
10+
{
11+
string key = "BUILD_BUILDNUMBER";
12+
string logPrefix = "##vso[build.updatebuildnumber]";
13+
List<Tuple<string, string, string>> examples;
14+
VsoAgent versionBuilder = new VsoAgent();
15+
16+
[SetUp]
17+
public void SetUpVsoAgentBuildNumberTest()
18+
{
19+
examples = new List<Tuple<string, string, string>>();
20+
}
21+
22+
[TearDown]
23+
public void TearDownVsoAgentBuildNumberTest()
24+
{
25+
examples = null;
26+
Environment.SetEnvironmentVariable(key, null, EnvironmentVariableTarget.Process);
27+
}
28+
29+
30+
[Test]
31+
public void VsoAgentBuildNumberWithFullSemVer()
32+
{
33+
examples.Add(new Tuple<string, string, string>("$(GitVersion.FullSemVer)", "1.0.0", "1.0.0"));
34+
examples.Add(new Tuple<string, string, string>("$(GITVERSION_FULLSEMVER)", "1.0.0", "1.0.0"));
35+
examples.Add(new Tuple<string, string, string>("$(GitVersion.FullSemVer)-Build.1234", "1.0.0", "1.0.0-Build.1234"));
36+
examples.Add(new Tuple<string, string, string>("$(GITVERSION_FULLSEMVER)-Build.1234", "1.0.0", "1.0.0-Build.1234"));
37+
38+
foreach (var example in examples)
39+
{
40+
Environment.SetEnvironmentVariable(key, example.Item1, EnvironmentVariableTarget.Process);
41+
var vars = new TestableVersionVariables(fullSemVer: example.Item2);
42+
43+
var logMessage = versionBuilder.GenerateSetVersionMessage(vars);
44+
logMessage.ShouldBe(logPrefix + example.Item3);
45+
}
46+
}
47+
48+
49+
[Test]
50+
public void VsoAgentBuildNumberWithSemVer()
51+
{
52+
examples.Add(new Tuple<string, string, string>("$(GitVersion.SemVer)", "1.0.0", "1.0.0"));
53+
examples.Add(new Tuple<string, string, string>("$(GITVERSION_SEMVER)", "1.0.0", "1.0.0"));
54+
examples.Add(new Tuple<string, string, string>("$(GitVersion.SemVer)-Build.1234", "1.0.0", "1.0.0-Build.1234"));
55+
examples.Add(new Tuple<string, string, string>("$(GITVERSION_SEMVER)-Build.1234", "1.0.0", "1.0.0-Build.1234"));
56+
57+
foreach (var example in examples)
58+
{
59+
Environment.SetEnvironmentVariable(key, example.Item1, EnvironmentVariableTarget.Process);
60+
var vars = new TestableVersionVariables(semVer: example.Item2);
61+
62+
var logMessage = versionBuilder.GenerateSetVersionMessage(vars);
63+
logMessage.ShouldBe(logPrefix + example.Item3);
64+
}
65+
}
66+
67+
}

0 commit comments

Comments
 (0)