Skip to content

Commit 30919c8

Browse files
committed
ci: enhance release workflow to detect version type from commit messages
1 parent bee56c5 commit 30919c8

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

.github/workflows/release.yml

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,53 @@ on:
1111
- patch
1212
- minor
1313
- major
14+
push:
15+
branches:
16+
- main
1417

1518
jobs:
19+
detect-version:
20+
runs-on: ubuntu-latest
21+
outputs:
22+
version_type: ${{ steps.detect.outputs.version_type }}
23+
should_release: ${{ steps.detect.outputs.should_release }}
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 1
29+
30+
- name: Detect version type from commit
31+
id: detect
32+
run: |
33+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
34+
echo "version_type=${{ github.event.inputs.version_type }}" >> $GITHUB_OUTPUT
35+
echo "should_release=true" >> $GITHUB_OUTPUT
36+
else
37+
COMMIT_MSG=$(git log -1 --pretty=%s)
38+
echo "Commit message: $COMMIT_MSG"
39+
if echo "$COMMIT_MSG" | grep -qE '^[a-z]+(\(.+\))?!:'; then
40+
echo "Detected: major (breaking change)"
41+
echo "version_type=major" >> $GITHUB_OUTPUT
42+
echo "should_release=true" >> $GITHUB_OUTPUT
43+
elif echo "$COMMIT_MSG" | grep -qE '^feat(\(.+\))?:'; then
44+
echo "Detected: minor (new feature)"
45+
echo "version_type=minor" >> $GITHUB_OUTPUT
46+
echo "should_release=true" >> $GITHUB_OUTPUT
47+
elif echo "$COMMIT_MSG" | grep -qE '^fix(\(.+\))?:'; then
48+
echo "Detected: patch (bug fix)"
49+
echo "version_type=patch" >> $GITHUB_OUTPUT
50+
echo "should_release=true" >> $GITHUB_OUTPUT
51+
else
52+
echo "No release needed for this commit type"
53+
echo "version_type=none" >> $GITHUB_OUTPUT
54+
echo "should_release=false" >> $GITHUB_OUTPUT
55+
fi
56+
fi
57+
1658
release:
59+
needs: detect-version
60+
if: needs.detect-version.outputs.should_release == 'true'
1761
runs-on: ubuntu-latest
1862
permissions:
1963
contents: write
@@ -38,7 +82,7 @@ jobs:
3882
- name: Bump npm version
3983
id: version
4084
run: |
41-
NEW_VERSION=$(npm version ${{ github.event.inputs.version_type }} --no-git-tag-version)
85+
NEW_VERSION=$(npm version ${{ needs.detect-version.outputs.version_type }} --no-git-tag-version)
4286
echo "new_version=${NEW_VERSION}" >> $GITHUB_OUTPUT
4387
echo "version_number=${NEW_VERSION#v}" >> $GITHUB_OUTPUT
4488

0 commit comments

Comments
 (0)