'GitLab CI/CD for Commitizen Bump and Changelog
Background
With Conventional Commits, commitizen, and pre-commit, one can enforce a standard rule for commit message and ensure they are properly formatted. Using Conventional Commits (or at least style-enforced commit messages):
- You can use services like GitHub's
dependabotto automatically tag PRs and run specific checks (or with a script that parses the commit message) commitizenitself can bump the version of the code base (cz bump) per semantic versioning, and you can even set aCHANGELOG.md(keep a changelog) and tag to be generated on every bump, eg. in yourpyproject.toml
[tool.commitizen]
update_changelog_on_bump = true
annotated_tag = true
Question
I write python (version 3.8, Windows) and store my versions in my pyproject.toml and mypkg/__version__.py files (FYI, my primary branch is called main (reference this article)).
I want commitizen to handle my versioning and CHANGELOG.md automatically. How can I perform the following?:
- Upon successful merge from merge request (MR) branch into
main
- Run
cz bump --changelog --annotated-tag, but rather than create a separate merge commit forbumpversion x.y.z -> a.b.c, amend the merge commit with the updated changelog and tag
Attempt
I have tried the following in my gitlab-ci.yml:
deploy_job:
stage: deploy
rules:
- if: $CI_PIPELINE_SOURCE == "push"
- if: $CI_BUILD_REF_NAME == "main"
before_script:
- git remote set-url origin "https://path/to/repo.git"
- git config --global user.email "${GITLAB_USER_EMAIL}"
- git config --global user.name "${GITLAB_USER_NAME}"
- git checkout main
script:
- git cz bump
- git push -o ci.skip --tags
but I can't seem to get it to work after the merge has taken place and I don't know how to bump my version without creating a separate commit.
Research
I found these useful:
- Commitizen > Tutorials > GitLab CI
- Automatic Software Version Bump Using GitLab CI/CD
- GitLab CI bump Python package version
- Automation of releases with gitlab CI
- What is the standard way of version bumping from gitlab CI? A few questions
- Automatic Semantic Versioning in GitLab CI
I have also looked at the following:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
