|
| 1 | +using GitTools.Testing; |
| 2 | +using GitVersion.Model.Configuration; |
| 3 | +using GitVersion.OutputVariables; |
| 4 | +using LibGit2Sharp; |
| 5 | +using NUnit.Framework; |
| 6 | +using Shouldly; |
| 7 | + |
| 8 | +namespace GitVersion.Core.Tests.IntegrationTests; |
| 9 | + |
| 10 | +public class VersioningDemoScenario |
| 11 | +{ |
| 12 | + [Test] |
| 13 | + public void ReleaseAndDevelopProblemDemo() |
| 14 | + { |
| 15 | + var configuration = new Config |
| 16 | + { |
| 17 | + // Settings the below NextVersion results in an exception |
| 18 | + // I wanted to set it to globally start with version 1 |
| 19 | + // Setting the version to 1.0 (which is not a valid semantic version) |
| 20 | + // works in GitVersion.yml but not here. |
| 21 | + |
| 22 | + // NextVersion = "1.0" |
| 23 | + }; |
| 24 | + |
| 25 | + // create main and develop branch, develop is two commits ahead of main |
| 26 | + using var fixture = new EmptyRepositoryFixture(); |
| 27 | + fixture.Repository.MakeACommit(); |
| 28 | + Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("develop")); |
| 29 | + fixture.Repository.MakeACommit(); |
| 30 | + fixture.Repository.MakeACommit(); |
| 31 | + |
| 32 | + var previousVersion = GetSemVer(fixture.GetVersion(configuration)); |
| 33 | + |
| 34 | + // make a 3rd commit on develop |
| 35 | + fixture.Repository.MakeACommit(); |
| 36 | + |
| 37 | + var currentVersion = GetSemVer(fixture.GetVersion(configuration)); |
| 38 | + |
| 39 | + currentVersion.ShouldBeGreaterThan(previousVersion, |
| 40 | + "the semver should be incremented after a commit on develop"); |
| 41 | + |
| 42 | + // we are ready to prepare the 1.0.0 release, create and checkout release/1.0.0 |
| 43 | + Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("release/1.0.0")); |
| 44 | + |
| 45 | + fixture.GetVersion(configuration).SemVer.ShouldBe("1.0.0-beta.1", |
| 46 | + "the first semver on release/1.0.0 should be beta1"); |
| 47 | + |
| 48 | + // make another commit on release/1.0.0 to prepare the actual beta1 release |
| 49 | + fixture.Repository.MakeACommit(); |
| 50 | + |
| 51 | + fixture.GetVersion(configuration).SemVer.ShouldBe("1.0.0-beta.1", |
| 52 | + "the semver on release/1.0.0 should still be be beta1"); |
| 53 | + |
| 54 | + Commands.Checkout(fixture.Repository, fixture.Repository.Branches["develop"]); |
| 55 | + |
| 56 | + previousVersion = currentVersion; |
| 57 | + currentVersion = GetSemVer(fixture.GetVersion(configuration)); |
| 58 | + |
| 59 | + currentVersion.ShouldBe(previousVersion, |
| 60 | + "the semver on develop should not have changed " + |
| 61 | + "even when release/1.0.0 has new commits due to beta 1 preparations"); |
| 62 | + |
| 63 | + // now some other team member makes changes on develop that may or may not end up in 1.0.0 |
| 64 | + fixture.Repository.MakeACommit(); |
| 65 | + fixture.Repository.MakeACommit(); |
| 66 | + |
| 67 | + previousVersion = currentVersion; |
| 68 | + currentVersion = GetSemVer(fixture.GetVersion(configuration)); |
| 69 | + |
| 70 | + currentVersion.ShouldBeGreaterThan(previousVersion, |
| 71 | + "the semver should be incremented after a even more commit on develop"); |
| 72 | + |
| 73 | + Commands.Checkout(fixture.Repository, fixture.Repository.Branches["release/1.0.0"]); |
| 74 | + |
| 75 | + // now we release the beta 1 |
| 76 | + fixture.Repository.ApplyTag("1.0.0-beta1"); |
| 77 | + |
| 78 | + fixture.GetVersion(configuration).SemVer.ShouldBe("1.0.0-beta.1", |
| 79 | + "the on release/1.0.0 should still be beta1 after the beta 1 tag"); |
| 80 | + |
| 81 | + // continue with more work on develop that may or may not end up in 1.0.0 |
| 82 | + Commands.Checkout(fixture.Repository, fixture.Repository.Branches["develop"]); |
| 83 | + fixture.Repository.MakeACommit(); |
| 84 | + fixture.Repository.MakeACommit(); |
| 85 | + |
| 86 | + previousVersion = currentVersion; |
| 87 | + currentVersion = GetSemVer(fixture.GetVersion(configuration)); |
| 88 | + |
| 89 | + currentVersion.ShouldBeGreaterThan(previousVersion, |
| 90 | + "the semver should be incremented after a even more commit on develop"); |
| 91 | + |
| 92 | + // now we decide that the three commits on develop should be part of the beta 2 release |
| 93 | + // se we merge it into release/1.0.0 with --no-ff because it is a protected branch |
| 94 | + Commands.Checkout(fixture.Repository, fixture.Repository.Branches["release/1.0.0"]); |
| 95 | + fixture.Repository.Merge( |
| 96 | + fixture.Repository.Branches["develop"], |
| 97 | + Generate.SignatureNow(), |
| 98 | + new MergeOptions {FastForwardStrategy = FastForwardStrategy.NoFastForward}); |
| 99 | + |
| 100 | + fixture.GetVersion(configuration).SemVer.ShouldBe("1.0.0-beta.2", |
| 101 | + "the next semver on release/1.0.0 should be beta2"); |
| 102 | + |
| 103 | + Commands.Checkout(fixture.Repository, fixture.Repository.Branches["develop"]); |
| 104 | + previousVersion = currentVersion; |
| 105 | + currentVersion = GetSemVer(fixture.GetVersion(configuration)); |
| 106 | + |
| 107 | + currentVersion.ShouldBeGreaterThanOrEqualTo(previousVersion, |
| 108 | + "the semver should be incremented (or unchanged) " + |
| 109 | + "after we merged develop into release/1.0.0"); |
| 110 | + |
| 111 | + static SemanticVersion GetSemVer(VersionVariables ver) |
| 112 | + => SemanticVersion.Parse(ver.FullSemVer, null); |
| 113 | + } |
| 114 | +} |
0 commit comments