Skip to content

Commit

Permalink
Merge pull request #364 from ParticularLabs/release/3.0.0
Browse files Browse the repository at this point in the history
Release/3.0.0
  • Loading branch information
JakeGinnivan committed Mar 13, 2015
2 parents 8b994aa + f277ae7 commit 049624a
Show file tree
Hide file tree
Showing 240 changed files with 3,593 additions and 4,441 deletions.
7 changes: 7 additions & 0 deletions BREAKING CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
v3.0.0
- Develop no longer tracks master
- NextVersion.txt has been deprecated, only GitVersion.yaml is supported
- `AssemblyFileSemVer` variable removed, AssemblyVersioningScheme configuration value makes this variable obsolete
- Variables `ClassicVersion` and `ClassicVersionWithTag` removed
- MSBuild task arguments (AssemblyVersioningScheme, DevelopBranchTag, ReleaseBranchTag, TagPrefix, NextVersion) have been removed, use GitVersionConfig.yaml instead
- GitVersionTask ReleaseDateAttribute no longer has OriginalReleaseDate
93 changes: 93 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Contributing to GitVersion
We love contributions to get started contributing you might need:

- [Get started with git](http://rogerdudler.github.io/git-guide)
- [How to create a pull request](https://help.github.com/articles/using-pull-requests)
- [An issue to work on](https://github.com/ParticularLabs/GitVersion/labels/up-for-grabs) - We are on [Up for grabs](http://up-for-grabs.net/), our up for grabs issues are tagged `up-for-grabs`
- An understanding of our [architecture](#architecture) and how [we write tests](#writing-tests)

Once you know how to create a pull request and have an issue to work on, just post a comment saying you will work on it.
If you end up not being able to complete the task, please post another comment so others can pick it up.

Issues are also welcome, [failing tests](#writing-tests) are even more welcome.

# Architecture
GitVersion has three distict steps for calculating versions in v3.0.

1. If the current commit is tagged, the tag is used and build metadata (Excluding commit count) is added. The other two steps will not execute
2. A set of strategies are evaluated to decide on the base version and some metadata about that version.
These strategies include HighestReachableTag, NextVersionInConfig, MergedBranchWithVersion, VersionInBranchName etc.
3. The highest base version is selected, using that base version the new version is calculated.

Visually it looks something like this:
![Version Calculation](http://www.plantuml.com:80/plantuml/png/fLCxJyCm4DxzAsuib4P914i69De1CS38Vd6kYIN7ZcodK8aVp-KX6Y2fKCbY9NV-7lVb2WoOeoVOMRDNfH0lz1vUoNbbpGwrR3K6ws1p3rlk-bN8u972f2AC3GHEbLN8m1D1Jjg-mPuXAZvx9kL1ZW1KY5dOZczMI0Pf54VnHtf7jpaAWJg0sW-uXw4PK3Eb1sMaevfCW6i1_0m6po1l7HfPJUxvu5XYUOHLWq5MLptCudmMK9--u5glJ0dIEaVo1Dw3JgVM6Km4cM9mzyrQXHuQHnj7chhl0JcnIrHjno1wiWtgfi8eWVK_7OQAmBHrJWvORFVM2PmrE7AcWZGh-Lj0FvptVvLiUPnCdG_XhNhOov9wQ1fzv7nw5S5EwSvw6CDQNfnMwUAP0XQyQpj70nkx3Nn3p5NFY9IshbNWepKi8ublWFiSPkC0ee8El75Dv5aOxqZQBScbWpWn0Pe2wb6aM1p4Eea_0G00)

[Edit Diagram](http://www.plantuml.com/plantuml/form?url=http://www.plantuml.com/plantuml/png/fLCxJyCm4DxzAsuib4P914i69De1CS38Vd6kYIN7ZcodK8aVp-KX6Y2fKCbY9NV-7lVb2WoOeoVOMRDNfH0lz1vUoNbbpGwrR3K6ws1p3rlk-bN8u972f2AC3GHEbLN8m1D1Jjg-mPuXAZvx9kL1ZW1KY5dOZczMI0Pf54VnHtf7jpaAWJg0sW-uXw4PK3Eb1sMaevfCW6i1_0m6po1l7HfPJUxvu5XYUOHLWq5MLptCudmMK9--u5glJ0dIEaVo1Dw3JgVM6Km4cM9mzyrQXHuQHnj7chhl0JcnIrHjno1wiWtgfi8eWVK_7OQAmBHrJWvORFVM2PmrE7AcWZGh-Lj0FvptVvLiUPnCdG_XhNhOov9wQ1fzv7nw5S5EwSvw6CDQNfnMwUAP0XQyQpj70nkx3Nn3p5NFY9IshbNWepKi8ublWFiSPkC0ee8El75Dv5aOxqZQBScbWpWn0Pe2wb6aM1p4Eea_0G00)

**\*** Some strategies allow the version to be incremented, others don't. More info below
**+** This version is out of context with the rest of the example. It is here just to show what happens if the check is true

## Base Version Strategies
Currently we have the following strategies

- `HighestTagBaseVersionStrategy` - Finds the highest reachable tag from the current branch
- `VersionInBranchBaseVersionStrategy` - Extracts version information from the branch name. eg `release/3.0.0` will find `3.0.0`
- `ConfigNextVersionBaseVersionStrategy` - Returns the version from the GitVersion.yaml file
- `MergeMessageBaseVersionStrategy` - Finds version numbers from merge messages. eg. `Merge 'release/3.0.0' into 'master'` will return `3.0.0`
- `FallbackBaseVersionStrategy` - Always returns 0.1.0 for new repositories

Each strategy needs to return an instance of `BaseVersion` which has the following properties

- `Source` - Description of the source. eg `Merge message 'Merge 'release/3.0.0' into 'master''
- `ShouldIncrement` - Some strategies should have the version incremented, others do not. eg `ConfigNextVersionBaseVersionStrategy` returns false, `HighestTagBaseVersionStrategy` returns true
- `SemanticVersion` - SemVer of the base version strategy
- `BaseVersionSource` - Sha of the source. Commits will be counted from this Sha. Can be null (eg ConfigNextVersionBaseVersionStrategy returns null)
- `BranchNameOverride` - When `useBranchNameAsTag` is used, this allows the branch name to be changed by a base version.
VersionInBranchBaseVersionStrategy uses this to strip out anything before the first - or /. So `foo` ends up being evaluated as `foo`. If in doubt, just use null

# Writing Tests
We have made it super easy to write tests in GitVersion. Most tests you are interested in are in `GitVersionCore.Tests\IntegrationTests`.

There is a scenario class for each type of branch. For example MasterScenarios, FeatureBranchScenarios etc.

## 1. Find Appropriate Scenario class
Find where your issue would logically sit. Or create a new scenario class if it doesn't fit anywhere in particular.

## 2. Create a test method
We are currently using NUnit, so just create a descriptive test method and attribute it with `[Test]`

## 3. Use a fixture
We have a few fixtures for different scenarios.

- `EmptyRepositoryFixture` - Gives you an empty git repo to start with
- `RemoteRepositoryFixture` - A local repo tracking a test remote repository. The remote repo is available through the `Repository` property, the local is accessible via `LocalRepository`
- `BaseGitFlowRepositoryFixture` - A repo setup for GitFlow (has a develop branch checked out ready to go)

You can use a fixture by just `using` it. Like this
``` csharp
using (var fixture = new EmptyRepositoryFixture(new Config()))
{
}
```

## 4. Customise config
If you are using non-default configuration just modify the `Config` class before creating the fixture

## 5. Writing the scenario
We have a number of extension method off `IRepository` to make it easy to write tests at the flow level and not worry about creating/commiting files.

An example test looks like this:
``` csharp
fixture.Repository.MakeATaggedCommit("1.0.0");
fixture.Repository.CreateBranch("feature-test");
fixture.Repository.Checkout("feature-test");
fixture.Repository.MakeACommit();
fixture.Repository.MakeCommits(4);

fixture.AssertFullSemver("1.0.1-test.1+5");
```

The last line is the most important. `AssertFullSemver` will run GitVersion and assert that the full SemVer it calculates is what you expect.

## 6. Submit a pull request with the failing test
Even better include the fix, but a failing test is a great start
21 changes: 5 additions & 16 deletions GitVersion.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30723.0
# Visual Studio 14
VisualStudioVersion = 14.0.22512.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitVersionExe", "GitVersionExe\GitVersionExe.csproj", "{C3578A7B-09A6-4444-9383-0DEAFA4958BD}"
EndProject
Expand All @@ -13,6 +13,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitVersionCore.Tests", "Git
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3EFFC5D6-88D0-49D9-BB53-E1B7EB49DD45}"
ProjectSection(SolutionItems) = preProject
BREAKING CHANGES.md = BREAKING CHANGES.md
CONTRIBUTING.md = CONTRIBUTING.md
GitVersionConfig.yaml = GitVersionConfig.yaml
LICENSE = LICENSE
README.md = README.md
EndProjectSection
Expand All @@ -24,47 +27,33 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C3578A7B-09A6-4444-9383-0DEAFA4958BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C3578A7B-09A6-4444-9383-0DEAFA4958BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C3578A7B-09A6-4444-9383-0DEAFA4958BD}.Debug|x86.ActiveCfg = Debug|Any CPU
{C3578A7B-09A6-4444-9383-0DEAFA4958BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C3578A7B-09A6-4444-9383-0DEAFA4958BD}.Release|Any CPU.Build.0 = Release|Any CPU
{C3578A7B-09A6-4444-9383-0DEAFA4958BD}.Release|x86.ActiveCfg = Release|Any CPU
{5A86453B-96FB-4B6E-A283-225BB9F753D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5A86453B-96FB-4B6E-A283-225BB9F753D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5A86453B-96FB-4B6E-A283-225BB9F753D3}.Debug|x86.ActiveCfg = Debug|Any CPU
{5A86453B-96FB-4B6E-A283-225BB9F753D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5A86453B-96FB-4B6E-A283-225BB9F753D3}.Release|Any CPU.Build.0 = Release|Any CPU
{5A86453B-96FB-4B6E-A283-225BB9F753D3}.Release|x86.ActiveCfg = Release|Any CPU
{F7AC0E71-3E9A-4F6D-B986-E004825A48E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F7AC0E71-3E9A-4F6D-B986-E004825A48E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F7AC0E71-3E9A-4F6D-B986-E004825A48E1}.Debug|x86.ActiveCfg = Debug|Any CPU
{F7AC0E71-3E9A-4F6D-B986-E004825A48E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F7AC0E71-3E9A-4F6D-B986-E004825A48E1}.Release|Any CPU.Build.0 = Release|Any CPU
{F7AC0E71-3E9A-4F6D-B986-E004825A48E1}.Release|x86.ActiveCfg = Release|Any CPU
{BF905F84-382C-440D-92F5-C61108626D8D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BF905F84-382C-440D-92F5-C61108626D8D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BF905F84-382C-440D-92F5-C61108626D8D}.Debug|x86.ActiveCfg = Debug|Any CPU
{BF905F84-382C-440D-92F5-C61108626D8D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BF905F84-382C-440D-92F5-C61108626D8D}.Release|Any CPU.Build.0 = Release|Any CPU
{BF905F84-382C-440D-92F5-C61108626D8D}.Release|x86.ActiveCfg = Release|Any CPU
{F9741A0D-B9D7-4557-9A1C-A7252C1071F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F9741A0D-B9D7-4557-9A1C-A7252C1071F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F9741A0D-B9D7-4557-9A1C-A7252C1071F5}.Debug|x86.ActiveCfg = Debug|Any CPU
{F9741A0D-B9D7-4557-9A1C-A7252C1071F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F9741A0D-B9D7-4557-9A1C-A7252C1071F5}.Release|Any CPU.Build.0 = Release|Any CPU
{F9741A0D-B9D7-4557-9A1C-A7252C1071F5}.Release|x86.ActiveCfg = Release|Any CPU
{75C2BE85-1DAF-4E34-8305-B17AFAA982A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{75C2BE85-1DAF-4E34-8305-B17AFAA982A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{75C2BE85-1DAF-4E34-8305-B17AFAA982A6}.Debug|x86.ActiveCfg = Debug|Any CPU
{75C2BE85-1DAF-4E34-8305-B17AFAA982A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{75C2BE85-1DAF-4E34-8305-B17AFAA982A6}.Release|Any CPU.Build.0 = Release|Any CPU
{75C2BE85-1DAF-4E34-8305-B17AFAA982A6}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 2 additions & 0 deletions GitVersion.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PossibleMistakenCallToGetType_002E2/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PossibleNullReferenceException/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PrivateFieldCanBeConvertedToLocalVariable/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantArgumentName/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantArgumentNameForLiteralExpression/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantAssignment/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantBaseConstructorCall/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantBoolCompare/@EntryIndexedValue">ERROR</s:String>
Expand Down
4 changes: 2 additions & 2 deletions GitVersionConfig.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
assembly-versioning-scheme: MajorMinor
next-version: 2.0.1
assembly-versioning-scheme: MajorMinorPatch
next-version: 3.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public void BuildNumberIsFullSemVer()

semanticVersion.BuildMetaData.CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z");
semanticVersion.BuildMetaData.Sha = "commitSha";
new BuildServer().WriteIntegration(semanticVersion, writes.Add);
var variables = VariableProvider.GetVariablesFor(semanticVersion, AssemblyVersioningScheme.MajorMinorPatch, VersioningMode.ContinuousDelivery, "ci", false);
new BuildServer().WriteIntegration(writes.Add, variables);

writes[1].ShouldBe("1.2.3-beta.1+5");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
assembly-versioning-scheme: MajorMinorPatch
mode: ContinuousDelivery
tag-prefix: '[vV]'
continuous-delivery-fallback-tag: ci
branches:
master:
tag:
increment: Patch
preventIncrementOfMergedBranchVersion: true
release[/-]:
tag: beta
feature[/-]:
tag: useBranchName
increment: Inherit
hotfix[/-]:
tag: beta
support[/-]:
tag:
increment: Patch
preventIncrementOfMergedBranchVersion: true
develop:
mode: ContinuousDeployment
tag: unstable
increment: Minor
(pull|pull\-requests|pr)[/-]:
tag: PullRequest
increment: Inherit
tagNumberPattern: '[/-](?<number>\d+)[-/]'
89 changes: 78 additions & 11 deletions GitVersionCore.Tests/ConfigProviderTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using ApprovalTests;
using GitVersion;
using GitVersion.Helpers;
using NUnit.Framework;
Expand All @@ -25,28 +28,87 @@ public void CanReadDocument()
{
const string text = @"
assembly-versioning-scheme: MajorMinor
develop-branch-tag: alpha
release-branch-tag: rc
next-version: 2.0.0
tag-prefix: '[vV|version-]'
mode: ContinuousDelivery
branches:
develop:
mode: ContinuousDeployment
tag: dev
release[/-]:
mode: continuousDeployment
tag: rc
";
SetupConfigFileContent(text);

var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor);
config.DevelopBranchTag.ShouldBe("alpha");
config.ReleaseBranchTag.ShouldBe("rc");
config.NextVersion.ShouldBe("2.0.0");
config.TagPrefix.ShouldBe("[vV|version-]");
config.VersioningMode.ShouldBe(VersioningMode.ContinuousDelivery);
config.Branches["develop"].Tag.ShouldBe("dev");
config.Branches["release[/-]"].Tag.ShouldBe("rc");
config.Branches["release[/-]"].VersioningMode.ShouldBe(VersioningMode.ContinuousDeployment);
config.Branches["develop"].VersioningMode.ShouldBe(VersioningMode.ContinuousDeployment);
}

[Test]
public void CanReadOldDocument()
{
const string text = @"assemblyVersioningScheme: MajorMinor";
const string text = @"
assemblyVersioningScheme: MajorMinor
develop-branch-tag: alpha
release-branch-tag: rc
";
SetupConfigFileContent(text);
var error = Should.Throw<OldConfigurationException>(() => ConfigurationProvider.Provide(gitDirectory, fileSystem));
error.Message.ShouldContainWithoutWhitespace(@"GitVersionConfig.yaml contains old configuration, please fix the following errors:
assemblyVersioningScheme has been replaced by assembly-versioning-scheme
develop-branch-tag has been replaced by branch specific configuration.See https://github.com/ParticularLabs/GitVersion/wiki/Branch-Specific-Configuration
release-branch-tag has been replaced by branch specific configuration.See https://github.com/ParticularLabs/GitVersion/wiki/Branch-Specific-Configuration");
}

[Test]
public void OverwritesDefaultsWithProvidedConfig()
{
const string text = @"
next-version: 2.0.0
branches:
develop:
mode: ContinuousDeployment
tag: dev";
SetupConfigFileContent(text);
var defaultConfig = new Config();
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor);

config.NextVersion.ShouldBe("2.0.0");
config.AssemblyVersioningScheme.ShouldBe(defaultConfig.AssemblyVersioningScheme);
config.Branches["develop"].Increment.ShouldBe(defaultConfig.Branches["develop"].Increment);
config.Branches["develop"].VersioningMode.ShouldBe(defaultConfig.Branches["develop"].VersioningMode);
config.Branches["develop"].Tag.ShouldBe("dev");
}

[Test]
public void CanProvideConfigForNewBranch()
{
const string text = @"
next-version: 2.0.0
branches:
bug[/-]:
tag: bugfix";
SetupConfigFileContent(text);
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);

config.Branches["bug[/-]"].Tag.ShouldBe("bugfix");
}

[Test]
[MethodImpl(MethodImplOptions.NoInlining)]
public void CanWriteOutEffectiveConfiguration()
{
var config = ConfigurationProvider.GetEffectiveConfigAsString(gitDirectory, fileSystem);

Approvals.Verify(config);
}

[Test]
Expand All @@ -56,8 +118,8 @@ public void CanReadDefaultDocument()
SetupConfigFileContent(text);
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinorPatch);
config.DevelopBranchTag.ShouldBe("unstable");
config.ReleaseBranchTag.ShouldBe("beta");
config.Branches["develop"].Tag.ShouldBe("unstable");
config.Branches["release[/-]"].Tag.ShouldBe("beta");
config.TagPrefix.ShouldBe("[vV]");
config.NextVersion.ShouldBe(null);
}
Expand All @@ -66,10 +128,12 @@ public void CanReadDefaultDocument()
public void VerifyInit()
{
var config = typeof(Config);
var aliases = config.GetProperties().Select(p => ((YamlAliasAttribute) p.GetCustomAttribute(typeof(YamlAliasAttribute))).Alias);
var aliases = config.GetProperties()
.Where(p => p.GetCustomAttribute<ObsoleteAttribute>() == null)
.Select(p => ((YamlMemberAttribute) p.GetCustomAttribute(typeof(YamlMemberAttribute))).Alias);
var writer = new StringWriter();

ConfigReader.WriteSample(writer);
ConfigSerialiser.WriteSample(writer);
var initFile = writer.GetStringBuilder().ToString();

foreach (var alias in aliases)
Expand All @@ -82,7 +146,10 @@ public void VerifyInit()
public void VerifyAliases()
{
var config = typeof(Config);
var propertiesMissingAlias = config.GetProperties().Where(p => p.GetCustomAttribute(typeof(YamlAliasAttribute)) == null).Select(p => p.Name);
var propertiesMissingAlias = config.GetProperties()
.Where(p => p.GetCustomAttribute<ObsoleteAttribute>() == null)
.Where(p => p.GetCustomAttribute(typeof(YamlMemberAttribute)) == null)
.Select(p => p.Name);

propertiesMissingAlias.ShouldBeEmpty();
}
Expand Down
Loading

0 comments on commit 049624a

Please sign in to comment.