Skip to content

Commit 55cf4e2

Browse files
feat: rework PR bump preview workflow
Replace the previous draft (poetry-based) attempt with a simpler, robust implementation: * Use commitizen-tools/setup-cz instead of installing Poetry/cz from the project lockfile. The action repo doesn't need its own Python toolchain to run cz. * Trigger on pull_request_target so the workflow has pull-requests: write even for fork PRs. Only `cz bump --dry-run` is executed, so PR-controlled scripts are not run. * Capture the dry-run exit status. Treat exit code 21 (NoneIncrementExit) as 'no eligible commits' instead of a hard failure, and surface other non-zero codes in the comment. * Use a hidden HTML marker so the comment is replaced (rather than duplicated) on every push. Closes commitizen-tools/commitizen#1510 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 8997da5 commit 55cf4e2

2 files changed

Lines changed: 82 additions & 41 deletions

File tree

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: PR bump preview
2+
3+
on:
4+
pull_request_target:
5+
types: [opened, reopened, synchronize, ready_for_review]
6+
7+
permissions:
8+
contents: read
9+
pull-requests: write
10+
11+
jobs:
12+
bump-preview:
13+
if: ${{ github.event.pull_request.draft == false }}
14+
runs-on: ubuntu-latest
15+
steps:
16+
# Using pull_request_target so the workflow has pull-requests: write
17+
# access for fork PRs. The job only runs `cz bump --dry-run`, a
18+
# read-only command, so PR-controlled scripts are not executed.
19+
- name: Check out PR head
20+
uses: actions/checkout@v4
21+
with:
22+
ref: ${{ github.event.pull_request.head.sha }}
23+
fetch-depth: 0
24+
fetch-tags: true
25+
26+
- name: Set up Commitizen
27+
uses: commitizen-tools/setup-cz@main
28+
with:
29+
set-git-config: false
30+
31+
- name: Run cz bump --dry-run
32+
id: dry-run
33+
run: |
34+
set +e
35+
output="$(cz bump --dry-run --yes 2>&1)"
36+
status=$?
37+
set -e
38+
{
39+
echo "status=${status}"
40+
echo "output<<__CZ_BUMP_PREVIEW__"
41+
printf '%s\n' "${output}"
42+
echo "__CZ_BUMP_PREVIEW__"
43+
} >> "$GITHUB_OUTPUT"
44+
45+
- name: Build comment body
46+
env:
47+
STATUS: ${{ steps.dry-run.outputs.status }}
48+
OUTPUT: ${{ steps.dry-run.outputs.output }}
49+
run: |
50+
{
51+
echo "<!-- commitizen-bump-preview -->"
52+
echo "## 🔍 Commitizen bump preview"
53+
echo ""
54+
case "${STATUS}" in
55+
0)
56+
echo "Merging this PR will produce the following bump:"
57+
echo ""
58+
echo '```'
59+
printf '%s\n' "${OUTPUT}"
60+
echo '```'
61+
;;
62+
21)
63+
echo "No commits in this PR are eligible for a version bump."
64+
;;
65+
*)
66+
echo "⚠️ \`cz bump --dry-run\` exited with status \`${STATUS}\`:"
67+
echo ""
68+
echo '```'
69+
printf '%s\n' "${OUTPUT}"
70+
echo '```'
71+
;;
72+
esac
73+
} > comment.md
74+
75+
- name: Post or update PR comment
76+
uses: peter-evans/create-or-update-comment@v4
77+
with:
78+
token: ${{ secrets.GITHUB_TOKEN }}
79+
issue-number: ${{ github.event.pull_request.number }}
80+
body-path: comment.md
81+
body-includes: "<!-- commitizen-bump-preview -->"
82+
edit-mode: replace

.github/workflows/pr-cz-dry-run-bump-comment.yml

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)