Skip to content

Commit 5dae248

Browse files
authored
Merge pull request #5 from commitizen-tools/feat/new-example
feat(examples): add a new more in-depth example
2 parents 7756c6d + 3e25cb9 commit 5dae248

File tree

6 files changed

+132
-0
lines changed

6 files changed

+132
-0
lines changed

.github/workflows/test.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,22 @@ jobs:
7979
assert.ok(changelogContent.includes('v0.1.0 (2025-11-20)'), 'Expected changelog to contain version 0.1.0');
8080
assert.ok(changelogContent.includes('### Feat'), 'Expected changelog to contain a header for features');
8181
assert.ok(changelogContent.includes('### Fix'), 'Expected changelog to contain a header for fixes');
82+
test-trigger-other-job:
83+
runs-on: ubuntu-latest
84+
steps:
85+
- uses: actions/checkout@v5
86+
with:
87+
fetch-depth: 0
88+
- uses: ./
89+
- id: get-version
90+
run: |
91+
current_version="$(cz version -p)" # ATTENTION: You may have to add the v* at the beginning of the version
92+
echo "current_version=$current_version" >> $GITHUB_OUTPUT
93+
- name: trigger other workflow
94+
env:
95+
GH_TOKEN: ${{ github.token }}
96+
run: |
97+
gh workflow list
98+
gh workflow run .github/workflows/trigger-me.yaml \
99+
--ref "${{ github.head_ref }}" \
100+
-f "version=${{ steps.get-version.outputs.current_version }}"

.github/workflows/trigger-me.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
on:
2+
workflow_dispatch:
3+
inputs:
4+
version:
5+
description: "Version to trigger"
6+
required: true
7+
8+
jobs:
9+
triggered-echo:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
actions: write
13+
steps:
14+
- name: Trigger other job
15+
run: |
16+
echo "Version: ${{ inputs.version }}"
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Trigger other job
2+
3+
In this example, we trigger another job without having to configure a PAT token.
4+
This is achieved by using github API and workflow_dispatch event.
5+
6+
```mermaid
7+
flowchart LR
8+
subgraph BR["bump-release"]
9+
direction TB
10+
bump
11+
git_push["git push"]
12+
create_changelog["create changelog"]
13+
release
14+
workflow_dispatch
15+
16+
bump --> git_push
17+
git_push --> create_changelog
18+
create_changelog --> release
19+
release --> workflow_dispatch
20+
end
21+
22+
subgraph TM["trigger-me"]
23+
echo_version["echo version"]
24+
25+
%% Workaround to increase height of the graph
26+
echo_version ~~~ spacer1[" "]:::hidden
27+
spacer1 ~~~ spacer2[" "]:::hidden
28+
spacer2 ~~~ spacer3[" "]:::hidden
29+
spacer3 ~~~ spacer4[" "]:::hidden
30+
spacer4 ~~~ spacer5[" "]:::hidden
31+
end
32+
33+
BR --> TM
34+
```
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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: commitizen-tools/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)" # 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 }}
43+
- name: trigger other workflow
44+
env:
45+
GH_TOKEN: ${{ github.token }}
46+
run: |
47+
gh workflow run .github/workflows/trigger-me.yaml \
48+
-f "version=${{ steps.bump-version.outputs.current_version }}"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
on:
2+
workflow_dispatch:
3+
inputs:
4+
version:
5+
description: "Version to trigger"
6+
required: true
7+
8+
jobs:
9+
triggered-echo:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Trigger other job
13+
run: |
14+
echo "Version: ${{ inputs.version }}"

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
python3
2828
nodejs
2929
commitizen
30+
gh
3031
];
3132

3233
shellHook = ''

0 commit comments

Comments
 (0)