From fc8bbcd26d5889b3f8f33d2b93dc5a25bb20853b Mon Sep 17 00:00:00 2001 From: Santiago Fraire Willemoes Date: Thu, 20 Nov 2025 07:36:13 +0000 Subject: [PATCH 1/5] feat(ci): introduce new setup-cz action --- .cz.yaml | 8 +++++ .github/workflows/test.yaml | 57 +++++++++++++++++++++++++++++++++++ .gitignore | 13 ++++++++ action.yaml | 41 +++++++++++++++++++++++++ flake.lock | 60 +++++++++++++++++++++++++++++++++++++ flake.nix | 38 +++++++++++++++++++++++ 6 files changed, 217 insertions(+) create mode 100644 .cz.yaml create mode 100644 .github/workflows/test.yaml create mode 100644 .gitignore create mode 100644 action.yaml create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.cz.yaml b/.cz.yaml new file mode 100644 index 0000000..4076692 --- /dev/null +++ b/.cz.yaml @@ -0,0 +1,8 @@ +--- +commitizen: + major_version_zero: true + name: cz_conventional_commits + tag_format: v$version + update_changelog_on_bump: true + version: 0.0.1 + version_scheme: semver2 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..bf09a5d --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,57 @@ +name: Test + +on: + pull_request: + branches: + - main + +jobs: + test-installs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - uses: ./ + - name: Test it was installed + run: | + cz version + test-version: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - uses: ./ + with: + version: 4.0.0 + - name: Test version matches + uses: actions/github-script@v8 + with: + script: | + const assert = require('node:assert/strict'); + const czVersion = await exec.getExecOutput('cz', ['version']); + const expectedVersion = '4.0.0'; + assert.equal(czVersion.stdout.trim(), expectedVersion); + test-extra-requirements: + strategy: + matrix: + extra_requirements: + - pip_name: cz-conventional-gitmoji + cz_name: cz_gitmoji + - pip_name: cz-kpn + cz_name: cz_kpn + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - uses: ./ + with: + extra_requirements: ${{ matrix.extra_requirements.pip_name }} + - name: Test extra requirements were installed + uses: actions/github-script@v8 + env: + EXTRA_REQUIREMENTS: ${{ matrix.extra_requirements.cz_name }} + with: + script: | + const assert = require('node:assert/strict'); + const extraRequirements = process.env.EXTRA_REQUIREMENTS; + const czList = await exec.getExecOutput('cz', ['ls']); + const allItems = czList.stdout.trim().split('\n'); + const result = allItems.includes(extraRequirements); + assert.ok(result, `Expected ${extraRequirements} to be included in the list of installed cz plugins, but it was not.`); diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f77277 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[codz] +*$py.class + +# nix +.direnv +result +.envrc + +# python +.venv/ +venv/ diff --git a/action.yaml b/action.yaml new file mode 100644 index 0000000..9ae5acc --- /dev/null +++ b/action.yaml @@ -0,0 +1,41 @@ +name: Setup commitizen CLI +description: | + This workflow sets up the commitizen CLI for use in your GitHub workflows. + Unlike `commitizen-action`, this workflow only installs the CLI. + It does not automatically bump, commit or push changes. + This workflow, instead, gives more flexibility to the user by letting them + use the full range of commitizen commands. + +inputs: + version: + description: "Version of commitizen to install" + required: false + default: "latest" + extra_requirements: + description: "Install extra dependencies" + required: false + +runs: + using: "composite" + steps: + - uses: actions/setup-python@v6 + - id: set-vars + shell: python + env: + COMMITIZEN_VERSION: ${{ inputs.version }} + run: | + import os + commitizen_version = os.environ.get("COMMITIZEN_VERSION", "").strip() + if commitizen_version == "latest": + set_commitizen_version = "" + else: + set_commitizen_version = f"=={commitizen_version}" + with open(os.environ["GITHUB_OUTPUT"], "a") as fh: + fh.write(f"COMMITIZEN_VERSION={set_commitizen_version}\n") + - name: Install commitizen + shell: bash + env: + COMMITIZEN_VERSION: ${{ steps.set-vars.outputs.COMMITIZEN_VERSION }} + EXTRA_REQUIREMENTS: ${{ inputs.extra_requirements }} + run: | + pip install -U commitizen${COMMITIZEN_VERSION} ${EXTRA_REQUIREMENTS} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..cb6b9ff --- /dev/null +++ b/flake.lock @@ -0,0 +1,60 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1762980239, + "narHash": "sha256-8oNVE8TrD19ulHinjaqONf9QWCKK+w4url56cdStMpM=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "52a2caecc898d0b46b2b905f058ccc5081f842da", + "type": "github" + }, + "original": { + "id": "flake-parts", + "type": "indirect" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1763464769, + "narHash": "sha256-AJHrsT7VoeQzErpBRlLJM1SODcaayp0joAoEA35yiwM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "6f374686605df381de8541c072038472a5ea2e2d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1761765539, + "narHash": "sha256-b0yj6kfvO8ApcSE+QmA6mUfu8IYG6/uU28OFn4PaC8M=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "719359f4562934ae99f5443f20aa06c2ffff91fc", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..a69739b --- /dev/null +++ b/flake.nix @@ -0,0 +1,38 @@ +{ + description = "A development shell"; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + }; + outputs = + inputs@{ + flake-parts, + ... + }: + # https://flake.parts/ + flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ + "x86_64-linux" + "aarch64-darwin" + "x86_64-darwin" + ]; + perSystem = + { pkgs, ... }: + { + # Default shell opened with `nix develop` + devShells.default = pkgs.mkShell { + name = "dev"; + + # Available packages on https://search.nixos.org/packages + buildInputs = with pkgs; [ + python3 + nodejs + commitizen + ]; + + shellHook = '' + echo "Welcome to the devshell!" + ''; + }; + }; + }; +} From 8983eb24d13218c195342c559b93ca8527462432 Mon Sep 17 00:00:00 2001 From: Santiago Fraire Willemoes Date: Thu, 20 Nov 2025 08:43:01 +0000 Subject: [PATCH 2/5] feat(ci): add bump action --- .cz.yaml | 1 + .github/workflows/bump.yaml | 56 +++++++++++++++++++++++++++++++++++++ README.md | 31 +++++++++++++++++++- 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/bump.yaml diff --git a/.cz.yaml b/.cz.yaml index 4076692..792f514 100644 --- a/.cz.yaml +++ b/.cz.yaml @@ -6,3 +6,4 @@ commitizen: update_changelog_on_bump: true version: 0.0.1 version_scheme: semver2 + annotated_tag: true diff --git a/.github/workflows/bump.yaml b/.github/workflows/bump.yaml new file mode 100644 index 0000000..e63355f --- /dev/null +++ b/.github/workflows/bump.yaml @@ -0,0 +1,56 @@ +on: + push: + branches: + - main + +jobs: + bump: + runs-on: ubuntu-latest + permissions: + contents: write + actions: write + steps: + - uses: actions/checkout@v5 + with: + fetch-depth: 0 + fetch-tags: true + - name: Set up git config + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" + - uses: actions/setup-cz@main + - uses: pndurette/gh-actions-auto-docs@v1 + with: + git_push: false + - id: bump-version + run: | + cz bump --yes + current_version="v$(cz version -p --current)" + major_version="v$(cz version -p --major)" + echo "current_version=$current_version" >> $GITHUB_OUTPUT + echo "major_version=$major_version" >> $GITHUB_OUTPUT + - name: Update major tag + env: + CURRENT_VERSION: ${{ steps.bump-version.outputs.current_version }} + MAJOR_VERSION: ${{ steps.bump-version.outputs.major_version }} + run: | + # Push new commit + new tag + git push --follow-tags + + # Move major tag to the latest commit + git tag -fa "${MAJOR_VERSION}" -m "release ${CURRENT_VERSION}" + + # Force push new major tag + git push origin "${MAJOR_VERSION}" -f + - name: Build changelog + env: + CURRENT_VERSION: ${{ steps.bump-version.outputs.current_version }} + run: | + cz changelog --dry-run "${CURRENT_VERSION}" > .changelog.md + - name: Release + uses: softprops/action-gh-release@v2 + with: + body_path: ".changelog.md" + tag_name: ${{ steps.bump-version.outputs.current_version }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index 170f328..3e31af7 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,31 @@ # setup-cz -Github action to configure cz + +> Github action to configure cz + +## Usage + +```yaml +jobs: + bump: + runs-on: ubuntu-latest + permissions: + contents: write + actions: write + steps: + - uses: actions/checkout@v5 + with: + fetch-depth: 0 + fetch-tags: true + - uses: actions/setup-cz@main + - name: Set up git config + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" + - run: | + cz version -p + cz bump --yes --annotated-tag + git push --follow-tags +``` + + + From 8eb1260d90ca2e958bb734b5960b7049445a0bd2 Mon Sep 17 00:00:00 2001 From: Santiago Fraire Willemoes Date: Thu, 20 Nov 2025 09:02:07 +0000 Subject: [PATCH 3/5] docs: add examples folder --- examples/bump-release.yaml | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 examples/bump-release.yaml diff --git a/examples/bump-release.yaml b/examples/bump-release.yaml new file mode 100644 index 0000000..7143c5f --- /dev/null +++ b/examples/bump-release.yaml @@ -0,0 +1,42 @@ +# YES, YOU CAN COPY-PASTE THIS ACTION AND IT SHOULD WORK +# keep in mind, that it won't trigger other actions because it's using action permissions. +# You can: use a PAT token or a workflow_call to trigger another action +on: + push: + branches: + - main + +jobs: + bump: + runs-on: ubuntu-latest + permissions: + contents: write + actions: write + steps: + - uses: actions/checkout@v5 + with: + fetch-depth: 0 + fetch-tags: true + - name: Set up git config + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" + - uses: actions/setup-cz@main + - id: bump-version + run: | + cz bump --yes --annotated-tag + git push --follow-tags + current_version="$(cz version -p --current)" # ATTENTION: You may have to add the v* at the beginning of the version + echo "current_version=$current_version" >> $GITHUB_OUTPUT + - name: Build changelog for Release + env: + CURRENT_VERSION: ${{ steps.bump-version.outputs.current_version }} + run: | + cz changelog --dry-run "${CURRENT_VERSION}" > .changelog.md + - name: Release + uses: softprops/action-gh-release@v2 + with: + body_path: ".changelog.md" + tag_name: ${{ steps.bump-version.outputs.current_version }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From affad346ab40ec810a025be7acd8647d1a438a87 Mon Sep 17 00:00:00 2001 From: Santiago Fraire Willemoes Date: Thu, 20 Nov 2025 09:08:49 +0000 Subject: [PATCH 4/5] docs: improve action description --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3e31af7..201da33 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # setup-cz -> Github action to configure cz +> Github action to only configure cz CLI ## Usage From a2097d395fa415224cc32a7f93225b20054d57e5 Mon Sep 17 00:00:00 2001 From: Santiago Fraire Willemoes Date: Thu, 20 Nov 2025 09:13:47 +0000 Subject: [PATCH 5/5] fix(test): add a new more complex case to matrix --- .github/workflows/test.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index bf09a5d..9ca4437 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -37,6 +37,8 @@ jobs: cz_name: cz_gitmoji - pip_name: cz-kpn cz_name: cz_kpn + - pip_name: cz-kpn cz-conventional-gitmoji==0.7.0 + cz_name: cz_kpn runs-on: ubuntu-latest steps: - uses: actions/checkout@v5