Skip to content

Commit 6ed08c9

Browse files
authored
Merge pull request #2 from commitizen-tools/feat/new-examples
Feat/new examples
2 parents 5c02dba + d698a66 commit 6ed08c9

File tree

6 files changed

+136
-2
lines changed

6 files changed

+136
-2
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
flake.nix linguist-vendored
2+
flake.lock linguist-vendored

.github/workflows/test.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,25 @@ jobs:
5757
const allItems = czList.stdout.trim().split('\n');
5858
const result = allItems.includes(extraRequirements);
5959
assert.ok(result, `Expected ${extraRequirements} to be included in the list of installed cz plugins, but it was not.`);
60+
test-get-changelog:
61+
runs-on: ubuntu-latest
62+
steps:
63+
- uses: actions/checkout@v5
64+
with:
65+
fetch-depth: 0
66+
- uses: ./
67+
- name: Build changelog
68+
env:
69+
GIVEN_VERSION: "v0.1.0"
70+
run: |
71+
cz changelog --dry-run "${GIVEN_VERSION}" > .changelog.md
72+
- name: Verify changelog content
73+
uses: actions/github-script@v8
74+
with:
75+
script: |
76+
const assert = require('node:assert/strict');
77+
const fs = require('node:fs');
78+
const changelogContent = fs.readFileSync('.changelog.md', 'utf8');
79+
assert.ok(changelogContent.includes('v0.1.0 (2025-11-20)'), 'Expected changelog to contain version 0.1.0');
80+
assert.ok(changelogContent.includes('### Feat'), 'Expected changelog to contain a header for features');
81+
assert.ok(changelogContent.includes('### Fix'), 'Expected changelog to contain a header for fixes');

action.yaml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,43 @@ inputs:
1414
extra_requirements:
1515
description: "Install extra dependencies"
1616
required: false
17+
cache:
18+
description: 'Cache commitizen installation, set to "true" to enable'
19+
required: false
20+
default: "false"
1721

1822
runs:
1923
using: "composite"
2024
steps:
21-
- uses: actions/setup-python@v6
2225
- id: set-vars
2326
shell: python
2427
env:
2528
COMMITIZEN_VERSION: ${{ inputs.version }}
29+
CACHE: ${{ inputs.cache }}
2630
run: |
2731
import os
32+
33+
# Set commitizen version
2834
commitizen_version = os.environ.get("COMMITIZEN_VERSION", "").strip()
2935
if commitizen_version == "latest":
3036
set_commitizen_version = ""
3137
else:
3238
set_commitizen_version = f"=={commitizen_version}"
39+
40+
# Set python cache
41+
cache = os.environ.get("CACHE", "")
42+
if cache == True or cache == "true":
43+
set_cache = "pip"
44+
else:
45+
set_cache = ""
46+
47+
# Write outputs
3348
with open(os.environ["GITHUB_OUTPUT"], "a") as fh:
3449
fh.write(f"COMMITIZEN_VERSION={set_commitizen_version}\n")
50+
fh.write(f"PYTHON_CACHE={set_cache}\n")
51+
- uses: actions/setup-python@v6
52+
with:
53+
cache: ${{ steps.set-vars.outputs.PYTHON_CACHE }}
3554
- name: Install commitizen
3655
shell: bash
3756
env:

examples/build-changelog.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Build the changelog for a given version with a manual trigger
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
version:
6+
description: "Version to build changelog for"
7+
required: true
8+
type: string
9+
# You can also trigger this workflow from another workflow
10+
workflow_call:
11+
inputs:
12+
version:
13+
description: "Version to build changelog for"
14+
required: true
15+
type: string
16+
17+
jobs:
18+
build-changelog:
19+
runs-on: ubuntu-latest
20+
outputs:
21+
changelog: ${{ steps.build-changelog.outputs.changelog }}
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v5
25+
with:
26+
fetch-depth: 0
27+
- uses: commitizen-tools/setup-cz@main
28+
- name: Build changelog
29+
env:
30+
GIVEN_VERSION: ${{ github.event.inputs.version }}
31+
run: |
32+
cz changelog --dry-run "${GIVEN_VERSION}" > .changelog.md
33+
- name: Display changelog
34+
run: |
35+
cat .changelog.md
36+
# You can send this file wherever you want:
37+
# - For a Github release
38+
# - Update a website
39+
# - Send it to a Slack channel
40+
# - Send it to a compliance tool

examples/bump-release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
run: |
2727
cz bump --yes --annotated-tag
2828
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
29+
current_version="$(cz version -p)" # ATTENTION: You may have to add the v* at the beginning of the version
3030
echo "current_version=$current_version" >> $GITHUB_OUTPUT
3131
- name: Build changelog for Release
3232
env:

examples/collect-version-info.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# This action shows how to collect version information and propagate it to the next job.
2+
name: Collect Version Info
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
branches:
10+
- main
11+
12+
jobs:
13+
collect-version-info:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
current_version: ${{ steps.version-info.outputs.current_version }}
17+
current_major_version: ${{ steps.version-info.outputs.current_major_version }}
18+
current_minor_version: ${{ steps.version-info.outputs.current_minor_version }}
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v5
22+
with:
23+
fetch-tags: true # in case your version provider is cvs
24+
- uses: commitizen-tools/setup-cz@main
25+
- id: version-info
26+
run: |
27+
# Gather version information
28+
current_version="$(cz version -p)"
29+
current_major_version="$(cz version -p --major)"
30+
current_minor_version="$(cz version -p --minor)"
31+
32+
# Set output variables
33+
echo "current_version=$current_version" >> $GITHUB_OUTPUT
34+
echo "current_major_version=$current_major_version" >> $GITHUB_OUTPUT
35+
echo "current_minor_version=$current_minor_version" >> $GITHUB_OUTPUT
36+
read-version-info:
37+
runs-on: ubuntu-latest
38+
needs: collect-version-info
39+
steps:
40+
- name: Checkout code
41+
uses: actions/checkout@v5
42+
- run: |
43+
# Read version information
44+
current_version="${{ needs.collect-version-info.outputs.current_version }}"
45+
current_major_version="${{ needs.collect-version-info.outputs.current_major_version }}"
46+
current_minor_version="${{ needs.collect-version-info.outputs.current_minor_version }}"
47+
48+
# Print version information
49+
echo "Current version: $current_version"
50+
echo "Current major version: $current_major_version"
51+
echo "Current minor version: $current_minor_version"

0 commit comments

Comments
 (0)