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] 5.12 bumps major based on the previous merges instead of the last tag and branch convention #3644

Closed
dawidkeshop opened this issue Aug 4, 2023 · 6 comments · Fixed by #3883
Labels
Milestone

Comments

@dawidkeshop
Copy link

Describe the bug
GitVersion instead of respecting last tag to calculate new major version in the branch, analyses the whole master history picks some merges and bumps Major too much. (5 instead of 3).

Branch history with visible master tag:
image

Version put into the csproj file by the GitVersion:
image

Old merges which bumps the Major part:
image

Expected Behavior

The new AssemblyVersion should be 3.0.0

Actual Behavior

The new AssemblyVersion is 5.0.0.

Possible Fix

Maybe stop analyzing the whole history, just pick up the parent branch tag?

Context

I'm trying to adapt GitVersion based CI process for publishing my packages. The process supposed to be very easy:

  • a master branch which is stable branch for releasing stable packages;
  • major/, /minor, patch/ prefixed branches for features and fixes, these branches should increase version number according to the name pattern and store the number in csproj file;
  • after merging any branch to master, pipeline script tags master with AssemblyVersion from merged branch;
  • new branch starts from master which is tagged, so branch naming convention should apply to bump the version properly.

Steps to Reproduce

Have an existing project with history and then use GitVersion.

My configuration:

mode: Mainline
assembly-versioning-format: '{Major}.{Minor}.{Patch}'
assembly-file-versioning-format: '{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber ?? 0}'
branches:
  master:
    is-mainline: true
    increment: None
  major:
    regex: ^major[\/-]
    increment: Major
    source-branches: ['master']
  minor:
    regex: ^minor[\/-]
    increment: Minor
    source-branches: ['master', 'support']
  patch:
    regex: ^patch[\/-]
    increment: Patch
    source-branches: ['master', 'support']
  support:
    is-mainline: true
    regex: ^support[/-]
    tag: ''
    increment: None
    source-branches: ['master']

Logs from GitVersion

INFO [08/04/23 11:03:41:03] Branch from build environment: refs/heads/major/another-breaking-change
INFO [08/04/23 11:03:41:03] Begin: Normalizing git directory for branch 'refs/heads/major/another-breaking-change'
  INFO [08/04/23 11:03:41:06] One remote found (origin -> '<xxx>`).
  INFO [08/04/23 11:03:41:06] Skipping fetching, if GitVersion does not calculate your version as expected you might need to allow fetching or use dynamic repositories
  INFO [08/04/23 11:03:41:07] Creating local branch major/another-breaking-change
  INFO [08/04/23 11:03:41:10] Creating local branch from remote tracking 'refs/remotes/origin/major-add-implemented'.
  INFO [08/04/23 11:03:41:12] Creating local branch from remote tracking 'refs/remotes/origin/major/very-breaking-change'.
  INFO [08/04/23 11:03:41:12] Creating local branch from remote tracking 'refs/remotes/origin/master'.
  INFO [08/04/23 11:03:41:13] Creating local branch from remote tracking 'refs/remotes/origin/minor/test-new-tags'.
  INFO [08/04/23 11:03:41:13] HEAD points at branch 'refs/heads/major/another-breaking-change'.
  INFO [08/04/23 11:03:41:13] End: Normalizing git directory for branch 'refs/heads/major/another-breaking-change' (Took: 108.23ms)
  INFO [08/04/23 11:03:41:15] Begin: Loading version variables from disk cache
    INFO [08/04/23 11:03:41:15] Cache file C:\project\.git\gitversion_cache\F510DCC39D2A02BB1AC3C0220ACE8EFEA480B50E.yml not found.
  INFO [08/04/23 11:03:41:15] End: Loading version variables from disk cache (Took: 0.67ms)
  INFO [08/04/23 11:03:41:15] Using latest commit on specified branch
  INFO [08/04/23 11:03:41:26] Running against branch: major/another-breaking-change (07432c1 Another class added)
  INFO [08/04/23 11:03:41:26] Begin: Calculating base versions
    INFO [08/04/23 11:03:41:28] Fallback base version: 0.1.0 with commit count source e85a6493e5b92f0e06b92f58c54a908357daf6bd
    INFO [08/04/23 11:03:41:36] Git tag 'v2.6.0': 2.6.0 with commit count source 355209cd88fb264d974cd9810c18ee20d686ff9f
    INFO [08/04/23 11:03:41:36] Git tag 'v2.5.2': 2.5.2 with commit count source 556d066ec0bf9a4c1091708d4d710c3833149d13
    INFO [08/04/23 11:03:41:36] Git tag 'v2.5.1': 2.5.1 with commit count source eabeafeb137b52f0b2a40f5c16d4e80b1d8f7d99
    INFO [08/04/23 11:03:41:36] Git tag 'v2.5.0': 2.5.0 with commit count source 9ac68a1d861ccc72c4432ee95a17ab2d6fb23378
    INFO [08/04/23 11:03:41:36] Git tag 'v2.4.0': 2.4.0 with commit count source 75edf3f9847fa31407581053246676fbfb37b5dc
    INFO [08/04/23 11:03:41:36] Git tag 'v2.3.0': 2.3.0 with commit count source 7a0891ca90aa55daeeaf2023ceae003b406d7c7c
    INFO [08/04/23 11:03:41:36] Git tag 'v2.2.0': 2.2.0 with commit count source 97409df3dc4291fa83ca6fad8f4895ad4b626a7e
    INFO [08/04/23 11:03:41:36] Git tag 'v2.1.0': 2.1.0 with commit count source 6d803b7270556844bc0f8052dbaa6887b374d62e
    INFO [08/04/23 11:03:41:36] Git tag 'v2.1.0-test-new-convention.4': 2.1.0-test-new-convention.4 with commit count source 03f9cbac6ee47bc818a1c6be0f5bb75c31cd5bd6
    INFO [08/04/23 11:03:41:36] Git tag 'v2.0.2': 2.0.2 with commit count source daf33361e4865f6e82438b5083df09d59fa49637
    INFO [08/04/23 11:03:41:36] Git tag 'v2.0.0': 2.0.0 with commit count source 077b31296829146c93d792d92dbadb7c3c20718b
    INFO [08/04/23 11:03:41:36] Git tag 'v1.0.3': 1.0.3 with commit count source 3301bc298fce095fd65a5c2e149c7efd57ec18cc
    INFO [08/04/23 11:03:41:36] Git tag 'v1.1.0-multiply-numbers.4': 1.1.0-multiply-numbers.4 with commit count source 7900eeb95416b37415f194bd7ef36ab670f658c9
    INFO [08/04/23 11:03:41:36] Git tag 'v1.1.0-multiply-numbers.1': 1.1.0-multiply-numbers.1 with commit count source 0033db88c87e52a20afc3d576f284a442ee42058
    INFO [08/04/23 11:03:41:36] Git tag 'v1.0.2': 1.0.2 with commit count source 5059acf026a3652abd6c9f764a7efad36d028b08
    INFO [08/04/23 11:03:41:36] Git tag 'v1.0.1': 1.0.1 with commit count source 475a06cb705c1e510f86e68886527cee6815ea11
    INFO [08/04/23 11:03:41:36] Git tag 'v1.0.0': 1.0.0 with commit count source d275ac4a717053eaa41dfc7b33e4b5ce36c9e70b
    INFO [08/04/23 11:03:41:51] Found multiple base versions which will produce the same SemVer (3.0.0), taking oldest source for commit counting (Git tag 'v2.0.0')
    INFO [08/04/23 11:03:41:51] Base version used: Git tag 'v2.0.0': 2.0.0 with commit count source 077b31296829146c93d792d92dbadb7c3c20718b
  INFO [08/04/23 11:03:41:51] End: Calculating base versions (Took: 245.93ms)
  INFO [08/04/23 11:03:41:51] 32 commits found between 077b312 Merged PR 226950: Absolute implemented +semver: major and 07432c1 Another class added
  INFO [08/04/23 11:03:41:51] Begin: Using mainline development mode to calculate current version
    INFO [08/04/23 11:03:41:52] '^master$|^main$' does not match 'major-add-implemented'.
    INFO [08/04/23 11:03:41:52] '^support[/-]' does not match 'major-add-implemented'.
    INFO [08/04/23 11:03:41:52] '^master$|^main$' does not match 'major/another-breaking-change'.
    INFO [08/04/23 11:03:41:52] '^support[/-]' does not match 'major/another-breaking-change'.
    INFO [08/04/23 11:03:41:52] '^master$|^main$' does not match 'major/very-breaking-change'.
    INFO [08/04/23 11:03:41:52] '^support[/-]' does not match 'major/very-breaking-change'.
    INFO [08/04/23 11:03:41:52] '^master$|^main$' matches 'master'.
    INFO [08/04/23 11:03:41:53] Found merge base 355209cd88fb264d974cd9810c18ee20d686ff9f for 'master'.
    INFO [08/04/23 11:03:41:53] '^master$|^main$' does not match 'minor/test-new-tags'.
    INFO [08/04/23 11:03:41:53] '^support[/-]' does not match 'minor/test-new-tags'.
    INFO [08/04/23 11:03:41:53] '^master$|^main$' does not match 'major-add-implemented'.
    INFO [08/04/23 11:03:41:53] '^support[/-]' does not match 'major-add-implemented'.
    INFO [08/04/23 11:03:41:53] '^master$|^main$' does not match 'major/another-breaking-change'.
    INFO [08/04/23 11:03:41:53] '^support[/-]' does not match 'major/another-breaking-change'.
    INFO [08/04/23 11:03:41:53] '^master$|^main$' does not match 'major/very-breaking-change'.
    INFO [08/04/23 11:03:41:53] '^support[/-]' does not match 'major/very-breaking-change'.
    INFO [08/04/23 11:03:41:53] '^master$|^main$' matches 'master'.
    INFO [08/04/23 11:03:41:53] Found merge base 355209cd88fb264d974cd9810c18ee20d686ff9f for 'origin/master'.
    INFO [08/04/23 11:03:41:53] '^master$|^main$' does not match 'minor/test-new-tags'.
    INFO [08/04/23 11:03:41:53] '^support[/-]' does not match 'minor/test-new-tags'.
    INFO [08/04/23 11:03:41:53] Found possible mainline branches: master, origin/master
    INFO [08/04/23 11:03:41:53] Choosing master as mainline because major/another-breaking-change's merge base was a direct commit to master
    INFO [08/04/23 11:03:41:53] Found branch merge point; choosing 355209c Merged PR 227976: GitVersion.yml removed as effective mainline tip
    INFO [08/04/23 11:03:41:53] Current branch (major/another-breaking-change) was branch from 355209c Merged PR 227976: GitVersion.yml removed
    INFO [08/04/23 11:03:41:54] Direct commit on main 2e9b933 Merged PR 226968: track-merge-target disabled incremented base versions None, now 2.0.0
    INFO [08/04/23 11:03:41:54] Direct commit on main daf3336 Merged PR 226969: Power implemented incremented base versions None, now 2.0.0
    INFO [08/04/23 11:03:41:54] Direct commit on main ca4648e Merged PR 227021: New environment variable and branch naming convention incremented base versions None, now 2.0.0
    INFO [08/04/23 11:03:41:54] Merge commit 54db4f4 Merged PR 227035: New feature to test convention incremented base versions Major, now 3.0.0
    INFO [08/04/23 11:03:41:54] Merge commit f940fee Merged PR 227055: New file added incremented base versions Major, now 4.0.0
    INFO [08/04/23 11:03:41:54] Merge commit 6d803b7 Merge branch 'minor-test-again' incremented base versions Minor, now 4.1.0
    INFO [08/04/23 11:03:41:54] Direct commit on main 3a7edc7 Merged PR 227245: Create GitVersion compatible PR templates per branch according to the convention incremented base versions None, now 4.1.0
    INFO [08/04/23 11:03:41:54] Direct commit on main bea1fb2 Merged PR 227633: Added support for support branches incremented base versions None, now 4.1.0
    INFO [08/04/23 11:03:41:54] Direct commit on main 21a473a Merged PR 227664: Persist git credentials for tagging master incremented base versions None, now 4.1.0
    INFO [08/04/23 11:03:41:54] Direct commit on main 97409df Merged PR 227704: Small feature implemented incremented base versions None, now 4.1.0
    INFO [08/04/23 11:03:41:54] Direct commit on main 7a0891c Merged PR 227726: Some comments added incremented base versions None, now 4.1.0
    INFO [08/04/23 11:03:41:54] Direct commit on main 72ac4fe Bump version in csproj file incremented base versions None, now 4.1.0
    INFO [08/04/23 11:03:41:54] Direct commit on main 65cf314 Merged PR 227727: Cleanup everything incremented base versions None, now 4.1.0
    INFO [08/04/23 11:03:41:54] Direct commit on main 52ccf8b Bump version in csproj file incremented base versions None, now 4.1.0
    INFO [08/04/23 11:03:41:54] Direct commit on main 7a089e6 Merged PR 227780: Run pipeline for every push in feature branches incremented base versions None, now 4.1.0
    INFO [08/04/23 11:03:41:54] Direct commit on main 75edf3f Merged PR 227852: Some changes as usual incremented base versions None, now 4.1.0
    INFO [08/04/23 11:03:41:54] Direct commit on main 9ac68a1 Merged PR 227857: Parallel merge test incremented base versions None, now 4.1.0
    INFO [08/04/23 11:03:41:54] Direct commit on main eabeafe Merged PR 227881: Fixed some stuff incremented base versions None, now 4.1.0
    INFO [08/04/23 11:03:41:54] Direct commit on main 556d066 Merged PR 227880: Fixed some stuff in parallel incremented base versions None, now 4.1.0
    INFO [08/04/23 11:03:41:54] Direct commit on main 355209c Merged PR 227976: GitVersion.yml removed incremented base versions None, now 4.1.0
    INFO [08/04/23 11:03:41:54] 6 commits found between 355209c Merged PR 227976: GitVersion.yml removed and 07432c1 Another class added
    INFO [08/04/23 11:03:41:55] Performing Major increment for current branch 
  INFO [08/04/23 11:03:41:55] End: Using mainline development mode to calculate current version (Took: 34.00ms)
  INFO [08/04/23 11:03:41:55] Using branch name to calculate version tag
  INFO [08/04/23 11:03:41:55] Begin: Getting version tags from branch 'refs/heads/major/another-breaking-change'.
  INFO [08/04/23 11:03:41:56] End: Getting version tags from branch 'refs/heads/major/another-breaking-change'. (Took: 12.50ms)
  INFO [08/04/23 11:03:41:65] Begin: Creating dictionary
  INFO [08/04/23 11:03:41:66] End: Creating dictionary (Took: 3.56ms)
  INFO [08/04/23 11:03:41:66] Begin: Storing version variables to cache file C:\project\.git\gitversion_cache\F510DCC39D2A02BB1AC3C0220ACE8EFEA480B50E.yml
  INFO [08/04/23 11:03:41:68] End: Storing version variables to cache file C:\project\.git\gitversion_cache\F510DCC39D2A02BB1AC3C0220ACE8EFEA480B50E.yml (Took: 24.42ms)
Executing GenerateSetVersionMessage for 'AzurePipelines'.
Executing GenerateBuildLogOutput for 'AzurePipelines'.
  INFO [08/04/23 11:03:41:70] Done writing 
##[section]Async Command Start: Update Build Number
Update build number to 5.0.0-another-breaking-change.6 for build 1000430
##[section]Async Command End: Update Build Number
##[section]Finishing: GitVersion run

Your Environment

Doesn't matter if I do this on my local or in the ADO pipeline, the result is the same.

@HHobeck
Copy link
Contributor

HHobeck commented Aug 5, 2023

Hit there. Please simplify your scenario and provide steps to reproduce. You can do this by e.g.:

  • creating an integration test
  • providing a repository
  • providing git commands

Thank you very much!

@dawidkeshop
Copy link
Author

Hi @HHobeck
Thank you for your response!

I've created a simple repository to reproduce the issue: https://github.com/dawidkeshop/gitversion-tests

This is how the history looks like:
image

And this is what GitVersion is calculating when I'm on major/breaking-change:

PS C:\Code\gitversion-tests\ClassLibrary1> dotnet gitversion /showvariable SemVer
6.0.0-breaking-change.1

@HHobeck HHobeck added this to the 6.x milestone Aug 8, 2023
@dawidkeshop
Copy link
Author

I was trying to implement an integration test for this scenario but I can't find an option to specify merge commit message.
Could you advise?
This is my fork: dawidkeshop@edc900e

Can I display somehow the commits tree, to verify if what I've specified in the test is what I really wanted?

@HHobeck
Copy link
Contributor

HHobeck commented Aug 11, 2023

I have no idea. The libgit2sharp library is limitating here. Maybe try this: libgit2/libgit2sharp#1562

Why do you need custom merge messages for you test scenario? If you do a merg-no-fast-forward the commit message looks like: Merge branch 'release-2.0.0'

@dawidkeshop
Copy link
Author

Hi @HHobeck, sorry for the delay in the response.

I need custom merge messages to simulate my real life scenario with ADO pipeline which uses own merge messages and it's not a matter of configuration.

@arturcic arturcic added stale and removed stale labels Oct 30, 2023
@HHobeck HHobeck linked a pull request Jan 28, 2024 that will close this issue
5 tasks
@HHobeck HHobeck closed this as completed Jan 28, 2024
@arturcic arturcic modified the milestones: 6.x, 6.0.0-beta.6 Mar 9, 2024
@arturcic
Copy link
Member

arturcic commented Mar 9, 2024

🎉 This issue has been resolved in version 6.0.0-beta.6 🎉
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

Successfully merging a pull request may close this issue.

3 participants