-1

I am very new to Azure DevOps and need help with Azure DevOps pipelines. I am setting up a repository with terraform files.

  • I want to enforce semantic versioning in the repo.
  • I want to automatically bump up the version in main branch (possibly as a part of build pipeline job) when feature branch is merged into it.
  • I want changelog to get updated automatically in main branch

I figured out that we need to have conventional commits enabled to achieve that. I tried to achieve this using pre-commit hook of git-conventional-commits, and then with commitizen but ran into problems related to plugins themselves. Moreover, I was able to achieve enforcement of conventional commits in local but can't force that on remote.

I just want to implement Semantic Versioning in the project and leverage conventional commits to auto bump up the version and auto-generate changelog. Commitizen seems like a good option, but I am facing issues with it in local where it fails to push to remote because older commits do not follow the standard commit convention.

Is there a way(maybe an extension in marketplace) which can help me achieve this?

Update-1: I did not configure anything in local and let all the commits get pushed. Instead, I implemented version update using commitizen only on main branch which means all I need to take care is that no-one commits on main branch, I squash all commits while merging PR and PR title should follow the commit convention.

Update-2: I added a PR validation pipeline to validate the title. But during the PR completion, Azure makes a special merge commit with format '<Merged PR #PR_NUMBER> ', which breaks the conventional commit convention. I am trying to override this commit using api calls but no luck yet.

Shadan
  • 1
  • 2
  • is it helps? https://marketplace.visualstudio.com/items?itemName=kharkevich.ado-semantic-release – Shayki Abramczyk Feb 27 '23 at 08:18
  • @ShaykiAbramczyk It's not exactly what I'm looking for. We've decided not to use any extension as with commitizen, there's always a change to miss the merge using the extension and someone can approve and merge the PR using the PR complete option. That will break the feature. I've updated my post with what we're are doing. – Shadan Mar 14 '23 at 06:46

1 Answers1

-1

You can use counter variable for that:

variables:
  major: 1
  minor: 0
  patch: $[counter(format('{0}.{1}', variables['major'], variables['minor']), 1)]

steps:
  - script: echo "##vso[build.updatebuildnumber]$(major).$(minor).$(patch)

Also you need to enable Tag sources option for your pipeline. By default it will have $(build.buildNumber) value. It will add git tag with build number value after each successful run. enter image description here


when feature branch is merged into it

For that you need to setup CI trigger for you pipeline.

jdfa
  • 659
  • 4
  • 11
  • We do not want to make a decision for the new version while merging the feature branch. Rather, we want the new version to get calculated automatically using the title which is following conventional commit format – Shadan Mar 14 '23 at 06:42