Repository navigation
Flag to avoid creating a new commit for the bump #753
Description
Activity
- addedtype: featureA new enhacement proposalA new enhacement proposal
on May 29, 2023 Can you explain a bit more? Would
--files-onlywork for you? https://commitizen-tools.github.io/commitizen/bump/#-files-onlyCommitizen creates a commit because it can update files depending on the version type used, the changelog and files that need to be updated, and all of that end up in the version commit. I wonder how all of that would work if no commit is created.
No --files-only wouldn't work, I do need the tag, but I don't want the extra commit.
My particular use case is a CI workflow that runs on every commit to main. I want to create a tag and do the release but I don't want to push a new commit back to main (and thus retrigger CI. I want the tag to be on the commit that triggered the pipeline.
I know that bump can change files, but if no file changes are actually needed, there should be an option to not create the commit but still create a tag.
I guess for my use case another option would be to do a dry run and get the next version from the output, then create the tag myself, but is there a way to print just the new version of the dry run without anything else so I don't need to parse it? Maybe like a --quiet or --porcelain flag or something
I think you could achieve something like that using the version provider
scm, but I'm seeing some bugs on it.[tool.commitizen] name = "cz_conventional_commits" tag_format = "$version" version_provider = "scm"with changelog off the version in
.cz.tomlis not updated and it fails because there's nothing to commit: https://github.com/commitizen-tools/commitizen/blob/master/commitizen/commands/bump.py#LL319C25-L319C25I'll label this as bug
Reacted by Lucas Vecina and Philip Nelson@Lee-W @noirbizarre do you have any thoughts on this? how should commitizen behave under this circumstance?
the circumstance:
- commitizen reads the version from scm
- changelog is not created and no files are modified
.cz.tomldoesn't change (because the version is read fromscm)
Under those circumstances, running
cz bumpfails.I can only think of 2 possibilities at the moment:
- Should we just create a tag? This is the one I'd like the most.
- Or should we create an empty commit and tag together ? this is the less error prone, as otherwise we'd have to change some behavior here
Reacted by StevenI prefer option 1. Just to clarify, does using "bump" add a tag to the most recent commit in this scenario?
That is (my) the expected behavior. But it's not working atm. If you update the readme or version files, it's creating the bump commit and everything works fine. If you don't modify anything and you try to bump... it fails.
I am currently in the process of deploying this kind of solution on enterprise projects, and it's working damn well. The solution I chose is the following (using
pdmbut should work with any project/package manager supportingscmversioning).I have the following in my
pyproject.toml:[tool.pdm.version] source = "scm" write_to = "<package name>/_version.py" write_template = '__version__ = "{}"' [tool.commitizen] version_provider = "scm"
and the content of
<package name>/_version.pyis:from __future__ import annotations try: import importlib.metadata as importlib_metadata __version__ = importlib_metadata.version("<distrib name>") except (importlib_metadata.PackageNotFoundError, ImportError): __version__ = "0.0.0.dev"
Release is fully automated using a GitHub action workflow like this:
name: Release on: workflow_dispatch: inputs: prerelease: type: choice description: Pre-release type (optional) options: - '' - alpha - beta - rc default: '' required: false increment: type: choice description: Kind of increment (optional) options: - '' - MAJOR - MINOR - PATCH default: '' required: false jobs: release: name: Bump version and create changelog with commitizen runs-on: ubuntu-latest steps: - name: Clone uses: actions/checkout@v3 with: fetch-depth: 0 token: ${{ secrets.RELEASE_TOKEN }} - name: Bump using commitizen uses: commitizen-tools/commitizen-action@master with: github_token: ${{ secrets.RELEASE_TOKEN }} changelog_increment_filename: body.md extra_requirements: <commitizen plugins> prerelease: ${{ github.event.inputs.prerelease }} increment: ${{ github.event.inputs.increment }} - name: Github Release uses: softprops/action-gh-release@v1 with: body_path: "body.md" tag_name: ${{ env.REVISION }} env: GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
This will trigger a
cz bumpwith changelog and then a CI build for the pushed tag.Adding a tag on the last commit is not enough to me because I will have at least a bump commit. The only exception that I know of is when you don't commit versioned files, including changelog.
However, I have one use-case that may require a
--no-commitflag: release candidates: most of the time, the lastrcrelease just become theX.Y.0. I still have to bump committed files, but I need commitizen to accept to produce a changelog without new commits/entries (which is currently failing, but it depends on the changelog rule, if the commits are ignored from changelog, it fails).
But for this case, I would love to be able to drop all RC's entries from changelog to replace with a singleX.Y.0entry.For @abrahammurciano case (you seem to use commitizen only for version detection and tag bump, no file change), the
--no-commitwould be legit, but maybe something simpler would be enough, something like:NEXT_VERSION=`cz next` git tag $NEXT_VERSION git push $NEXT_VERSION
Where
cz nextcommand is simply giving the next expected version according to the rule (the question here is whether it's simpler to have a--no-commitflag or simply a command giving the next version with the same parameters).
This will trigger a CI build for the tag only (but you need to clone and push using a PAT instead of the built-in GitHub provided token)TLDR:
--no-commitmight be necessary, but I wonder if this shouldn't be the default (--no-commitbeing the default and having a flag to enforce new commit between bumps). Lack of new changelog entry while there are new commits in the tree should not prevent a bump (maybe with a fallback entry like "only internal changes" or something like that). For the tag only bump approach, it would solve the issue.(Those are on the fly thinking, I might take some more time to study this case a bit more)
Reacted by Santiago Fraire Willemoes and Reza KhanipourI'm also looking for a
--no-commitoption, for similar reasons to @abrahammurciano. Saving versions into files creates merge conflicts, and in our continuously integrated gitflow process, it generates noise in our commit history. Many build tools support reading the version from the latest git tag on deployment, so writing to a file is increasingly optional.I'm happy to implement this feature if we can agree on the behavior. Some thoughts:
- @noirbizarre 's
cz nextsuggestion would work for me. I may start with since it has fewer strings attached and other use cases. I would add an option to format the version using thetag_formatconfiguration option. e.g.cz next --as-tag - for
cz bumpare there 3 commit scenarios: always, never, and when_dirty? The third case is essentially "commit if there are outstanding changes, but don't require a commit".
Reacted by Steven, Leonid Morozov and Rufina- @noirbizarre 's
I did some testing with the scm provider, trying to use a gitflow branching structure with commitizen and the scm provider. There's a pretty serious bug with the SCM provider which makes it pretty useless as is, but I've made a PR to address that here: #975
For now I'm just parsing the version using
--dry-run:version=$(cz bump --dry-run | grep tag | sed 's/tag to create: \(.*\)/\1/')With my PR and #799 to fix prereelase behavior I have a good POC.
- addedissue-status: wait-for-implementationmaintainers agree on the bug / featuremaintainers agree on the bug / feature
on May 20, 2024 Mark it as wait-for-implementation as it is mentioned in #1073
I ran into this problem today. We really want to work without an additional commit. Unfortunately, this is probably not possible with commitizen.
Reacted by Jon CottonI would love to get this feature out. FWIW. I used these commands to create a new tag:
git tag "v$(cz bump --yes --get-next)" git push --tagsReacted by Philip NelsonTriage from #1964: Confirmed still valid on master (4.15.1). No
--no-commitflag exists inBumpArgs. Suggesting we relabel astype: feature. Implementation outline: skipgit.commit()(and the corresponding error handling incommitizen/commands/bump.pylines 385-394) and tag whatever the user has staged manually.Reacted by EliasI ran into this problem as well - I had assumed that because the
scmprovider is advertised as read-only, it wouldn't require any git changes either.
Description
Since I use git tags to control the version there's no need to create a commit for the new tag when calling bump. Adding the tag to the latest commit would do just fine.
Possible Solution
Adding a flag like --no-commit to not create a commit during the bump, causing the tag to point to the latest existing commit.
Additional context
No response
Additional context
No response