Skip to content

Commit 245cf72

Browse files
committed
🎨 增加github action来自动发布版本到maven中央仓库
1 parent fb57af7 commit 245cf72

File tree

3 files changed

+59
-7
lines changed

3 files changed

+59
-7
lines changed

.github/workflows

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Publish to Maven Central
2+
on:
3+
push:
4+
branches:
5+
- develop
6+
7+
jobs:
8+
build-and-publish:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
# 检出代码
13+
- name: Checkout Code
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
18+
# 设置所需的Java版本
19+
- name: Set up Java
20+
uses: actions/setup-java@v4
21+
with:
22+
java-version: '8'
23+
distribution: 'temurin'
24+
server-id: ossrh
25+
server-username: MAVEN_USERNAME
26+
server-password: MAVEN_PASSWORD
27+
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
28+
gpg-passphrase: MAVEN_GPG_PASSPHRASE
29+
cache: maven
30+
31+
- name: Verify GPG keys
32+
run: |
33+
echo "Available GPG Keys:"
34+
gpg --list-secret-keys --keyid-format LONG
35+
36+
- name: Generate version && Set version
37+
id: set_version
38+
run: |
39+
git describe --tags 2>/dev/null || echo "no tag"
40+
TIMESTAMP=$(date +'%Y%m%d.%H%M%S')
41+
GIT_DESCRIBE=$(git describe --tags --abbrev=0 2>/dev/null | sed 's/^v//' || echo "0.0.1")
42+
VERSION="${GIT_DESCRIBE}-${TIMESTAMP}"
43+
echo "Generated version: $VERSION"
44+
mvn versions:set -DnewVersion=$VERSION --no-transfer-progress
45+
env:
46+
TZ: Asia/Shanghai
47+
48+
- name: Publish to Maven Central
49+
run: |
50+
mvn clean deploy -P release \
51+
-Dmaven.test.skip=true \
52+
-Dgpg.args="--batch --yes --pinentry-mode loopback" \
53+
--no-transfer-progress
54+
env:
55+
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
56+
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
57+
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}

pom.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,8 @@
136136

137137
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
138138
<httpclient.version>4.5.13</httpclient.version>
139-
<jetty.version>9.4.56.v20240826</jetty.version>
140-
<!-- 这个不能用10以上的版本,不支持jdk8-->
139+
<jetty.version>9.4.56.v20240826</jetty.version> <!-- 这个不能用10以上的版本,不支持jdk8-->
141140
</properties>
142-
143141
<dependencyManagement>
144142
<dependencies>
145143
<dependency>
@@ -339,6 +337,7 @@
339337
</snapshotRepository>
340338
<repository>
341339
<id>ossrh</id>
340+
<name>OSSRH Repository</name>
342341
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
343342
</repository>
344343
</distributionManagement>

0 commit comments

Comments
 (0)