-
Hi, We create our features on feature/* branches and we make Pull Requests on Azure DevOps to merge them on dev branch. On the PR, we have a template that suggest to choose between Fix, Minor or Major. Selecting one of the options will trigger the corresponding commit This is the template : ## Type of update
- [ ] Fix
- [ ] Feature
- [ ] Major Change This is the build validation pipeline : trigger:
- none
pool:
vmImage: ubuntu-latest
## Job to calculate semantic version
jobs:
- job: CalculateVersion
displayName: Semantic versioning
steps:
# Checkout with persist credentials
- checkout: self
fetchDepth: 0
persistCredentials: true
# Install GitVersion
- task: gitversion/setup@0
displayName: Install GitVersion
inputs:
versionSpec: '5.x'
# Retrieve Pull Request Description
- task: PullRequestDescription@0
name: RetrievePullRequestDescription
displayName: Retrieve Pull Request description
inputs:
action: 'view'
outputVariable: 'PullRequest.DescriptionContent'
isOutput: true
stripIdentifiers: false
# Add git commit message that will be picked up by GitVersion ("+semver: patch/minor/major")
# Depending on the Pull Request description, where the developer has marked the type of change
- task: PowerShell@2
displayName: Add git commit message for SemVer
inputs:
targetType: inline
script: |
Write-Host "Configuring git author info.." -ForegroundColor Cyan
git config user.email "Azure DevOps pipeline"
git config user.name "[email protected]"
Write-Host "Doing git checkout..." -ForegroundColor Cyan
git checkout -b $("$(System.PullRequest.SourceBranch)".replace('refs/heads/', ''))
Write-Host "Checking Pull Request description..." -ForegroundColor Cyan
$PRdesc = "$(RetrievePullRequestDescription.PullRequest.DescriptionContent)"
if ($PRdesc -match '(\[x\] \bFix\b)') {
Write-Host "Adding git (empty) commit message to mark this branch as a 'patch' SemVer increment." -ForegroundColor Cyan
git commit -a -m "+semver: patch [skip azurepipelines]" --allow-empty
} elseif ($PRdesc -match '(\[x\] \bFeature\b)') {
Write-Host "Adding git (empty) commit message to mark this branch as a 'minor' SemVer increment." -ForegroundColor Cyan
git commit -a -m "+semver: minor [skip azurepipelines]" --allow-empty
} elseif ($PRdesc -match '(\[x\] \bMajor Change\b)') {
Write-Host "Adding git (empty) commit message to mark this branch as a 'major' SemVer increment." -ForegroundColor Cyan
git commit -a -m "+semver: major [skip azurepipelines]" --allow-empty
} else {
Write-Host "##vso[task.LogIssue type=error;]Please select the type of change in the Pull Request description, and Re-queue the validation." -ForegroundColor Cyan
$PRdesc
exit 1
}
Write-Host "Doing git push.." -ForegroundColor Cyan
git push -f --set-upstream origin $("$(System.PullRequest.SourceBranch)".replace('refs/heads/', ''))
Write-Host "Done." -ForegroundColor Cyan
# Determine the semantic version
- task: gitversion/execute@0
displayName: Determine SemVer
inputs:
useConfigFile: True
configFilePath: ".azuredevops/gitversion.yml"
updateAssemblyInfo: true When merge is done, we tag version on dev based on the semver. Question: Currently, every merge of feature/* into dev branch will increment (minor, major or patch, according to the checked box in the Pull Request's description) based on the last version of main. How can we make it increment based on the last version made on the dev branch instead ? Thank you in advance for your help :) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi there. First of all I would like to ask you: Which version of git version are you using? From the workflow scenario it seems to me like your develop branch is your main and your main is a archive branch. When merging the version from develop to main you can use the following feature to detect the version automatically (in archive branch):
See issue: #3052 Happy branching. |
Beta Was this translation helpful? Give feedback.
Hi there.
First of all I would like to ask you: Which version of git version are you using? From the workflow scenario it seems to me like your develop branch is your main and your main is a archive branch. When merging the version from develop to main you can use the following feature to detect the version automatically (in archive branch):
See issue: #3052
Happy branching.