Skip to content

Commit b63b1e3

Browse files
committed
Enhance semantic release workflow
1 parent 8decbe5 commit b63b1e3

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

.github/workflows/semantic-release.yml

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,48 @@ jobs:
3535
minor_pattern: "/^feat:/"
3636
version_format: "${major}.${minor}.${patch}"
3737
search_commit_body: true
38+
bump_each_commit: true
3839
debug: true
3940

4041
- name: Check if new release is needed
4142
id: check
4243
run: |
43-
if [ "v${{ steps.semver.outputs.version }}" == "${{ steps.get_latest.outputs.latest }}" ]; then
44-
echo "No new version needed."
44+
LATEST_TAG="${{ steps.get_latest.outputs.latest }}"
45+
NEW_VERSION="v${{ steps.semver.outputs.version }}"
46+
47+
# Check if there are any commits since the latest tag
48+
COMMITS_SINCE=$(git rev-list ${LATEST_TAG}..HEAD --count 2>/dev/null || echo "0")
49+
50+
if [ "$COMMITS_SINCE" -eq "0" ]; then
51+
echo "No new commits since $LATEST_TAG."
4552
echo "release=false" >> $GITHUB_OUTPUT
53+
elif [ "$NEW_VERSION" == "$LATEST_TAG" ]; then
54+
echo "Version hasn't changed ($NEW_VERSION), but there are $COMMITS_SINCE new commits."
55+
echo "Force creating patch release..."
56+
# Calculate next patch version manually
57+
LATEST_WITHOUT_V=$(echo $LATEST_TAG | sed 's/^v//')
58+
MAJOR=$(echo $LATEST_WITHOUT_V | cut -d. -f1)
59+
MINOR=$(echo $LATEST_WITHOUT_V | cut -d. -f2)
60+
PATCH=$(echo $LATEST_WITHOUT_V | cut -d. -f3)
61+
NEW_PATCH=$((PATCH + 1))
62+
NEW_VERSION="v${MAJOR}.${MINOR}.${NEW_PATCH}"
63+
echo "version_override=${MAJOR}.${MINOR}.${NEW_PATCH}" >> $GITHUB_OUTPUT
64+
echo "New version will be: $NEW_VERSION"
65+
echo "release=true" >> $GITHUB_OUTPUT
4666
else
47-
echo "New version will be: ${{ steps.semver.outputs.version }}"
67+
echo "New version will be: $NEW_VERSION"
4868
echo "release=true" >> $GITHUB_OUTPUT
4969
fi
5070
5171
- name: Generate changelog
5272
if: steps.check.outputs.release == 'true'
5373
id: changelog
5474
run: |
55-
NEW_TAG="v${{ steps.semver.outputs.version }}"
75+
if [ -n "${{ steps.check.outputs.version_override }}" ]; then
76+
NEW_TAG="v${{ steps.check.outputs.version_override }}"
77+
else
78+
NEW_TAG="v${{ steps.semver.outputs.version }}"
79+
fi
5680
OLD_TAG="${{ steps.get_latest.outputs.latest }}"
5781
5882
echo "release_notes<<EOF" >> $GITHUB_OUTPUT
@@ -94,7 +118,7 @@ jobs:
94118
if: steps.check.outputs.release == 'true'
95119
uses: softprops/action-gh-release@v2
96120
with:
97-
tag_name: v${{ steps.semver.outputs.version }}
98-
name: Release v${{ steps.semver.outputs.version }}
121+
tag_name: ${{ steps.check.outputs.version_override && format('v{0}', steps.check.outputs.version_override) || format('v{0}', steps.semver.outputs.version) }}
122+
name: ${{ steps.check.outputs.version_override && format('Release v{0}', steps.check.outputs.version_override) || format('Release v{0}', steps.semver.outputs.version) }}
99123
body: ${{ steps.changelog.outputs.release_notes }}
100124
generate_release_notes: true

0 commit comments

Comments
 (0)