Skip to content

Commit 43216ae

Browse files
committed
ci(pr): implement release pr detection
Ref: #65 Signed-off-by: Philip Gerke <me@philipgerke.com>
1 parent 44b3a67 commit 43216ae

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: "Detect commitizen version change"
2+
description: "Checks if the 'version' key in .cz.json has changed compared to the previous commit."
3+
outputs:
4+
version_changed:
5+
description: "Boolean indicating if the version has changed"
6+
value: ${{ steps.check.outputs.version_changed }}
7+
runs:
8+
using: "composite"
9+
steps:
10+
- name: Checkout previous commit
11+
uses: actions/checkout@v4
12+
with:
13+
fetch-depth: 2
14+
15+
- name: Extract version from previous commit
16+
id: old_version
17+
shell: bash
18+
run: |
19+
OLD_VERSION=$(git show HEAD^:package.json | jq -r '.version // "not_found"')
20+
echo "OLD_VERSION=$OLD_VERSION" >> $GITHUB_ENV
21+
echo "Previous version: $OLD_VERSION"
22+
23+
- name: Extract version from current commit
24+
id: new_version
25+
shell: bash
26+
run: |
27+
NEW_VERSION=$(jq -r '.version // "not_found"' package.json)
28+
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
29+
echo "Current version: $NEW_VERSION"
30+
31+
- name: Compare versions
32+
id: check
33+
shell: bash
34+
run: |
35+
if [ "$OLD_VERSION" != "$NEW_VERSION" ]; then
36+
echo "Version changed from $OLD_VERSION to $NEW_VERSION"
37+
echo "version_changed=true" >> $GITHUB_OUTPUT
38+
else
39+
echo "No version change detected"
40+
echo "version_changed=false" >> $GITHUB_OUTPUT
41+
fi
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: "Get Version and Changelog"
2+
description: "Get the new version and changelog entry from commitizen"
3+
outputs:
4+
version:
5+
description: "The new version"
6+
value: ${{ steps.version.outputs.version }}
7+
changelog:
8+
description: "The changelog entry for the new version"
9+
value: ${{ steps.changelog.outputs.changelog }}
10+
runs:
11+
using: "composite"
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
fetch-tags: true
18+
- name: Install Commitizen
19+
shell: bash
20+
run: pip install commitizen
21+
- name: Get new version
22+
shell: bash
23+
id: version
24+
run: |
25+
cz version -p
26+
echo "version=$(cz version -p)" >> $GITHUB_OUTPUT
27+
- name: Extract Changelog Entry
28+
shell: bash
29+
id: changelog
30+
run: |
31+
{
32+
echo "changelog<<EOF"
33+
cz ch ${{ steps.version.outputs.version }} --dry-run
34+
echo "EOF"
35+
} >> "$GITHUB_OUTPUT"
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: PR Release Check
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
7+
jobs:
8+
check_release_trigger:
9+
name: Check if PR will trigger a Release
10+
runs-on: ubuntu-latest
11+
outputs:
12+
version_changed: ${{ steps.detect_version_change.outputs.version_changed }}
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
- name: Detect version change
17+
id: detect_version_change
18+
uses: ./.github/actions/detect-version-change
19+
20+
update_pr_comment:
21+
name: Update PR Comment
22+
runs-on: ubuntu-latest
23+
needs: check_release_trigger
24+
if: ${{ needs.check_release_trigger.outputs.version_changed }} == "true"
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v4
28+
- name: Add "release" label
29+
uses: actions-ecosystem/action-add-labels@v1
30+
with:
31+
labels: release
32+
- name: Get new version and changelog
33+
id: extract_version
34+
uses: ./.github/actions/get-version-and-changelog
35+
- name: Find Comment
36+
uses: peter-evans/find-comment@v3
37+
id: fc
38+
with:
39+
issue-number: ${{ github.event.pull_request.number }}
40+
comment-author: "github-actions[bot]"
41+
body-includes: ✅ **This PR will trigger a new release upon merge!** 🚀
42+
- name: Comment on PR if release will be triggered
43+
uses: peter-evans/create-or-update-comment@v4
44+
with:
45+
comment-id: ${{ steps.fc.outputs.comment-id }}
46+
issue-number: ${{ github.event.pull_request.number }}
47+
body: |
48+
✅ **This PR will trigger a new release upon merge!** 🚀
49+
50+
## 📢 Planned version: v${{ steps.extract_version.outputs.version }}
51+
52+
🔍 **Changelog for the new version:**
53+
```markdown
54+
${{ steps.extract_version.outputs.changelog }}
55+
```
56+
edit-mode: replace

0 commit comments

Comments
 (0)