Skip to content

Commit 85ea2fe

Browse files
committed
add Publish to Maven Central
1 parent be93dee commit 85ea2fe

2 files changed

Lines changed: 126 additions & 18 deletions

File tree

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Publish to Maven Central
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Version to release (e.g., 0.1.0 or 0.1.0-SNAPSHOT)'
8+
required: true
9+
default: '0.1.0-SNAPSHOT'
10+
type: string
11+
12+
jobs:
13+
publish:
14+
runs-on: macos-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Java
21+
uses: actions/setup-java@v4
22+
with:
23+
java-version: '8'
24+
distribution: 'temurin'
25+
cache: 'maven'
26+
27+
- name: Install GPG
28+
run: brew install gnupg
29+
30+
- name: Generate GPG key
31+
run: |
32+
cat > gpg-batch << EOF
33+
%no-protection
34+
Key-Type: RSA
35+
Key-Length: 4096
36+
Name-Real: GitHub Actions Bot
37+
Name-Email: github-actions-bot@users.noreply.github.com
38+
Expire-Date: 0
39+
%commit
40+
EOF
41+
gpg --batch --generate-key gpg-batch
42+
rm gpg-batch
43+
44+
- name: Get GPG key ID
45+
id: gpg_key_id
46+
run: |
47+
KEY_ID=$(gpg --list-secret-keys --keyid-format=long | grep -E "^sec" | awk '{print $2}' | cut -d'/' -f2)
48+
echo "key_id=$KEY_ID" >> $GITHUB_OUTPUT
49+
echo "GPG Key ID: $KEY_ID"
50+
51+
- name: Export and save GPG key
52+
run: |
53+
gpg --export-secret-keys ${{ steps.gpg_key_id.outputs.key_id }} > gpg-private.key
54+
echo "GPG private key generated and saved"
55+
56+
- name: Publish GPG key to keyserver
57+
run: |
58+
gpg --keyserver keyserver.ubuntu.com --send-keys ${{ steps.gpg_key_id.outputs.key_id }}
59+
echo "Waiting for key to propagate..."
60+
sleep 30
61+
62+
- name: Configure Maven settings
63+
run: |
64+
mkdir -p ~/.m2
65+
cat > ~/.m2/settings.xml << EOF
66+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
67+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
68+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
69+
<servers>
70+
<server>
71+
<id>central</id>
72+
<username>${{ secrets.CENTRAL_USERNAME }}</username>
73+
<password>${{ secrets.CENTRAL_PASSWORD }}</password>
74+
</server>
75+
</servers>
76+
</settings>
77+
EOF
78+
79+
- name: Update version in pom.xml
80+
run: |
81+
mvn versions:set -DnewVersion=${{ github.event.inputs.version }}
82+
mvn versions:commit
83+
84+
- name: Build and publish to Maven Central
85+
run: mvn clean deploy -Psign-artifacts
86+
env:
87+
GPG_TTY: $(tty)
88+
89+
- name: Upload build artifacts
90+
if: always()
91+
uses: actions/upload-artifact@v4
92+
with:
93+
name: maven-artifacts
94+
path: |
95+
clients/java/target/*.jar
96+
clients/java/target/*.pom
97+
clients/java/target/*.asc
98+
retention-days: 7

clients/java/pom.xml

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
<groupId>io.openkruise</groupId>
55
<artifactId>agents-client-java</artifactId>
66
<packaging>jar</packaging>
7-
<version>0.1.0</version>
7+
<version>0.1.0-SNAPSHOT</version>
88
<name>agents-client-java</name>
99
<description>Java client for Agents</description>
1010
<url>https://github.com/openkruise/agents-api</url>
1111

1212
<prerequisites>
13-
<maven>2.2.0</maven>
13+
<maven>3.6.0</maven>
1414
</prerequisites>
1515

1616
<scm>
@@ -28,13 +28,10 @@
2828
</licenses>
2929

3030
<distributionManagement>
31-
<snapshotRepository>
32-
<id>ossrh</id>
33-
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
34-
</snapshotRepository>
3531
<repository>
36-
<id>ossrh</id>
37-
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
32+
<id>central</id>
33+
<name>Central Repository</name>
34+
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
3835
</repository>
3936
</distributionManagement>
4037

@@ -43,7 +40,7 @@
4340
<plugin>
4441
<groupId>org.apache.maven.plugins</groupId>
4542
<artifactId>maven-surefire-plugin</artifactId>
46-
<version>2.12</version>
43+
<version>3.0.0</version>
4744
<configuration>
4845
<systemProperties>
4946
<property>
@@ -52,8 +49,6 @@
5249
</property>
5350
</systemProperties>
5451
<argLine>-Xms512m -Xmx1500m</argLine>
55-
<parallel>methods</parallel>
56-
<forkMode>pertest</forkMode>
5752
</configuration>
5853
</plugin>
5954
<plugin>
@@ -75,7 +70,7 @@
7570
<plugin>
7671
<groupId>org.apache.maven.plugins</groupId>
7772
<artifactId>maven-jar-plugin</artifactId>
78-
<version>2.2</version>
73+
<version>3.3.0</version>
7974
<executions>
8075
<execution>
8176
<goals>
@@ -84,14 +79,12 @@
8479
</goals>
8580
</execution>
8681
</executions>
87-
<configuration>
88-
</configuration>
8982
</plugin>
9083

9184
<plugin>
9285
<groupId>org.codehaus.mojo</groupId>
9386
<artifactId>build-helper-maven-plugin</artifactId>
94-
<version>1.10</version>
87+
<version>3.5.0</version>
9588
<executions>
9689
<execution>
9790
<id>add_sources</id>
@@ -122,7 +115,7 @@
122115
<plugin>
123116
<groupId>org.apache.maven.plugins</groupId>
124117
<artifactId>maven-javadoc-plugin</artifactId>
125-
<version>2.10.4</version>
118+
<version>3.6.0</version>
126119
<executions>
127120
<execution>
128121
<id>attach-javadocs</id>
@@ -135,7 +128,7 @@
135128
<plugin>
136129
<groupId>org.apache.maven.plugins</groupId>
137130
<artifactId>maven-source-plugin</artifactId>
138-
<version>2.2.1</version>
131+
<version>3.3.0</version>
139132
<executions>
140133
<execution>
141134
<id>attach-sources</id>
@@ -145,6 +138,17 @@
145138
</execution>
146139
</executions>
147140
</plugin>
141+
<!-- Central Publishing Plugin for Maven Central -->
142+
<plugin>
143+
<groupId>org.sonatype.central</groupId>
144+
<artifactId>central-publishing-maven-plugin</artifactId>
145+
<version>0.9.0</version>
146+
<extensions>true</extensions>
147+
<configuration>
148+
<publishingServerId>central</publishingServerId>
149+
<tokenAuth>true</tokenAuth>
150+
</configuration>
151+
</plugin>
148152
</plugins>
149153
</build>
150154

@@ -156,14 +160,20 @@
156160
<plugin>
157161
<groupId>org.apache.maven.plugins</groupId>
158162
<artifactId>maven-gpg-plugin</artifactId>
159-
<version>1.5</version>
163+
<version>3.1.0</version>
160164
<executions>
161165
<execution>
162166
<id>sign-artifacts</id>
163167
<phase>verify</phase>
164168
<goals>
165169
<goal>sign</goal>
166170
</goals>
171+
<configuration>
172+
<gpgArguments>
173+
<arg>--pinentry-mode</arg>
174+
<arg>loopback</arg>
175+
</gpgArguments>
176+
</configuration>
167177
</execution>
168178
</executions>
169179
</plugin>

0 commit comments

Comments
 (0)