Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Regression: GitVersion 5.12.0 uses only MajorMinorPatch from tag instead of SemVer #3487

Closed
d5UtQvp8QQU9 opened this issue Apr 21, 2023 · 9 comments
Labels
Milestone

Comments

@d5UtQvp8QQU9
Copy link

d5UtQvp8QQU9 commented Apr 21, 2023

Describe the bug
For tagged commits, GitVersion 5.12.0 ignores PreReleaseTagWithDash and applies only MajorMinorPatch from tag.
For versions before that (e.g. GitVersion.MsBuild 5.11.1) the full SemVer from the tag would be used.

Expected Behavior

If i tag a git commit with or without the appropriate tag-prefix followed by a SemVer, GitVersion should use that SemVer.

Actual Behavior

If i tag a git commit with or without the appropriate tag-prefix followed by a SemVer, GitVersion uses only MajorMinorPatch and ignores any PreReleaseTagWithDash

Possible Fix

Steps to Reproduce

Test1 (without tag-prefix):

    [Test]
    public void GivenARepositoryWithSingleCommitAndSingleBranchAndSemVerTag()
    {
        using var fixture = new EmptyRepositoryFixture();
        const string taggedVersion = "1.0.3-beta.14";
        fixture.Repository.MakeATaggedCommit(taggedVersion);
        fixture.Checkout(taggedVersion);

        fixture.AssertFullSemver(taggedVersion);
    }

Result:

 GivenARepositoryWithSingleCommitAndSingleBranchAndSemVerTag
   Source: TagCheckoutScenarios.cs line 34
   Duration: 493 ms

  Message: 
Shouldly.ShouldAssertException : variables.FullSemVer
    should be
"1.0.3-beta.14"
    but was
"1.0.3"
    difference
Difference     |                           |    |    |    |    |    |    |    |   
               |                          \|/  \|/  \|/  \|/  \|/  \|/  \|/  \|/  
Index          | 0    1    2    3    4    5    6    7    8    9    10   11   12   
Expected Value | 1    .    0    .    3    -    b    e    t    a    .    1    4    
Actual Value   | 1    .    0    .    3                                            
Expected Code  | 49   46   48   46   51   45   98   101  116  97   46   49   52   
Actual Code    | 49   46   48   46   51                                           

  Stack Trace: 
GitToolsTestingExtensions.AssertFullSemver(RepositoryFixtureBase fixture, String fullSemver, Config configuration, IRepository repository, String commitId, Boolean onlyTrackedBranches, String targetBranch) line 116
TagCheckoutScenarios.GivenARepositoryWithSingleCommitAndSingleBranchAndSemVerTag() line 41

  Standard Output: 
Initialized empty Git repository in {USERPROFILE}/AppData/Local/Temp/TestRepositories/{UUID}/.git/
Created git repository at '{USERPROFILE}\AppData\Local\Temp\TestRepositories\{UUID}'
---------
* 2a3eb43 58 minutes ago  (HEAD, tag: 1.0.3-beta.14, main)
**Visualisation of test:**

@startuml
@enduml

Test2 (with tag-prefix):

    [Test]
    public void GivenARepositoryWithSingleCommitAndSingleBranchAndPrefixedSemVerTag()
    {
        using var fixture = new EmptyRepositoryFixture();
        const string semVer = "1.0.3-beta.14";
        const string taggedVersion = $"v{semVer}";
        fixture.Repository.MakeATaggedCommit(taggedVersion);
        fixture.Checkout(taggedVersion);

        fixture.AssertFullSemver(semVer);
    }

Result:

 GivenARepositoryWithSingleCommitAndSingleBranchAndPrefixedSemVerTag
   Source: TagCheckoutScenarios.cs line 45
   Duration: 454 ms

  Message: 
Shouldly.ShouldAssertException : variables.FullSemVer
    should be
"1.0.3-beta.14"
    but was
"1.0.3"
    difference
Difference     |                           |    |    |    |    |    |    |    |   
               |                          \|/  \|/  \|/  \|/  \|/  \|/  \|/  \|/  
Index          | 0    1    2    3    4    5    6    7    8    9    10   11   12   
Expected Value | 1    .    0    .    3    -    b    e    t    a    .    1    4    
Actual Value   | 1    .    0    .    3                                            
Expected Code  | 49   46   48   46   51   45   98   101  116  97   46   49   52   
Actual Code    | 49   46   48   46   51                                           

  Stack Trace: 
GitToolsTestingExtensions.AssertFullSemver(RepositoryFixtureBase fixture, String fullSemver, Config configuration, IRepository repository, String commitId, Boolean onlyTrackedBranches, String targetBranch) line 116
TagCheckoutScenarios.GivenARepositoryWithSingleCommitAndSingleBranchAndPrefixedSemVerTag() line 53

  Standard Output: 
Initialized empty Git repository in {USERPROFILE}/AppData/Local/Temp/TestRepositories/{UUID}/.git/
Created git repository at '{USERPROFILE}\AppData\Local\Temp\TestRepositories\{UUID}'
---------
* e64df05 58 minutes ago  (HEAD, tag: v1.0.3-beta.14, main)
**Visualisation of test:**

@startuml
@enduml

Context

Your Environment

  • Version Used: 5.12.0
  • Operating System and version (Windows 10, Ubuntu 18.04): Windows 10
  • Link to your project: -
  • Link to your CI build (if appropriate): -
@asbjornu
Copy link
Member

I believe this is fixed in 6.0.0-beta.2, can you please test it to verify?

@d5UtQvp8QQU9
Copy link
Author

d5UtQvp8QQU9 commented Apr 23, 2023

The results are different but not according to my expectations. Is it a bug or a feature? I don't know.

Summary

7576b44b1
Last 'good'

3a6b12348
First 'bad'

variables.FullSemVer should be "1.0.3-beta.14" but was "1.0.3"

Relevant addition to src/GitVersion.Core/VersionCalculation/NextVersionCalculator.cs:

// set the updated prerelease tag when it doesn't match with prerelease tag defined in branch configuration
if (preReleaseTagDoesNotMatchConfiguration)
{
    taggedSemanticVersion.PreReleaseTag = semver.PreReleaseTag;
}

5.12.0

variables.FullSemVer should be "1.0.3-beta.14" but was "1.0.3"

6.0.0-beta.2
Different result, test still fails:

variables.FullSemVer should be "1.0.3-beta.14" but was "1.0.3-1"

Conclusion

Culprit for 'breakage' in 5.12.0 currently looks like a feature to me.
I can't see right now whether I am using GitVersion in unintended ways or if there is something that can be done to work around this.

Full test results for 6.0.0-beta.2

Result 1 (without tag-prefix):

 GivenARepositoryWithSingleCommitAndSingleBranchAndSemVerTag
   Source: TagCheckoutScenarios.cs line 32
   Duration: 1,2 sec

  Message: 
Shouldly.ShouldAssertException : variables.FullSemVer
    should be
"1.0.3-beta.14"
    but was
"1.0.3-1"
    difference
Difference     |                                |    |    |    |    |    |    |   
               |                               \|/  \|/  \|/  \|/  \|/  \|/  \|/  
Index          | 0    1    2    3    4    5    6    7    8    9    10   11   12   
Expected Value | 1    .    0    .    3    -    b    e    t    a    .    1    4    
Actual Value   | 1    .    0    .    3    -    1                                  
Expected Code  | 49   46   48   46   51   45   98   101  116  97   46   49   52   
Actual Code    | 49   46   48   46   51   45   49                                 

  Stack Trace: 
GitToolsTestingExtensions.AssertFullSemver(RepositoryFixtureBase fixture, String fullSemver, IGitVersionConfiguration configuration, IRepository repository, String commitId, Boolean onlyTrackedBranches, String targetBranch) line 120
TagCheckoutScenarios.GivenARepositoryWithSingleCommitAndSingleBranchAndSemVerTag() line 39
RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)

  Standard Output: 
Initialized empty Git repository in {SOMELOCALPATH}/.git/
Created git repository at '{SOMELOCALPATH}'
---------
**Visualisation of test:**

@startuml
@enduml

Result 2 (with tag-prefix):

 GivenARepositoryWithSingleCommitAndSingleBranchAndPrefixedSemVerTag
   Source: TagCheckoutScenarios.cs line 43
   Duration: 871 ms

  Message: 
Shouldly.ShouldAssertException : variables.FullSemVer
    should be
"1.0.3-beta.14"
    but was
"1.0.3-1"
    difference
Difference     |                                |    |    |    |    |    |    |   
               |                               \|/  \|/  \|/  \|/  \|/  \|/  \|/  
Index          | 0    1    2    3    4    5    6    7    8    9    10   11   12   
Expected Value | 1    .    0    .    3    -    b    e    t    a    .    1    4    
Actual Value   | 1    .    0    .    3    -    1                                  
Expected Code  | 49   46   48   46   51   45   98   101  116  97   46   49   52   
Actual Code    | 49   46   48   46   51   45   49                                 

  Stack Trace: 
GitToolsTestingExtensions.AssertFullSemver(RepositoryFixtureBase fixture, String fullSemver, IGitVersionConfiguration configuration, IRepository repository, String commitId, Boolean onlyTrackedBranches, String targetBranch) line 120
TagCheckoutScenarios.GivenARepositoryWithSingleCommitAndSingleBranchAndPrefixedSemVerTag() line 51
RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)

  Standard Output: 
Initialized empty Git repository in {SOMELOCALPATH}/.git/
Created git repository at '{SOMELOCALPATH}'
---------
**Visualisation of test:**

@startuml
@enduml

@HHobeck
Copy link
Contributor

HHobeck commented Apr 25, 2023

Hi there.

Please consider that in your scenario the pre-release label of the main branch is set to an empty string. That means the resulting versions on this branch are always pre-release versions without a label name. Also the pre release number e.g. coming from a tag will be only incremented if it matches with the pre-release label of the branch. Same is for alpha and beta release stages. The number of beta starts with one independent how many alpha releases have been deployed previously. It makes sense right?

If you want to detect all pre-release labels in one branch because you have a trunk base strategy or whetever you need to specify the pre-release label to null.

Happy Branching.

@HHobeck HHobeck added this to the 6.x milestone Apr 25, 2023
@HHobeck HHobeck closed this as completed Apr 25, 2023
@d5UtQvp8QQU9
Copy link
Author

Hello @HHobeck, thanks for your explanation.
However I do not get it to work with 5.12.0 and above.

Also, I am confused whether this is a bug that requires fixing (as you added the milestone tag) or it is not a bug (as you closed the issue without a commit reference). Am I missing something?

If you want to detect all pre-release labels in one branch because you have a trunk base strategy or whetever you need to specify the pre-release label to null.

I modified my tests to include this recommendation.

Summary

5.11.1

All of my tests pass (as they have without setting the branch tag to null).

5.12.0

All of my tests fail (as they have without setting the branch tag to null).

6.0.0-beta.2

All of my tests fail but the result is different from before.
GitVersion will now use the branch name as branch tag instead of omitting the branch tag.

variables.FullSemVer should be "1.0.3-beta.14" but was "1.0.3-main.1"

Apart from this synthetic test, I also tested setting the branch tag to null in a real szenario, also without success.
Not sure if I understood your comment correctly. Do you have any hints for me?

Test code

5.11.1

    [Test]
    public void GivenARepositoryWithSingleCommitAndSingleBranchAndSemVerTag1()
    {
        // Arrange
        var config = new Config()
        {
            Branches = new Dictionary<string, BranchConfig>()
            {
                { "main", new BranchConfig() { Tag = null } }
            }
        };

        // Act
        using var fixture = new EmptyRepositoryFixture();
        const string taggedVersion = "1.0.3-beta.14";
        fixture.Repository.MakeATaggedCommit(taggedVersion);
        fixture.Checkout(taggedVersion);

        // Assert
        fixture.AssertFullSemver(taggedVersion, config);
    }

    [Test]
    public void GivenARepositoryWithSingleCommitAndSingleBranchAndSemVerTag2()
    {
        // Arrange
        var config = TestConfigurationBuilder.New.WithTag("main", null).Build();

        // Act
        using var fixture = new EmptyRepositoryFixture();
        const string taggedVersion = "1.0.3-beta.14";
        fixture.Repository.MakeATaggedCommit(taggedVersion);
        fixture.Checkout(taggedVersion);

        // Assert
        fixture.AssertFullSemver(taggedVersion, config);
    }

    [Test]
    public void GivenARepositoryWithSingleCommitAndSingleBranchAndPrefixedSemVerTag1()
    {
        // Arrange
        var config = new Config()
        {
            Branches = new Dictionary<string, BranchConfig>()
            {
                { "main", new BranchConfig() { Tag = null } }
            }
        };

        // Act
        using var fixture = new EmptyRepositoryFixture();
        const string semVer = "1.0.3-beta.14";
        const string taggedVersion = $"v{semVer}";
        fixture.Repository.MakeATaggedCommit(taggedVersion);
        fixture.Checkout(taggedVersion);

        // Assert
        fixture.AssertFullSemver(semVer, config);
    }

    [Test]
    public void GivenARepositoryWithSingleCommitAndSingleBranchAndPrefixedSemVerTag2()
    {
        // Arrange
        var config = TestConfigurationBuilder.New.WithTag("main", null).Build();

        // Act
        using var fixture = new EmptyRepositoryFixture();
        const string semVer = "1.0.3-beta.14";
        const string taggedVersion = $"v{semVer}";
        fixture.Repository.MakeATaggedCommit(taggedVersion);
        fixture.Checkout(taggedVersion);

        // Assert
        fixture.AssertFullSemver(semVer, config);
    }

5.12.0

Same test code as with 5.11.1.

6.0.0-beta.2

I had to modify the tests for 6.0.0-beta.2 as new Config() is no longer available:

    [Test]
    public void GivenARepositoryWithSingleCommitAndSingleBranchAndSemVerTag1()
    {
        // Arrange
        var config = GitFlowConfigurationBuilder.New
            .WithBranch("main", builder => builder.WithLabel(null))
            .Build();

        // Act
        using var fixture = new EmptyRepositoryFixture();
        const string taggedVersion = "1.0.3-beta.14";
        fixture.Repository.MakeATaggedCommit(taggedVersion);
        fixture.Checkout(taggedVersion);

        // Assert
        fixture.AssertFullSemver(taggedVersion, config);
    }

    [Test]
    public void GivenARepositoryWithSingleCommitAndSingleBranchAndSemVerTag2()
    {
        // Arrange
        var config = GitHubFlowConfigurationBuilder.New
            .WithBranch("main", builder => builder.WithLabel(null))
            .Build();

        // Act
        using var fixture = new EmptyRepositoryFixture();
        const string taggedVersion = "1.0.3-beta.14";
        fixture.Repository.MakeATaggedCommit(taggedVersion);
        fixture.Checkout(taggedVersion);

        // Assert
        fixture.AssertFullSemver(taggedVersion, config);
    }

    [Test]
    public void GivenARepositoryWithSingleCommitAndSingleBranchAndPrefixedSemVerTag1()
    {
        // Arrange
        var config = GitFlowConfigurationBuilder.New
            .WithBranch("main", builder => builder.WithLabel(null))
            .Build();

        // Act
        using var fixture = new EmptyRepositoryFixture();
        const string semVer = "1.0.3-beta.14";
        const string taggedVersion = $"v{semVer}";
        fixture.Repository.MakeATaggedCommit(taggedVersion);
        fixture.Checkout(taggedVersion);

        // Assert
        fixture.AssertFullSemver(semVer, config);
    }

    [Test]
    public void GivenARepositoryWithSingleCommitAndSingleBranchAndPrefixedSemVerTag2()
    {
        // Arrange
        var config = GitHubFlowConfigurationBuilder.New
            .WithBranch("main", builder => builder.WithLabel(null))
            .Build();

        // Act
        using var fixture = new EmptyRepositoryFixture();
        const string semVer = "1.0.3-beta.14";
        const string taggedVersion = $"v{semVer}";
        fixture.Repository.MakeATaggedCommit(taggedVersion);
        fixture.Checkout(taggedVersion);

        // Assert
        fixture.AssertFullSemver(semVer, config);
    }

Failing test results

5.12.0

Result 1

 GivenARepositoryWithSingleCommitAndSingleBranchAndSemVerTag1
   Source: VersionInTagScenarios.cs line 113
   Duration: 302 ms

  Message: 
Shouldly.ShouldAssertException : variables.FullSemVer
    should be
"1.0.3-beta.14"
    but was
"1.0.3"
    difference
Difference     |                           |    |    |    |    |    |    |    |   
               |                          \|/  \|/  \|/  \|/  \|/  \|/  \|/  \|/  
Index          | 0    1    2    3    4    5    6    7    8    9    10   11   12   
Expected Value | 1    .    0    .    3    -    b    e    t    a    .    1    4    
Actual Value   | 1    .    0    .    3                                            
Expected Code  | 49   46   48   46   51   45   98   101  116  97   46   49   52   
Actual Code    | 49   46   48   46   51                                           

  Stack Trace: 
GitToolsTestingExtensions.AssertFullSemver(RepositoryFixtureBase fixture, String fullSemver, Config configuration, IRepository repository, String commitId, Boolean onlyTrackedBranches, String targetBranch) line 116
VersionInTagScenarios.GivenARepositoryWithSingleCommitAndSingleBranchAndSemVerTag1() line 131

  Standard Output: 
Initialized empty Git repository in {SOMELOCALPATH}/.git/
Created git repository at '{SOMELOCALPATH}'
---------
* 9db1e5d 54 minutes ago  (HEAD, tag: 1.0.3-beta.14, main)
**Visualisation of test:**

@startuml
@enduml

Result 2

 GivenARepositoryWithSingleCommitAndSingleBranchAndSemVerTag2
   Source: VersionInTagScenarios.cs line 135
   Duration: 299 ms

  Message: 
Shouldly.ShouldAssertException : variables.FullSemVer
    should be
"1.0.3-beta.14"
    but was
"1.0.3"
    difference
Difference     |                           |    |    |    |    |    |    |    |   
               |                          \|/  \|/  \|/  \|/  \|/  \|/  \|/  \|/  
Index          | 0    1    2    3    4    5    6    7    8    9    10   11   12   
Expected Value | 1    .    0    .    3    -    b    e    t    a    .    1    4    
Actual Value   | 1    .    0    .    3                                            
Expected Code  | 49   46   48   46   51   45   98   101  116  97   46   49   52   
Actual Code    | 49   46   48   46   51                                           

  Stack Trace: 
GitToolsTestingExtensions.AssertFullSemver(RepositoryFixtureBase fixture, String fullSemver, Config configuration, IRepository repository, String commitId, Boolean onlyTrackedBranches, String targetBranch) line 116
VersionInTagScenarios.GivenARepositoryWithSingleCommitAndSingleBranchAndSemVerTag2() line 147

  Standard Output: 
Initialized empty Git repository in {SOMELOCALPATH}/.git/
Created git repository at '{SOMELOCALPATH}'
---------
* da15e52 52 minutes ago  (HEAD, tag: 1.0.3-beta.14, main)
**Visualisation of test:**

@startuml
@enduml

Result 3

 GivenARepositoryWithSingleCommitAndSingleBranchAndPrefixedSemVerTag1
   Source: VersionInTagScenarios.cs line 151
   Duration: 514 ms

  Message: 
Shouldly.ShouldAssertException : variables.FullSemVer
    should be
"1.0.3-beta.14"
    but was
"1.0.3"
    difference
Difference     |                           |    |    |    |    |    |    |    |   
               |                          \|/  \|/  \|/  \|/  \|/  \|/  \|/  \|/  
Index          | 0    1    2    3    4    5    6    7    8    9    10   11   12   
Expected Value | 1    .    0    .    3    -    b    e    t    a    .    1    4    
Actual Value   | 1    .    0    .    3                                            
Expected Code  | 49   46   48   46   51   45   98   101  116  97   46   49   52   
Actual Code    | 49   46   48   46   51                                           

  Stack Trace: 
GitToolsTestingExtensions.AssertFullSemver(RepositoryFixtureBase fixture, String fullSemver, Config configuration, IRepository repository, String commitId, Boolean onlyTrackedBranches, String targetBranch) line 116
VersionInTagScenarios.GivenARepositoryWithSingleCommitAndSingleBranchAndPrefixedSemVerTag1() line 170

  Standard Output: 
Initialized empty Git repository in {SOMELOCALPATH}/.git/
Created git repository at '{SOMELOCALPATH}'
---------
* 6381ea8 58 minutes ago  (HEAD, tag: v1.0.3-beta.14, main)
**Visualisation of test:**

@startuml
@enduml

Result 4

 GivenARepositoryWithSingleCommitAndSingleBranchAndPrefixedSemVerTag2
   Source: VersionInTagScenarios.cs line 174
   Duration: 303 ms

  Message: 
Shouldly.ShouldAssertException : variables.FullSemVer
    should be
"1.0.3-beta.14"
    but was
"1.0.3"
    difference
Difference     |                           |    |    |    |    |    |    |    |   
               |                          \|/  \|/  \|/  \|/  \|/  \|/  \|/  \|/  
Index          | 0    1    2    3    4    5    6    7    8    9    10   11   12   
Expected Value | 1    .    0    .    3    -    b    e    t    a    .    1    4    
Actual Value   | 1    .    0    .    3                                            
Expected Code  | 49   46   48   46   51   45   98   101  116  97   46   49   52   
Actual Code    | 49   46   48   46   51                                           

  Stack Trace: 
GitToolsTestingExtensions.AssertFullSemver(RepositoryFixtureBase fixture, String fullSemver, Config configuration, IRepository repository, String commitId, Boolean onlyTrackedBranches, String targetBranch) line 116
VersionInTagScenarios.GivenARepositoryWithSingleCommitAndSingleBranchAndPrefixedSemVerTag2() line 187

  Standard Output: 
Initialized empty Git repository in {SOMELOCALPATH}/.git/
Created git repository at '{SOMELOCALPATH}'
---------
* 1ea5338 56 minutes ago  (HEAD, tag: v1.0.3-beta.14, main)
**Visualisation of test:**

@startuml
@enduml

6.0.0-beta.2

Result 1

 GivenARepositoryWithSingleCommitAndSingleBranchAndSemVerTag1
   Source: VersionInTagScenarios.cs line 100
   Duration: 196 ms

  Message: 
Shouldly.ShouldAssertException : variables.FullSemVer
    should be
"1.0.3-beta.14"
    but was
"1.0.3-main.1"
    difference
Difference     |                                |    |    |    |              |   
               |                               \|/  \|/  \|/  \|/            \|/  
Index          | 0    1    2    3    4    5    6    7    8    9    10   11   12   
Expected Value | 1    .    0    .    3    -    b    e    t    a    .    1    4    
Actual Value   | 1    .    0    .    3    -    m    a    i    n    .    1         
Expected Code  | 49   46   48   46   51   45   98   101  116  97   46   49   52   
Actual Code    | 49   46   48   46   51   45   109  97   105  110  46   49        

  Stack Trace: 
GitToolsTestingExtensions.AssertFullSemver(RepositoryFixtureBase fixture, String fullSemver, IGitVersionConfiguration configuration, IRepository repository, String commitId, Boolean onlyTrackedBranches, String targetBranch) line 120
VersionInTagScenarios.GivenARepositoryWithSingleCommitAndSingleBranchAndSemVerTag1() line 114

  Standard Output: 
Initialized empty Git repository in {SOMELOCALPATH}/.git/
Created git repository at '{SOMELOCALPATH}'
---------
**Visualisation of test:**

@startuml
@enduml

Result 2

 GivenARepositoryWithSingleCommitAndSingleBranchAndSemVerTag2
   Source: VersionInTagScenarios.cs line 118
   Duration: 193 ms

  Message: 
Shouldly.ShouldAssertException : variables.FullSemVer
    should be
"1.0.3-beta.14"
    but was
"1.0.3-main.1"
    difference
Difference     |                                |    |    |    |              |   
               |                               \|/  \|/  \|/  \|/            \|/  
Index          | 0    1    2    3    4    5    6    7    8    9    10   11   12   
Expected Value | 1    .    0    .    3    -    b    e    t    a    .    1    4    
Actual Value   | 1    .    0    .    3    -    m    a    i    n    .    1         
Expected Code  | 49   46   48   46   51   45   98   101  116  97   46   49   52   
Actual Code    | 49   46   48   46   51   45   109  97   105  110  46   49        

  Stack Trace: 
GitToolsTestingExtensions.AssertFullSemver(RepositoryFixtureBase fixture, String fullSemver, IGitVersionConfiguration configuration, IRepository repository, String commitId, Boolean onlyTrackedBranches, String targetBranch) line 120
VersionInTagScenarios.GivenARepositoryWithSingleCommitAndSingleBranchAndSemVerTag2() line 132

  Standard Output: 
Initialized empty Git repository in {SOMELOCALPATH}/.git/
Created git repository at '{SOMELOCALPATH}'
---------
**Visualisation of test:**

@startuml
@enduml

Result 3

   GivenARepositoryWithSingleCommitAndSingleBranchAndPrefixedSemVerTag1
     Source: VersionInTagScenarios.cs line 136
     Duration: 474 ms

    Message: 
  Shouldly.ShouldAssertException : variables.FullSemVer
      should be
  "1.0.3-beta.14"
      but was
  "1.0.3-main.1"
      difference
  Difference     |                                |    |    |    |              |   
                 |                               \|/  \|/  \|/  \|/            \|/  
  Index          | 0    1    2    3    4    5    6    7    8    9    10   11   12   
  Expected Value | 1    .    0    .    3    -    b    e    t    a    .    1    4    
  Actual Value   | 1    .    0    .    3    -    m    a    i    n    .    1         
  Expected Code  | 49   46   48   46   51   45   98   101  116  97   46   49   52   
  Actual Code    | 49   46   48   46   51   45   109  97   105  110  46   49        

    Stack Trace: 
  GitToolsTestingExtensions.AssertFullSemver(RepositoryFixtureBase fixture, String fullSemver, IGitVersionConfiguration configuration, IRepository repository, String commitId, Boolean onlyTrackedBranches, String targetBranch) line 120
  VersionInTagScenarios.GivenARepositoryWithSingleCommitAndSingleBranchAndPrefixedSemVerTag1() line 151

    Standard Output: 
  Initialized empty Git repository in {SOMELOCALPATH}/.git/
  Created git repository at '{SOMELOCALPATH}'
  ---------
  **Visualisation of test:**

  @startuml
  @enduml

Result 4

 GivenARepositoryWithSingleCommitAndSingleBranchAndPrefixedSemVerTag2
   Source: VersionInTagScenarios.cs line 155
   Duration: 186 ms

  Message: 
Shouldly.ShouldAssertException : variables.FullSemVer
    should be
"1.0.3-beta.14"
    but was
"1.0.3-main.1"
    difference
Difference     |                                |    |    |    |              |   
               |                               \|/  \|/  \|/  \|/            \|/  
Index          | 0    1    2    3    4    5    6    7    8    9    10   11   12   
Expected Value | 1    .    0    .    3    -    b    e    t    a    .    1    4    
Actual Value   | 1    .    0    .    3    -    m    a    i    n    .    1         
Expected Code  | 49   46   48   46   51   45   98   101  116  97   46   49   52   
Actual Code    | 49   46   48   46   51   45   109  97   105  110  46   49        

  Stack Trace: 
GitToolsTestingExtensions.AssertFullSemver(RepositoryFixtureBase fixture, String fullSemver, IGitVersionConfiguration configuration, IRepository repository, String commitId, Boolean onlyTrackedBranches, String targetBranch) line 120
VersionInTagScenarios.GivenARepositoryWithSingleCommitAndSingleBranchAndPrefixedSemVerTag2() line 170

  Standard Output: 
Initialized empty Git repository in {SOMELOCALPATH}/.git/
Created git repository at '{SOMELOCALPATH}'
---------
**Visualisation of test:**

@startuml
@enduml

@HHobeck
Copy link
Contributor

HHobeck commented May 1, 2023

You need to set the fallback configuration of the label property to null as well on the root level. Please try the following:

    [Test]
    public void GivenARepositoryWithSingleCommitAndSingleBranchAndSemVerTag1()
    {
        // Arrange
        var config = GitFlowConfigurationBuilder.New.WithLabel(null)
            .WithBranch("main", builder => builder.WithLabel(null)
            .WithVersioningMode(VersioningMode.ContinuousDelivery)
        ).Build();

        // Act
        using var fixture = new EmptyRepositoryFixture();
        const string taggedVersion = "1.0.3-beta.14";
        fixture.Repository.MakeATaggedCommit(taggedVersion);
        fixture.Checkout(taggedVersion);

        // Assert
        fixture.AssertFullSemver(taggedVersion, config);
    }

    [Test]
    public void GivenARepositoryWithSingleCommitAndSingleBranchAndSemVerTag2()
    {
        // Arrange
        var config = GitHubFlowConfigurationBuilder.New.WithLabel(null)
            .WithBranch("main", builder => builder.WithLabel(null)
            .WithVersioningMode(VersioningMode.ContinuousDelivery)
        ).Build();

        // Act
        using var fixture = new EmptyRepositoryFixture();
        const string taggedVersion = "1.0.3-beta.14";
        fixture.Repository.MakeATaggedCommit(taggedVersion);
        fixture.Checkout(taggedVersion);

        // Assert
        fixture.AssertFullSemver(taggedVersion, config);
    }

    [Test]
    public void GivenARepositoryWithSingleCommitAndSingleBranchAndPrefixedSemVerTag1()
    {
        // Arrange
        var config = GitFlowConfigurationBuilder.New.WithLabel(null)
            .WithBranch("main", builder => builder.WithLabel(null)
            .WithVersioningMode(VersioningMode.ContinuousDelivery)
        ).Build();

        // Act
        using var fixture = new EmptyRepositoryFixture();
        const string semVer = "1.0.3-beta.14";
        const string taggedVersion = $"v{semVer}";
        fixture.Repository.MakeATaggedCommit(taggedVersion);
        fixture.Checkout(taggedVersion);

        // Assert
        fixture.AssertFullSemver(semVer, config);
    }

    [Test]
    public void GivenARepositoryWithSingleCommitAndSingleBranchAndPrefixedSemVerTag2()
    {
        // Arrange
        var config = GitHubFlowConfigurationBuilder.New.WithLabel(null)
            .WithBranch("main", builder => builder.WithLabel(null)
            .WithVersioningMode(VersioningMode.ContinuousDelivery)
        ).Build();

        // Act
        using var fixture = new EmptyRepositoryFixture();
        const string semVer = "1.0.3-beta.14";
        const string taggedVersion = $"v{semVer}";
        fixture.Repository.MakeATaggedCommit(taggedVersion);
        fixture.Checkout(taggedVersion);

        // Assert
        fixture.AssertFullSemver(semVer, config);
    }

@HHobeck
Copy link
Contributor

HHobeck commented May 1, 2023

You need to forget the previous version and focus on the version 6.x because it's the next version with alot of changes.

@HHobeck
Copy link
Contributor

HHobeck commented May 1, 2023

To understand the different between manually deployment, continues deployment, continues delivery and trunk based (main line) I would suggest you to read the following integration tests:

/src/GitVersion.Core.Tests/IntegrationTests/ComparingTheBehaviorOfDifferentVersioningModes.cs

In advance this might be informative:

@d5UtQvp8QQU9
Copy link
Author

Thank you @HHobeck, this was very helpful!

@arturcic arturcic modified the milestones: 6.x, 6.0.0-beta.3 Jun 26, 2023
@arturcic
Copy link
Member

🎉 This issue has been resolved in version 6.0.0-beta.3 🎉
The release is available on:

Your GitReleaseManager bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants