You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This guide shows you how to automatically bump versions, create changelogs, and publish releases using Commitizen in GitHub Actions.
4
4
5
-
To execute `cz bump` in your CI, and push the new commit and
6
-
the new tag, back to your master branch, we have to:
5
+
### Prerequisites
7
6
8
-
1. Create a personal access token. [Follow the instructions here](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line#creating-a-token). And copy the generated key
9
-
2. Create a secret called `PERSONAL_ACCESS_TOKEN`, with the copied key, by going to your
10
-
project repository and then `Settings > Secrets > Add new secret`.
11
-
3. In your repository create a new file `.github/workflows/bumpversion.yml`
12
-
with the following content.
7
+
Before setting up the workflow, you'll need:
13
8
14
-
!!! warning
15
-
If you use `GITHUB_TOKEN` instead of `PERSONAL_ACCESS_TOKEN`, the job won't trigger another workflow. It's like using `[skip ci]` in other CI's.
9
+
1. A personal access token with repository write permissions
10
+
2. Commitizen configured in your project (see [configuration documentation](../config/configuration_file.md))
16
11
17
-
```yaml
12
+
### Automatic version bumping
13
+
14
+
To automatically execute `cz bump` in your CI and push the new commit and tag back to your repository, follow these steps:
15
+
16
+
#### Step 1: Create a personal access token
17
+
18
+
1. Go to [GitHub Settings > Developer settings > Personal access tokens](https://github.com/settings/tokens)
19
+
2. Click "Generate new token (classic)"
20
+
3. Give it a descriptive name (e.g., "Commitizen CI")
21
+
4. Select the `repo` scope to grant full repository access
22
+
5. Click "Generate token" and **copy the token immediately** (you won't be able to see it again)
23
+
24
+
!!! warning "Important: Use Personal Access Token, not GITHUB_TOKEN"
25
+
If you use `GITHUB_TOKEN` instead of `PERSONAL_ACCESS_TOKEN`, the workflow won't trigger another workflow run. This is a GitHub security feature to prevent infinite loops. The `GITHUB_TOKEN` is treated like using `[skip ci]` in other CI systems.
26
+
27
+
#### Step 2: Add the token as a repository secret
28
+
29
+
1. Go to your repository on GitHub
30
+
2. Navigate to `Settings > Secrets and variables > Actions`
31
+
3. Click "New repository secret"
32
+
4. Name it `PERSONAL_ACCESS_TOKEN`
33
+
5. Paste the token you copied in Step 1
34
+
6. Click "Add secret"
35
+
36
+
#### Step 3: Create the workflow file
37
+
38
+
Create a new file `.github/workflows/bumpversion.yml` in your repository with the following content:
39
+
40
+
```yaml title=".github/workflows/bumpversion.yml"
18
41
name: Bump version
19
42
20
43
on:
21
44
push:
22
45
branches:
23
-
- master
46
+
- master# or 'main' if that's your default branch
24
47
25
48
jobs:
26
49
bump-version:
@@ -29,7 +52,7 @@ jobs:
29
52
name: "Bump version and create changelog with commitizen"
To automatically create a GitHub release when a new version is bumped, you can extend the workflow above.
70
84
71
-
### Publishing a python package
85
+
The `commitizen-action` creates an environment variable called `REVISION` containing the newly created version. You can use this to create a release with the changelog content.
72
86
73
-
Once the new tag is created, triggering an automatic publish command would be desired.
87
+
```yaml title=".github/workflows/bumpversion.yml"
88
+
name: Bump version
74
89
75
-
In order to do so, the credential needs to be added with the information of our PyPI account.
90
+
on:
91
+
push:
92
+
branches:
93
+
- master # or 'main' if that's your default branch
76
94
77
-
Instead of using username and password, we suggest using [api token](https://pypi.org/help/#apitoken) generated from PyPI.
After generate api token, use the token as the PyPI password and `__token__` as the username.
121
+
You can find the complete workflow in our repository at [bumpversion.yml](https://github.com/commitizen-tools/commitizen/blob/master/.github/workflows/bumpversion.yml).
80
122
81
-
Go to `Settings > Secrets > Add new secret` and add the secret: `PYPI_PASSWORD`.
123
+
### Publishing a Python package
82
124
83
-
Create a file in `.github/workflows/pythonpublish.yaml` with the following content:
125
+
After a new version tag is created, you can automatically publish your package to PyPI (or other package registries).
Notice that we are using poetry to publish the package.
122
-
123
-
124
-
You can also use [pypa/gh-action-pypi-publish](https://github.com/pypa/gh-action-pypi-publish) to publish your package.
125
-
126
-
Push the changes and that's it.
154
+
You can find the complete workflow in our repository at [pythonpublish.yml](https://github.com/commitizen-tools/commitizen/blob/master/.github/workflows/pythonpublish.yml).
0 commit comments