Skip to content

Commit 83c88e2

Browse files
authored
Merge pull request #1 from commitizen-tools/feat/add-new-action
feat(ci): introduce new setup-cz action
2 parents 482c4c4 + a2097d3 commit 83c88e2

File tree

9 files changed

+348
-1
lines changed

9 files changed

+348
-1
lines changed

.cz.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
commitizen:
3+
major_version_zero: true
4+
name: cz_conventional_commits
5+
tag_format: v$version
6+
update_changelog_on_bump: true
7+
version: 0.0.1
8+
version_scheme: semver2
9+
annotated_tag: true

.github/workflows/bump.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
6+
jobs:
7+
bump:
8+
runs-on: ubuntu-latest
9+
permissions:
10+
contents: write
11+
actions: write
12+
steps:
13+
- uses: actions/checkout@v5
14+
with:
15+
fetch-depth: 0
16+
fetch-tags: true
17+
- name: Set up git config
18+
run: |
19+
git config --global user.name "github-actions[bot]"
20+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
21+
- uses: actions/setup-cz@main
22+
- uses: pndurette/gh-actions-auto-docs@v1
23+
with:
24+
git_push: false
25+
- id: bump-version
26+
run: |
27+
cz bump --yes
28+
current_version="v$(cz version -p --current)"
29+
major_version="v$(cz version -p --major)"
30+
echo "current_version=$current_version" >> $GITHUB_OUTPUT
31+
echo "major_version=$major_version" >> $GITHUB_OUTPUT
32+
- name: Update major tag
33+
env:
34+
CURRENT_VERSION: ${{ steps.bump-version.outputs.current_version }}
35+
MAJOR_VERSION: ${{ steps.bump-version.outputs.major_version }}
36+
run: |
37+
# Push new commit + new tag
38+
git push --follow-tags
39+
40+
# Move major tag to the latest commit
41+
git tag -fa "${MAJOR_VERSION}" -m "release ${CURRENT_VERSION}"
42+
43+
# Force push new major tag
44+
git push origin "${MAJOR_VERSION}" -f
45+
- name: Build changelog
46+
env:
47+
CURRENT_VERSION: ${{ steps.bump-version.outputs.current_version }}
48+
run: |
49+
cz changelog --dry-run "${CURRENT_VERSION}" > .changelog.md
50+
- name: Release
51+
uses: softprops/action-gh-release@v2
52+
with:
53+
body_path: ".changelog.md"
54+
tag_name: ${{ steps.bump-version.outputs.current_version }}
55+
env:
56+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yaml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
test-installs:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v5
13+
- uses: ./
14+
- name: Test it was installed
15+
run: |
16+
cz version
17+
test-version:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v5
21+
- uses: ./
22+
with:
23+
version: 4.0.0
24+
- name: Test version matches
25+
uses: actions/github-script@v8
26+
with:
27+
script: |
28+
const assert = require('node:assert/strict');
29+
const czVersion = await exec.getExecOutput('cz', ['version']);
30+
const expectedVersion = '4.0.0';
31+
assert.equal(czVersion.stdout.trim(), expectedVersion);
32+
test-extra-requirements:
33+
strategy:
34+
matrix:
35+
extra_requirements:
36+
- pip_name: cz-conventional-gitmoji
37+
cz_name: cz_gitmoji
38+
- pip_name: cz-kpn
39+
cz_name: cz_kpn
40+
- pip_name: cz-kpn cz-conventional-gitmoji==0.7.0
41+
cz_name: cz_kpn
42+
runs-on: ubuntu-latest
43+
steps:
44+
- uses: actions/checkout@v5
45+
- uses: ./
46+
with:
47+
extra_requirements: ${{ matrix.extra_requirements.pip_name }}
48+
- name: Test extra requirements were installed
49+
uses: actions/github-script@v8
50+
env:
51+
EXTRA_REQUIREMENTS: ${{ matrix.extra_requirements.cz_name }}
52+
with:
53+
script: |
54+
const assert = require('node:assert/strict');
55+
const extraRequirements = process.env.EXTRA_REQUIREMENTS;
56+
const czList = await exec.getExecOutput('cz', ['ls']);
57+
const allItems = czList.stdout.trim().split('\n');
58+
const result = allItems.includes(extraRequirements);
59+
assert.ok(result, `Expected ${extraRequirements} to be included in the list of installed cz plugins, but it was not.`);

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[codz]
4+
*$py.class
5+
6+
# nix
7+
.direnv
8+
result
9+
.envrc
10+
11+
# python
12+
.venv/
13+
venv/

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,31 @@
11
# setup-cz
2-
Github action to configure cz
2+
3+
> Github action to only configure cz CLI
4+
5+
## Usage
6+
7+
```yaml
8+
jobs:
9+
bump:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
actions: write
14+
steps:
15+
- uses: actions/checkout@v5
16+
with:
17+
fetch-depth: 0
18+
fetch-tags: true
19+
- uses: actions/setup-cz@main
20+
- name: Set up git config
21+
run: |
22+
git config --global user.name "github-actions[bot]"
23+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
24+
- run: |
25+
cz version -p
26+
cz bump --yes --annotated-tag
27+
git push --follow-tags
28+
```
29+
30+
<!--doc_begin-->
31+
<!--doc_end-->

action.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Setup commitizen CLI
2+
description: |
3+
This workflow sets up the commitizen CLI for use in your GitHub workflows.
4+
Unlike `commitizen-action`, this workflow only installs the CLI.
5+
It does not automatically bump, commit or push changes.
6+
This workflow, instead, gives more flexibility to the user by letting them
7+
use the full range of commitizen commands.
8+
9+
inputs:
10+
version:
11+
description: "Version of commitizen to install"
12+
required: false
13+
default: "latest"
14+
extra_requirements:
15+
description: "Install extra dependencies"
16+
required: false
17+
18+
runs:
19+
using: "composite"
20+
steps:
21+
- uses: actions/setup-python@v6
22+
- id: set-vars
23+
shell: python
24+
env:
25+
COMMITIZEN_VERSION: ${{ inputs.version }}
26+
run: |
27+
import os
28+
commitizen_version = os.environ.get("COMMITIZEN_VERSION", "").strip()
29+
if commitizen_version == "latest":
30+
set_commitizen_version = ""
31+
else:
32+
set_commitizen_version = f"=={commitizen_version}"
33+
with open(os.environ["GITHUB_OUTPUT"], "a") as fh:
34+
fh.write(f"COMMITIZEN_VERSION={set_commitizen_version}\n")
35+
- name: Install commitizen
36+
shell: bash
37+
env:
38+
COMMITIZEN_VERSION: ${{ steps.set-vars.outputs.COMMITIZEN_VERSION }}
39+
EXTRA_REQUIREMENTS: ${{ inputs.extra_requirements }}
40+
run: |
41+
pip install -U commitizen${COMMITIZEN_VERSION} ${EXTRA_REQUIREMENTS}

examples/bump-release.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# YES, YOU CAN COPY-PASTE THIS ACTION AND IT SHOULD WORK
2+
# keep in mind, that it won't trigger other actions because it's using action permissions.
3+
# You can: use a PAT token or a workflow_call to trigger another action
4+
on:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
bump:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
14+
actions: write
15+
steps:
16+
- uses: actions/checkout@v5
17+
with:
18+
fetch-depth: 0
19+
fetch-tags: true
20+
- name: Set up git config
21+
run: |
22+
git config --global user.name "github-actions[bot]"
23+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
24+
- uses: actions/setup-cz@main
25+
- id: bump-version
26+
run: |
27+
cz bump --yes --annotated-tag
28+
git push --follow-tags
29+
current_version="$(cz version -p --current)" # ATTENTION: You may have to add the v* at the beginning of the version
30+
echo "current_version=$current_version" >> $GITHUB_OUTPUT
31+
- name: Build changelog for Release
32+
env:
33+
CURRENT_VERSION: ${{ steps.bump-version.outputs.current_version }}
34+
run: |
35+
cz changelog --dry-run "${CURRENT_VERSION}" > .changelog.md
36+
- name: Release
37+
uses: softprops/action-gh-release@v2
38+
with:
39+
body_path: ".changelog.md"
40+
tag_name: ${{ steps.bump-version.outputs.current_version }}
41+
env:
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

flake.lock

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
description = "A development shell";
3+
inputs = {
4+
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
5+
};
6+
outputs =
7+
inputs@{
8+
flake-parts,
9+
...
10+
}:
11+
# https://flake.parts/
12+
flake-parts.lib.mkFlake { inherit inputs; } {
13+
systems = [
14+
"x86_64-linux"
15+
"aarch64-darwin"
16+
"x86_64-darwin"
17+
];
18+
perSystem =
19+
{ pkgs, ... }:
20+
{
21+
# Default shell opened with `nix develop`
22+
devShells.default = pkgs.mkShell {
23+
name = "dev";
24+
25+
# Available packages on https://search.nixos.org/packages
26+
buildInputs = with pkgs; [
27+
python3
28+
nodejs
29+
commitizen
30+
];
31+
32+
shellHook = ''
33+
echo "Welcome to the devshell!"
34+
'';
35+
};
36+
};
37+
};
38+
}

0 commit comments

Comments
 (0)