| 1 |
# Releasing with the SCM Version Provider |
| 2 |
|
| 3 |
In this tutorial, you will learn how to bump the version using the `scp` version provider; as you can't use `cz bump`. |
| 4 |
|
| 5 |
## About |
| 6 |
|
| 7 |
When `version_provider` is set to `scm`, Commitizen reads the version directly from your Git tags instead of a config file. |
| 8 |
This provider is **read-only**: it can determine the current version, but it cannot write a new one for you. |
| 9 |
|
| 10 |
```toml title=".cz.toml" |
| 11 |
[tool.commitizen] |
| 12 |
tag_format = "v${version}" |
| 13 |
version_provider = "scm" |
| 14 |
``` |
| 15 |
|
| 16 |
This means `cz bump` cannot complete its usual job of writing the new version anywhere (see [Why can't I bump with SCM?](#why-cant-i-bump-with-scm) below). In the next section, you will learn how to do it anyways. |
| 17 |
|
| 18 |
## Creating a New Version Tag Manually |
| 19 |
|
| 20 |
To release a new version without an extra commit and using tags, |
| 21 |
you can compute the next tag using `cz version` and then, you can manually create the tag directly. |
| 22 |
|
| 23 |
In this example, we create an annotated tag with the changelog as the tag message, using just `git`. |
| 24 |
|
| 25 |
```sh |
| 26 |
next_version=$(cz version --project --next --tag) |
| 27 |
cz changelog --incremental --dry-run --unreleased-version "$next_version" > .changelog.md |
| 28 |
git tag --annotate "$next_version" -F .changelog.md |
| 29 |
git push --follow-tags |
| 30 |
``` |
| 31 |
|
| 32 |
!!! tip |
| 33 |
Wrap this in a CI job to fully automate releases when using the `scm` provider using [setup-cz](https://github.com/commitizen-tools/setup-cz) |
| 34 |
|
| 35 |
## GitHub Action Example |
| 36 |
|
| 37 |
```yaml title=".github/workflows/bump-version.yml" |
| 38 |
name: Bump version |
| 39 |
|
| 40 |
on: |
| 41 |
push: |
| 42 |
branches: |
| 43 |
- main |
| 44 |
|
| 45 |
jobs: |
| 46 |
bump: |
| 47 |
runs-on: ubuntu-latest |
| 48 |
permissions: |
| 49 |
contents: write |
| 50 |
actions: write |
| 51 |
steps: |
| 52 |
- uses: actions/checkout@v7 |
| 53 |
with: |
| 54 |
token: "${{ secrets.PERSONAL_ACCESS_TOKEN }}" |
| 55 |
fetch-depth: 0 |
| 56 |
fetch-tags: true |
| 57 |
- uses: commitizen-tools/setup-cz@main |
| 58 |
with: |
| 59 |
python-version: "3.x" |
| 60 |
- id: bump-version |
| 61 |
run: | |
| 62 |
next_version=$(cz version --project --next --tag) |
| 63 |
cz changelog --incremental --dry-run --unreleased-version "$next_version" > .changelog.md |
| 64 |
git tag --annotate "$next_version" -F .changelog.md |
| 65 |
git push --follow-tags |
| 66 |
``` |
| 67 |
|
| 68 |
## Why Can't I Bump with SCM? |
| 69 |
|
| 70 |
When you run `cz bump`, Commitizen normally creates a new commit that updates the version somewhere, |
| 71 |
either in `.cz.toml`, or in `pyproject.toml` if you're using Python, or `Cargo.toml` for rust. |
| 72 |
It may also update `version_files` and regenerate `CHANGELOG.md`. |
| 73 |
|
| 74 |
Commitizen deliberately bundles a new release into a single "release commit". |
| 75 |
|
| 76 |
This is core to its philosophy: the version should live in the code itself, not only in a Git tag, |
| 77 |
so anyone can read the current version straight from the source, without needing to inspect the tags. |
| 78 |
|
| 79 |
When a Git tag is the sole source of truth, that guarantee disappears, |
| 80 |
the version becomes metadata layered on top of your history instead of something visible within the code itself. |
| 81 |
|
| 82 |
Nonetheless, you can still do it. |