4
4
branches :
5
5
- develop
6
6
7
+ permissions :
8
+ contents : write
9
+
7
10
concurrency :
8
11
group : maven-publish-${{ github.ref }}
9
12
cancel-in-progress : true
@@ -13,13 +16,38 @@ jobs:
13
16
runs-on : ubuntu-latest
14
17
15
18
steps :
16
- # 检出代码
17
19
- name : Checkout Code
18
20
uses : actions/checkout@v4
19
21
with :
20
22
fetch-depth : 0
21
23
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 "a@binarywang.com"
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
+
23
51
- name : Set up Java
24
52
uses : actions/setup-java@v4
25
53
with :
@@ -37,14 +65,19 @@ jobs:
37
65
echo "Available GPG Keys:"
38
66
gpg --list-secret-keys --keyid-format LONG
39
67
40
- - name : Generate version && Set version
68
+ - name : Generate and set version
41
69
id : set_version
42
70
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
48
81
mvn versions:set -DnewVersion=$VERSION --no-transfer-progress
49
82
env :
50
83
TZ : Asia/Shanghai
0 commit comments