44 branches :
55 - develop
66
7+ permissions :
8+ contents : write
9+
710concurrency :
811 group : maven-publish-${{ github.ref }}
912 cancel-in-progress : true
@@ -13,13 +16,38 @@ jobs:
1316 runs-on : ubuntu-latest
1417
1518 steps :
16- # 检出代码
1719 - name : Checkout Code
1820 uses : actions/checkout@v4
1921 with :
2022 fetch-depth : 0
2123
22- # 设置所需的Java版本
24+ - name : Detect and tag release version from commit message
25+ id : version_detect
26+ run : |
27+ COMMIT_MSG=$(git log -1 --pretty=%B)
28+ VERSION=""
29+ TAG=""
30+ IS_RELEASE="false"
31+ if [[ "$COMMIT_MSG" =~ ^:bookmark:\ 发布\ ([0-9]+\.[0-9]+\.[0-9]+)\.B\ 测试版本 ]]; then
32+ BASE_VER="${BASH_REMATCH[1]}"
33+ VERSION="${BASE_VER}.B"
34+ TAG="v${BASE_VER}"
35+ IS_RELEASE="true"
36+ echo "Matched release commit: VERSION=$VERSION, TAG=$TAG"
37+ # 检查并打tag
38+ if git tag | grep -q "^$TAG$"; then
39+ echo "Tag $TAG already exists."
40+ else
41+ git config user.name "Binary Wang"
42+ git config user.email "[email protected] " 43+ git tag -a "$TAG" -m "Release $TAG"
44+ git push origin "$TAG"
45+ echo "Tag $TAG created and pushed."
46+ fi
47+ fi
48+ echo "is_release=$IS_RELEASE" >> $GITHUB_OUTPUT
49+ echo "version=$VERSION" >> $GITHUB_OUTPUT
50+
2351 - name : Set up Java
2452 uses : actions/setup-java@v4
2553 with :
@@ -37,14 +65,19 @@ jobs:
3765 echo "Available GPG Keys:"
3866 gpg --list-secret-keys --keyid-format LONG
3967
40- - name : Generate version && Set version
68+ - name : Generate and set version
4169 id : set_version
4270 run : |
43- git describe --tags 2>/dev/null || echo "no tag"
44- TIMESTAMP=$(date +'%Y%m%d.%H%M%S')
45- GIT_DESCRIBE=$(git describe --tags --abbrev=0 2>/dev/null | sed 's/^v//' || echo "0.0.1")
46- VERSION="${GIT_DESCRIBE}-${TIMESTAMP}"
47- echo "Generated version: $VERSION"
71+ if [[ "${{ steps.version_detect.outputs.is_release }}" == "true" ]]; then
72+ VERSION="${{ steps.version_detect.outputs.version }}"
73+ else
74+ git describe --tags 2>/dev/null || echo "no tag"
75+ TIMESTAMP=$(date +'%Y%m%d.%H%M%S')
76+ GIT_DESCRIBE=$(git describe --tags --abbrev=0 2>/dev/null | sed 's/^v//' || echo "0.0.1")
77+ VERSION="${GIT_DESCRIBE}-${TIMESTAMP}"
78+ fi
79+ echo "Final version: $VERSION"
80+ echo "VERSION=$VERSION" >> $GITHUB_ENV
4881 mvn versions:set -DnewVersion=$VERSION --no-transfer-progress
4982 env :
5083 TZ : Asia/Shanghai
0 commit comments