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.
84
+
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.
86
+
87
+
```yaml title=".github/workflows/bumpversion.yml"
88
+
name: Bump version
89
+
90
+
on:
91
+
push:
92
+
branches:
93
+
- master # or 'main' if that's your default branch
You can find the complete workflow in our repository at [bumpversion.yml](https://github.com/commitizen-tools/commitizen/blob/master/.github/workflows/bumpversion.yml).
122
+
71
123
### Publishing a python package
72
124
73
-
Once the new tag is created, triggering an automatic publish command would be desired.
125
+
After a new version tag is created by the bump workflow, you can automatically publish your package to PyPI.
126
+
127
+
#### Step 1: Create a PyPI API token
128
+
129
+
1. Go to [PyPI Account Settings](https://pypi.org/manage/account/)
130
+
2. Scroll to the "API tokens" section
131
+
3. Click "Add API token"
132
+
4. Give it a name (e.g., "GitHub Actions")
133
+
5. Set the scope (project-specific or account-wide)
134
+
6. Click "Add token" and **copy the token immediately**
74
135
75
-
In order to do so, the credential needs to be added with the information of our PyPI account.
136
+
!!! tip "Using API tokens"
137
+
PyPI API tokens are more secure than passwords. Use `__token__` as the username and the token as the password.
76
138
77
-
Instead of using username and password, we suggest using [api token](https://pypi.org/help/#apitoken) generated from PyPI.
139
+
#### Step 2: Add the token as a repository secret
78
140
79
-
After generate api token, use the token as the PyPI password and `__token__` as the username.
141
+
1. Go to your repository on GitHub
142
+
2. Navigate to `Settings > Secrets and variables > Actions`
143
+
3. Click "New repository secret"
144
+
4. Name it `PYPI_PASSWORD`
145
+
5. Paste the PyPI token
146
+
6. Click "Add secret"
80
147
81
-
Go to `Settings > Secrets > Add new secret` and add the secret: `PYPI_PASSWORD`.
148
+
#### Step 3: Create the publish workflow
82
149
83
-
Create a file in `.github/workflows/pythonpublish.yaml` with the following content:
150
+
Create a new file `.github/workflows/pythonpublish.yml` that triggers on tag pushes:
- "*" # Will trigger for every tag, alternative: 'v*'
158
+
- "*" # Will trigger for every tag, alternative: 'v*'
92
159
93
160
jobs:
94
161
deploy:
95
162
runs-on: ubuntu-latest
96
163
steps:
97
-
- uses: actions/checkout@v3
164
+
- uses: actions/checkout@v6
98
165
with:
99
166
fetch-depth: 0
100
167
- name: Set up Python
@@ -118,9 +185,7 @@ jobs:
118
185
run: poetry publish --build
119
186
```
120
187
121
-
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.
188
+
This workflow uses Poetry to build and publish the package. You can find the complete workflow in our repository at [pythonpublish.yml](https://github.com/commitizen-tools/commitizen/blob/master/.github/workflows/pythonpublish.yml).
125
189
126
-
Push the changes and that's it.
190
+
!!! note "Alternative publishing methods"
191
+
You can also use [pypa/gh-action-pypi-publish](https://github.com/pypa/gh-action-pypi-publish) or other build tools like `setuptools`, `flit`, or `hatchling` to publish your package.
0 commit comments