Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions src/GitVersion.Core.Tests/IntegrationTests/VersioningDemoScenario.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using GitTools.Testing;
using GitVersion.Model.Configuration;
using GitVersion.OutputVariables;
using LibGit2Sharp;
using NUnit.Framework;
using Shouldly;

namespace GitVersion.Core.Tests.IntegrationTests;

public class VersioningDemoScenario
{
[Test]
public void ReleaseAndDevelopProblemDemo()
{
var configuration = new Config
{
// Settings the below NextVersion results in an exception
// I wanted to set it to globally start with version 1
// Setting the version to 1.0 (which is not a valid semantic version)
// works in GitVersion.yml but not here.

// NextVersion = "1.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To start with a 1.0.0 version, you just need to add a git tag. You can do that in a test with fixture.Repository.MakeATaggedCommit("1.0.0").

Copy link
Contributor Author

@bitbonk bitbonk Sep 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making a tagged commit is a bit weird. When looking at the commit log, it looks like as if that commit was the 1.0.0 release.
That's what a version tag usually denotes (I would think)..
Also I was told, that using NextVersion in the config is a good approach here: #3123

};

// create main and develop branch, develop is two commits ahead of main
using var fixture = new EmptyRepositoryFixture();
fixture.Repository.MakeACommit();
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("develop"));
fixture.Repository.MakeACommit();
fixture.Repository.MakeACommit();

var previousVersion = GetSemVer(fixture.GetVersion(configuration));

// make a 3rd commit on develop
fixture.Repository.MakeACommit();

var currentVersion = GetSemVer(fixture.GetVersion(configuration));

currentVersion.ShouldBeGreaterThan(previousVersion,
"the semver should be incremented after a commit on develop");

// we are ready to prepare the 1.0.0 release, create and checkout release/1.0.0
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("release/1.0.0"));

fixture.GetVersion(configuration).SemVer.ShouldBe("1.0.0-beta.1",
"the first semver on release/1.0.0 should be beta1");

// make another commit on release/1.0.0 to prepare the actual beta1 release
fixture.Repository.MakeACommit();

fixture.GetVersion(configuration).SemVer.ShouldBe("1.0.0-beta.1",
"the semver on release/1.0.0 should still be be beta1");

Commands.Checkout(fixture.Repository, fixture.Repository.Branches["develop"]);

previousVersion = currentVersion;
currentVersion = GetSemVer(fixture.GetVersion(configuration));

currentVersion.ShouldBe(previousVersion,
"the semver on develop should not have changed " +
"even when release/1.0.0 has new commits due to beta 1 preparations");

// now some other team member makes changes on develop that may or may not end up in 1.0.0
fixture.Repository.MakeACommit();
fixture.Repository.MakeACommit();

previousVersion = currentVersion;
currentVersion = GetSemVer(fixture.GetVersion(configuration));

currentVersion.ShouldBeGreaterThan(previousVersion,
"the semver should be incremented after a even more commit on develop");

Commands.Checkout(fixture.Repository, fixture.Repository.Branches["release/1.0.0"]);

// now we release the beta 1
fixture.Repository.ApplyTag("1.0.0-beta1");

fixture.GetVersion(configuration).SemVer.ShouldBe("1.0.0-beta.1",
"the on release/1.0.0 should still be beta1 after the beta 1 tag");

// continue with more work on develop that may or may not end up in 1.0.0
Commands.Checkout(fixture.Repository, fixture.Repository.Branches["develop"]);
fixture.Repository.MakeACommit();
fixture.Repository.MakeACommit();

previousVersion = currentVersion;
currentVersion = GetSemVer(fixture.GetVersion(configuration));

currentVersion.ShouldBeGreaterThan(previousVersion,
"the semver should be incremented after a even more commit on develop");

// now we decide that the three commits on develop should be part of the beta 2 release
// se we merge it into release/1.0.0 with --no-ff because it is a protected branch
Commands.Checkout(fixture.Repository, fixture.Repository.Branches["release/1.0.0"]);
fixture.Repository.Merge(
fixture.Repository.Branches["develop"],
Generate.SignatureNow(),
new MergeOptions {FastForwardStrategy = FastForwardStrategy.NoFastForward});

fixture.GetVersion(configuration).SemVer.ShouldBe("1.0.0-beta.2",
"the next semver on release/1.0.0 should be beta2");

Commands.Checkout(fixture.Repository, fixture.Repository.Branches["develop"]);
previousVersion = currentVersion;
currentVersion = GetSemVer(fixture.GetVersion(configuration));

currentVersion.ShouldBeGreaterThanOrEqualTo(previousVersion,
"the semver should be incremented (or unchanged) " +
"after we merged develop into release/1.0.0");

static SemanticVersion GetSemVer(VersionVariables ver)
=> SemanticVersion.Parse(ver.FullSemVer, null);
}
}