Skip to content

Pre-Bump Scripts do not have access to packages installed before using commitizen-tools/commitizen-action #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
elcharitas opened this issue Sep 14, 2023 · 9 comments

Comments

@elcharitas
Copy link

Background

I have a closed-sample project where I make use of commitizen-action to handle versioning and changelog generation. I make use of .cz.toml's pre_bump_hooks configuration to add shell scripts which should be executed before version bump commit. The idea was to run a couple of cleanups based on the version information.

However, this fails as some external required packages are not made available to the scripts although they were installed in previous steps before commitizen-tools/commitizen-action is used.

Example

release.yml

 tag-and-bump:
    if: ${{ github.ref == 'refs/heads/main' && !startsWith(github.event.head_commit.message, 'bump:') }}
    needs: install-and-test
    runs-on: ubuntu-latest
    name: "Bump version and create changelog with commitizen"
    steps:
      - name: Check out
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
          token: "${{ secrets.GITHUB_TOKEN }}"
      - name: Setup Node
        uses: actions/setup-node@v3
        with:
            node-version: 16
      - name: Install packages
        run: yarn install --immutable
      - id: cz
        name: Bump package
        uses: commitizen-tools/commitizen-action@master
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
      - name: Print Version
        run: echo "Bumped to version ${{ steps.cz.outputs.version }}"

.cz.toml

pre_bump_hooks = [
  "scripts/pre-bump-script.sh"
]

scripts/pre-bump-scripts.sh

node -v

The script above fails with a command node not found

@woile
Copy link
Member

woile commented Sep 14, 2023

Interesting, I'm not sure how to solve this issue. The thing is that the action runs on its own docker image.

@elcharitas
Copy link
Author

Interesting, I'm not sure how to solve this issue. The thing is that the action runs on its own docker image.

That would explain it.

So far, a fix I have found is to install the required packages within the same script however, the workflow takes wayy too long when I do this.

@woile
Copy link
Member

woile commented Sep 15, 2023

Is it a possibility for you to re-write it in python or with coreutils? That's why I'm not a big fan pre_bump_hooks from commitizen.

@elcharitas
Copy link
Author

Is it a possibility for you to re-write it in python or with coreutils? That's why I'm not a big fan pre_bump_hooks from commitizen.

Unfortunately, the scripts aren't portable to python due to tight dependence on the packages.
Is there an alternative to using pre_bump_hooks you can recommend?

@woile
Copy link
Member

woile commented Sep 15, 2023

What is your script doing? I'd consider if the step can be done outside commitizen. Which variables do you use from: https://commitizen-tools.github.io/commitizen/bump/#pre_bump_hooks

@elcharitas
Copy link
Author

elcharitas commented Sep 15, 2023

Which variables do you use from: https://commitizen-tools.github.io/commitizen/bump/#pre_bump_hooks

I only make use of CZ_PRE_NEW_VERSION.

I'd consider if the step can be done outside commitizen.

Thanks for this, I can already see possible ways I can handle the scripts outside commitizen. The only downside is I'd have a chore: cleanup after bump commit after each version bump. But I should be able to live with that 😅

@woile
Copy link
Member

woile commented Sep 15, 2023

You can have a step which installs commitizen with pip install commitizen, then run something like:

cz bump --git-output-to-stderr --dry-run | grep 'tag to create:' | grep -Eo '[0-9].+' > CZ_NEXT_VERSION
cat CZ_NEXT_VERSION

Or directly into a github action variable:

- name: Setup python
   uses: actions/setup-python@v4
   with:
      python-version: '3.x'
- run: pip install -U commitizen
- name: Next version
   id: getnextversion
   run: |
      export NEXT_VERSION=$(cz bump --git-output-to-stderr --dry-run | grep 'tag to create:' | grep -Eo '[0-9].+')
      echo "VERSION=$NEXT_VERSION" >> $GITHUB_OUTPUT
- name: Your NODEJS script
  env:
    CZ_PRE_NEW_VERSION: ${{ steps.getversion.outputs.VERSION }}
  
# HERE the commitizen action

Note: I'm on a MAC so the grep flags might be different

I believe any change done in git will be picked up by commitizen and commit them in the bump commit. If that's not the case, try doing git add <files you changed>, at that point cz bump will definitely pick them up for the cz bump commit generated.

@elcharitas
Copy link
Author

You can have a step which installs commitizen with pip install commitizen, then run something like....

Thanks @woile I'm going to give this a try and let you know how it goes

@elcharitas
Copy link
Author

I'm closing this since my issue has been addressed already by @woile.
Thanks for the help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants