commitizen-tools / commitizen

Create committing rules for projects :rocket: auto bump versions :arrow_up: and auto changelog generation :open_file_folder:
https://commitizen-tools.github.io/commitizen/
MIT License
2.36k stars 257 forks source link

lightweight tags create no "create event" in github actions #271

Closed diefans closed 3 years ago

diefans commented 3 years ago

Description

Commitizen creates only lightweight tags, which are not creating a "create event" in github actions.

Steps to reproduce

https://github.com/commitizen-tools/commitizen/blob/master/commitizen/git.py#L49

Current behavior

A lightweight tag created by commitizen does not lead to a usefull event in github actions.

Desired behavior

Create an annotated tag, e.g. git tag -a <version> -m <version>. This should be at least a configurable option IMHO.

Environment

woile commented 3 years ago

thanks for the finding! some questions, how did you find this problem? could you point the GA documentation where they mention lightweight tag don't create events? I couldn't find it.

I'll run some tests in to verify it as well :muscle:

diefans commented 3 years ago

I have no documentation at hand. But as far as I know, lightweight tags are not "real" objects in git and have also no creation date. You can see this via git for-each-ref where the objecttype of a lightweight tag is commit and for an annotated tag it is tag (also find this in my unit test). So basically I found this by trying github actions to do something after tag creation (see https://docs.github.com/en/actions/reference/events-that-trigger-workflows#create), but there was no event triggered after commitizen created the "tag". So I just created a dummy annotated tag and my workflow was running - so I came to that conclusion....

Lee-W commented 3 years ago

We use the following syntax to detect release which might be the reason why we did not encounter such problem.

on:
  push:
    tags:
      - 'v*'

But I think it's a feature we could have. Thanks for great work 🙂 I'll also run some test to verify it.

diefans commented 3 years ago

@Lee-W I do not really understand how this is working for you: I have a job running basically the example in your docs:

  bump-version:
    if: github.ref == 'refs/heads/master'
    runs-on: ubuntu-latest
    name: "Bump version and create changelog with commitizen"
    needs:
      - build
    steps:
      - name: Check out
        uses: actions/checkout@v2
        with:
          token: '${{ secrets.GITHUB_TOKEN }}'
          fetch-depth: 0
      - name: Create bump and changelog
        uses: commitizen-tools/commitizen-action@master
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}

The job appears to work fine:

Configuring git user and email...
Runnung cz...
bump: version 0.2.1 → 0.2.2
tag to create: 0.2.2
increment detected: PATCH

Done!
Pushing to branch...
To https://github.com/*/*.git
   f76d488..8bdc82d  HEAD -> master
 * [new tag]         0.2.2 -> 0.2.2
Done.

I also have a debug workflow:

name: debug
on:
  push:
    tags:
      - "*"
  create:

jobs:
  debug:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - run: echo ${{ github.ref }}
      - run: echo ${{ toJSON(github.event) }}

but this gets never triggered after the "tag" is "pushed" via the bump-version job.

woile commented 3 years ago

secrets.GITHUB_TOKEN won't trigger another workflow. It's like using [skip ci] in other CI's.

You have to use a personal token like here: https://github.com/commitizen-tools/commitizen/blob/master/.github/workflows/bumpversion.yml

I asked the same in the github action discussion board: https://github.community/t/action-does-not-trigger-another-on-push-tag-action/17148/2

Note: for some reason your PERSONAL_TOKEN must be provided to the checkout step :man_shrugging:

I think in our case (commitizen) that's why it was failing. Now we are waiting for next release :crossed_fingers: hahahha

diefans commented 3 years ago

@Woile this explains a lot...

woile commented 3 years ago

Yeah I lost a few hairs dealing with it.

The documentation explains how to add a PERSONAL TOKEN, I think we should mention why though.

https://commitizen-tools.github.io/commitizen/tutorials/github_actions/