Closed rowley-pete closed 1 year ago
Are you doing a full checkout in the pipeline, or is it just a single commit?
It is a full checkout
Is the changelog coming up empty? I have a similar issue right now. Here's the gist:
0.1.12
main
and anytime the source branch is updated while in the PR. The pipeline:
git fetch
deploy/staging
branch. npx commit-and-tag-version --skip.changelog --skip.tag --prerelease rc
. This bumps the version to 0.2.0-rc.0
. deploy/staging
branch which triggers a deploy to our test environment.git fetch
deploy/production
branch. deploy/production
branch is reset to origin/main
instead of pulling because we have had issues where deleted files kept reappearing after a merge.npx commit-and-tag-version
. This bumps the version to 0.1.13
(!) and the changelog is empty. deploy/production
branch which triggers a deploy to our production environment.This triggers future failures because we upload the builds to aws under the version number. Future PRs keep staging and prod version numbers out of sync.
The worst part is if I pull the branch locally and run the command, the changelog generates normally.
I don't understand why this doesn't work. The only thing I can think of is that it somehow is unable to find the commits in the pipeline, and since conventional-changelog
uses this to come up with the version bump it messes this up somehow. The thing is I don't know why. I am wondering if it's possibly due to me cloning locally using ssh and the pipeline cloning using https? This shouldn't be an issue but I do notice the links are different when I run it locally vs running in the pipeline.
After leaving it for a few weeks and coming back to it prompted by the previous comment I fixed the issue I was having by adding packageFiles property to my .versionrc.json;
{
"releaseCommitMessageFormat": "chore(release): {{currentTag}} [skip ci]",
"bumpFiles": [
{
"filename": "./lib/version.json",
"updater": "./commit-and-tag-updater.js"
}
],
"packageFiles": [
{
"filename": "./lib/version.json",
"updater": "./commit-and-tag-updater.js"
}
]
}
This fixed the issue for me.
Awesome! I'll close this one, please feel free to reopen if there are further problems.
I had the same issue on gitlab and the solution was simple: adding GIT_DEPTH=0
.
By default the runner clones just the last 20 commit messages and if you have more than this, the calculated SemVer wasn't correct. Most likely Azure uses something similar.
Describe the bug I have a gradle project, a build.gradle file, a version.json file, a .versionrc.json file, an azure-pipeline.yml and a commit-and-tag-updater.js file (detailed below). When running the commit-and-tag-version in the azure pipeline it insists on setting the version to 1.0.1 no matter what is in the version.json or tagged on the branch.
Current behavior Using the --dry-run flag locally works as expected but in the pipeline it insists on setting version to 1.0.1 no matter what it was previously, this causes downstream errors when publishing artifiacts.
azure pipeline task output
{ updated: '1.0.1' } { updated: '1.0.2' } ✔ bumping version in ./lib/version.json from 1.0.2 to 1.0.1 ✔ outputting changes to CHANGELOG.md ✔ committing ./lib/version.json and CHANGELOG.md ✔ tagging release v1.0.1 fatal: tag 'v1.0.1' already exists
Expected behavior I would expect it to bump the version from 1.0.2 to 1.0.3 if the commit message is prefixed with fix:
Environment
commit-and-tag-version
version(s): [e.g. v6.0.0, v8.0.0, master]Possible Solution
Additional context
build.gradle fragment
import groovy.json.JsonSlurper plugins { id 'java-library' id 'maven-publish' } task readVersionNumber { def json = new JsonSlurper().parseText(file('./version.json').text) project.version = json.version } jar { dependsOn readVersionNumber }
version.json{ "version": "1.0.2" }
versionrc.json
{ "releaseCommitMessageFormat": "chore(release): {{currentTag}} [skip ci]", "bumpFiles": [ { "filename": "./lib/version.json", "updater": "./commit-and-tag-updater.js" } ] }
azure-pipeline script
- script: | sudo npm install -g commit-and-tag-version git config --global user.email "azure@bot.com" git config --global user.name "azurebot" if [ "$(Build.SourceBranch)" == "refs/heads/main" ]; then commit-and-tag-version else commit-and-tag-version --prerelease alpha fi git push --follow-tags origin HEAD:$(Build.SourceBranchName) displayName: 'Bump version and commit'
commit-and-tag-updater.js
module.exports.readVersion = (contents) => { const updated = JSON.parse(contents).version; console.log({updated}); return updated; } module.exports.writeVersion = (contents, version) => { const json = JSON.parse(contents); json.version = version; return JSON.stringify(json); }