Skip to content

Commit 62adb9b

Browse files
committed
add maven-publish github action
1 parent 4e9842d commit 62adb9b

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

.github/workflows/maven-publish.yml

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+
- main
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: central
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 }}

0 commit comments

Comments
 (0)