commitizen icon indicating copy to clipboard operation
commitizen copied to clipboard

No tag found to do an incremental changelog

Open 12rambau opened this issue 4 years ago • 16 comments

Description

I want to use commitizen in my repository and automatically bump vresion to pipy (and maybe someday conda-forge). Looking at the documentation I started with github actions that are still not compatible with my repository structure (I have a main branch and I'm working directly on it).

So I wanted to go with the CLI that looks exactly like what i needed:

I created a .cz.yaml file:

commitizen:
  changelog_file: CHANGELOG.md
  changelog_incremental: true
  changelog_start_rev: v0.12.9
  name: cz_conventional_commits
  tag_format: v$major.$minor.$patch$prerelease
  update_changelog_on_bump: true
  version: 0.12.10
  version_files:
  - setup.py:version
  - ost/__init__.py:__version__ 

and did little modifications

Steps to reproduce

When I run cz bump I get the following error message:

No tag found to do an incremental changelog

If I clean the changelog.md file, it works but I then only have the latest tag and not the previous one.

So I changed the .cz.yaml file to bump the changelog in a second step:

update_changelog_on_bump: false

Then the tag is created but running cz changelog end up with the same error message. When I print my tags they are all here even some that I don't want to use:

$ git tag 

0.10.1
0.12.5
0.12.6
0.9.4
v0.12.10
v0.12.7
v0.12.8
v0.12.9

It looks like a chicken & egg problem, what did I miss in my configuration?

Environment

Commitizen Version: 2.20.2 Python Version: 3.8.3 (default, Oct 14 2020, 12:53:46) [Clang 11.0.3 (clang-1103.0.32.29)] Operating System: Darwin

12rambau avatar Dec 17 '21 09:12 12rambau

I cloned your repo, and I think your main issue is the tag_format, which includes a v now. I changed it like this:

-  tag_format: v$major.$minor.$patch$prerelease
+ tag_format: $major.$minor.$patch$prerelease

And then created the missing tag (0.12.9). After that when doing cz bump it works (you still have to create a new commit because there won't be any).

Let me know if this helps, because in your examples there are tags that are not available in the repo you linked.

woile avatar Dec 17 '21 09:12 woile

ok now I wrapped my head around it. I was (naively) thinking that tags were pushed to distant repo but nope. So these tags are only existing on my local creating all sort of isssues (actions not triggered), previous tag not existing etc...

Now that the workflow is clearer to me, it works like a charm. thanks for the guidance !

12rambau avatar Dec 17 '21 11:12 12rambau

Great news! What we usually do is let the github action create the tag and then push back to the repo. Here's the tutorial for github actions: https://commitizen-tools.github.io/commitizen/tutorials/github_actions/

woile avatar Dec 17 '21 12:12 woile

I'm waiting for this issue to be solved as I'm using a main branch

12rambau avatar Dec 17 '21 15:12 12rambau

I'm reopening the issue because it's the exact same problem in another repository. I thought I had understand but it seems I didn't...

So in this repository: https://github.com/12rambau/sepal_ui I wanted to do the exact same thing: create the changelog on bump.

currently I'm not. I tried to add to folowing in my .cz.yaml file:

changelog_incremental: true
update_changelog_on_bump: true

But I'm getting the exact same error:

No tag found to do an incremental changelog

This time I checked my tags and they should all be here with a v_*.*.* value, the last one being v_2.5.3. So what am I missing this time ?

12rambau avatar Jan 11 '22 13:01 12rambau

It works fine on my side. I cloned, run cz bump and the tag created was v_2.5.3 with the changelog.

My conf:

$ cz version
2.17.11

on ubuntu

woile avatar Jan 12 '22 13:01 woile

I think that's because I had manually updated the changelog file. I deleted it on the 2.6.2 release and everything came back to normal

12rambau avatar Mar 28 '22 11:03 12rambau

Sorry to reopen it again but I fail to get it every time I want to use the cz bump command it fails because of the changelog (which the main feature of cz for me). All the solutions I found so far are small patches from my side but I would like to better understand what's behinf this error message.

So still the same old problem, I changed stuff in my repository sepal_ui and on a fresh clone and I run cz bump, result:

bump: version 2.9.4 → 2.10.0
tag to create: v_2.10.0
increment detected: MINOR

No tag found to do an incremental changelog

which is again not working. looking at the tags: the last one is v_2.9.4 which should work. could you clone my repository and simply help me diagnose what's wrong ?

12rambau avatar Jul 18 '22 10:07 12rambau

I digged a bit in the lib and it seems the problem for me is coming from the way commitizen is recognizing tags in the tag list.

https://github.com/commitizen-tools/commitizen/blob/234765d2a580b026217700315194912c8798d059/commitizen/commands/changelog.py#L67

I printed the partial result of the evaluation from my side:

bump: version 2.9.4 → 2.10.0
tag to create: v_2.10.0
increment detected: MINOR

["v_2.9.4: (0.8333333333333334, GitTag('v_2.9.4', 'b01d653a693c700675034e94bdb014cc1ae75afb', '2022-06-09'))"

That's the latest but as .83 < .89 I get an error.

Would it be possible to reduce the value to let's say .8 ? and add my example to the tests ?

12rambau avatar Jul 21 '22 15:07 12rambau

think that would be possible, do you think you could add some extra examples?

woile avatar Jul 21 '22 16:07 woile

I'll look at the test structure to see if I can generate more exotic version convention (vers_, version., v- etc) and check how they behave with the current value

12rambau avatar Jul 21 '22 16:07 12rambau

@Woile if such error could happen, do you think we should make that values configurable 🤔

Lee-W avatar Jul 22 '22 14:07 Lee-W

that would be super difficult for users to guess what is the appropriate value. plus if you decrease the value to much you'll may end up with a result that is not the expected one. IMO that is safer to build the test with exotic version conventions and add one if somebody have a weird idea (like "v_" in my case). It ensures that the value is as high as possible.

12rambau avatar Jul 22 '22 16:07 12rambau

Sounds great! maybe we could list what we have tested, so the next time we want to change the value we'll have a better idea on why we decide to use that value from the very begining

Lee-W avatar Jul 23 '22 02:07 Lee-W

Hi I was trying to run cz bump but it's failing with the same error code. Below is my pyproject.toml file

[tool]
[tool.commitizen]
name = "cz_conventional_commits"
version = "0.0.1"
tag_format = "v$major.$minor.$patch$prerelease"

Also, I'm not setting any git tags, just trying to use cz directly as a PoC for our CI/CD process. Can anyone suggest, what shall I do?

souravjamwal77 avatar Aug 01 '22 08:08 souravjamwal77

@souravjamwal77 May I know what was the commit types (e.g., feat, fix)? If there's only ci, doc and etc., commitizen won't bump the version. This is the default bump_map https://github.com/commitizen-tools/commitizen/blob/85d9939965befeb572403f32ebb27fd391ed783f/commitizen/defaults.py#L73

Lee-W avatar Aug 02 '22 13:08 Lee-W

@Lee-W, I will have the time to work on this in the next 2 weeks, where would you like me to write the tests and is there already an example where you create a fake changelog with a normal version tree (to get some inspiration) ?

12rambau avatar Jan 15 '23 17:01 12rambau

@12rambau Is this something you're looking for? https://github.com/commitizen-tools/commitizen/blob/master/tests/test_changelog.py#L516

Lee-W avatar Jan 18 '23 15:01 Lee-W

I'm having the same issue, but only on Github actions.. Doing CZ bump locally seems to work, but using the github actions setup always seems to yield:

 cz --no-raise 21 bump --yes --changelog --check-consistency --changelog-to-stdout >CHANGELOG.md
bump: version 0.1.0 → 0.1.1
tag to create: 0.1.1
increment detected: PATCH

No tag found to do an incremental changelog

Can someone take a look at my repo and settings to see why this might be? link I've tried setting the tag format both with and without a v, but nothing seems to fix it.

-- EDIT I found a fix for my case (which was more a github CI yml issue than the issues listed here, but threw the same error message), I had changed the "body.md" file in the example yml, because i thought it should be the name of your changelog, but that's not the case. changing back to body.md fixed it. I also had to add a permissions:write setting in the yml file to properly push the new release, otherwise the bump occurred in github ci but not the release.

mmorley0395 avatar Apr 12 '23 15:04 mmorley0395

I've updated the docs for github actions. I think this issue shouldn't be happening anymore.

Try using latest actions/checkout@v3 and latest commitizen

woile avatar Apr 28 '23 13:04 woile

I had changed from body.md to CHANGELOG.md, and I am still getting this error using the Github action.

Settings:

[tool.commitizen]
name = "cz_conventional_commits"
version = "0.1.8"
tag_format = "v$version"
update_changelog_on_bump = true
annoted_tag = true
major_version_zero = true
version_files = [
    "pyproject.toml:^version",
    "./src/humbl-data/__version__.py"
]

Github Action:

name: Bump version

on:
  push:
    branches:
      - master

permissions:
  contents: write

jobs:
  bump-version:
    if: "!startsWith(github.event.head_commit.message, 'bump:')"
    runs-on: ubuntu-latest
    name: "Bump version and create changelog with commitizen"
    steps:
      - name: Check out
        uses: actions/checkout@v3
        with:
          token: "${{ secrets.PERSONAL_ACCESS_TOKEN }}"
          fetch-depth: 0
      - name: Create bump and changelog
        uses: commitizen-tools/commitizen-action@master
        with:
          github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
          changelog_increment_filename: CHANGELOG.md
      - name: Release
        uses: softprops/action-gh-release@v1
        with:
          name: humbl-data v${{ env.REVISION }}
          body_path: "CHANGELOG.md"
          tag_name: v${{ env.REVISION }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
name: Bump version

on:
  push:
    branches:
      - master

permissions:
  contents: write

jobs:
  bump-version:
    if: "!startsWith(github.event.head_commit.message, 'bump:')"
    runs-on: ubuntu-latest
    name: "Bump version and create changelog with commitizen"
    steps:
      - name: Check out
        uses: actions/checkout@v3
        with:
          token: "${{ secrets.PERSONAL_ACCESS_TOKEN }}"
          fetch-depth: 0
      - name: Create bump and changelog
        uses: commitizen-tools/commitizen-action@master
        with:
          github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
          changelog_increment_filename: CHANGELOG.md
      - name: Release
        uses: softprops/action-gh-release@v1
        with:
          name: humbl-data v${{ env.REVISION }}
          body_path: "CHANGELOG.md"
          tag_name: v${{ env.REVISION }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}name: Bump version

on:
  push:
    branches:
      - master

permissions:
  contents: write

jobs:
  bump-version:
    if: "!startsWith(github.event.head_commit.message, 'bump:')"
    runs-on: ubuntu-latest
    name: "Bump version and create changelog with commitizen"
    steps:
      - name: Check out
        uses: actions/checkout@v3
        with:
          token: "${{ secrets.PERSONAL_ACCESS_TOKEN }}"
          fetch-depth: 0
      - name: Create bump and changelog
        uses: commitizen-tools/commitizen-action@master
        with:
          github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
          changelog_increment_filename: CHANGELOG.md
      - name: Release
        uses: softprops/action-gh-release@v1
        with:
          name: humbl-data v${{ env.REVISION }}
          body_path: "CHANGELOG.md"
          tag_name: v${{ env.REVISION }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}name: Bump version

on:
  push:
    branches:
      - master

permissions:
  contents: write

jobs:
  bump-version:
    if: "!startsWith(github.event.head_commit.message, 'bump:')"
    runs-on: ubuntu-latest
    name: "Bump version and create changelog with commitizen"
    steps:
      - name: Check out
        uses: actions/checkout@v3
        with:
          token: "${{ secrets.PERSONAL_ACCESS_TOKEN }}"
          fetch-depth: 0
      - name: Create bump and changelog
        uses: commitizen-tools/commitizen-action@master
        with:
          github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
          changelog_increment_filename: CHANGELOG.md
      - name: Release
        uses: softprops/action-gh-release@v1
        with:
          name: humbl-data v${{ env.REVISION }}
          body_path: "CHANGELOG.md"
          tag_name: v${{ env.REVISION }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Everything works fine if I comment out changelog_increment_filename: CHANGELOG.md. I just want the newest changes to be shown for each release, ie incremental?

jjfantini avatar Sep 26 '23 15:09 jjfantini

switching to body.md for both instances fixes the issue

jjfantini avatar Sep 26 '23 15:09 jjfantini