Skip to content

Commit cd2fded

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

2 files changed

Lines changed: 132 additions & 21 deletions

File tree

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Publish to Maven Central
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Version to release'
8+
required: true
9+
default: '0.1.0'
10+
type: string
11+
12+
jobs:
13+
publish:
14+
runs-on: ubuntu-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: 'zulu'
25+
cache: 'maven'
26+
27+
- name: Install GPG
28+
run: |
29+
sudo apt-get update
30+
sudo apt-get install -y gnupg
31+
32+
- name: Import GPG key
33+
run: |
34+
echo "${{ secrets.GPG_PRIVATE_KEY }}" | base64 -d > private.key
35+
gpg --batch --import private.key
36+
rm private.key
37+
echo "GPG key imported successfully"
38+
gpg --list-keys
39+
40+
- name: Configure Maven settings
41+
run: |
42+
mkdir -p ~/.m2
43+
cat > ~/.m2/settings.xml << EOF
44+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
45+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
46+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
47+
<servers>
48+
<server>
49+
<id>central</id>
50+
<username>${{ secrets.CENTRAL_USERNAME }}</username>
51+
<password>${{ secrets.CENTRAL_PASSWORD }}</password>
52+
</server>
53+
</servers>
54+
<profiles>
55+
<profile>
56+
<id>sign-artifacts</id>
57+
<properties>
58+
<gpg.passphrase>${{ secrets.GPG_PASSPHRASE }}</gpg.passphrase>
59+
</properties>
60+
</profile>
61+
</profiles>
62+
</settings>
63+
EOF
64+
65+
- name: Update version in pom.xml
66+
run: |
67+
cd clients/java
68+
mvn versions:set -DnewVersion=${{ github.event.inputs.version }}
69+
mvn versions:commit
70+
71+
- name: Build and publish to Maven Central
72+
run: |
73+
cd clients/java
74+
mvn clean deploy -Psign-artifacts -Dgpg.passphrase="${{ secrets.GPG_PASSPHRASE }}" --batch-mode
75+
env:
76+
GPG_TTY: ''
77+
GPG_AGENT_INFO: /dev/null
78+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
79+
80+
- name: Upload build artifacts
81+
if: always()
82+
uses: actions/upload-artifact@v4
83+
with:
84+
name: maven-artifacts
85+
path: |
86+
clients/java/target/*.jar
87+
clients/java/target/*.pom
88+
clients/java/target/*.asc
89+
retention-days: 1

clients/java/pom.xml

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
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>
@@ -27,23 +27,21 @@
2727
</license>
2828
</licenses>
2929

30-
<distributionManagement>
31-
<snapshotRepository>
32-
<id>ossrh</id>
33-
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
34-
</snapshotRepository>
35-
<repository>
36-
<id>ossrh</id>
37-
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
38-
</repository>
39-
</distributionManagement>
30+
<developers>
31+
<developer>
32+
<name>Qing Zhao</name>
33+
<email>zq01297892@alibaba-inc.com</email>
34+
<organization>openkruise</organization>
35+
<organizationUrl>https://github.com/openkruise/agents-api</organizationUrl>
36+
</developer>
37+
</developers>
4038

4139
<build>
4240
<plugins>
4341
<plugin>
4442
<groupId>org.apache.maven.plugins</groupId>
4543
<artifactId>maven-surefire-plugin</artifactId>
46-
<version>2.12</version>
44+
<version>3.0.0</version>
4745
<configuration>
4846
<systemProperties>
4947
<property>
@@ -52,12 +50,11 @@
5250
</property>
5351
</systemProperties>
5452
<argLine>-Xms512m -Xmx1500m</argLine>
55-
<parallel>methods</parallel>
56-
<forkMode>pertest</forkMode>
5753
</configuration>
5854
</plugin>
5955
<plugin>
6056
<artifactId>maven-dependency-plugin</artifactId>
57+
<version>3.6.1</version>
6158
<executions>
6259
<execution>
6360
<phase>package</phase>
@@ -75,23 +72,30 @@
7572
<plugin>
7673
<groupId>org.apache.maven.plugins</groupId>
7774
<artifactId>maven-jar-plugin</artifactId>
78-
<version>2.2</version>
75+
<version>3.3.0</version>
7976
<executions>
8077
<execution>
78+
<id>default-jar</id>
8179
<goals>
8280
<goal>jar</goal>
81+
</goals>
82+
</execution>
83+
<execution>
84+
<id>test-jar</id>
85+
<goals>
8386
<goal>test-jar</goal>
8487
</goals>
88+
<configuration>
89+
<classifier>tests</classifier>
90+
</configuration>
8591
</execution>
8692
</executions>
87-
<configuration>
88-
</configuration>
8993
</plugin>
9094

9195
<plugin>
9296
<groupId>org.codehaus.mojo</groupId>
9397
<artifactId>build-helper-maven-plugin</artifactId>
94-
<version>1.10</version>
98+
<version>3.5.0</version>
9599
<executions>
96100
<execution>
97101
<id>add_sources</id>
@@ -122,7 +126,7 @@
122126
<plugin>
123127
<groupId>org.apache.maven.plugins</groupId>
124128
<artifactId>maven-javadoc-plugin</artifactId>
125-
<version>2.10.4</version>
129+
<version>3.6.0</version>
126130
<executions>
127131
<execution>
128132
<id>attach-javadocs</id>
@@ -135,7 +139,7 @@
135139
<plugin>
136140
<groupId>org.apache.maven.plugins</groupId>
137141
<artifactId>maven-source-plugin</artifactId>
138-
<version>2.2.1</version>
142+
<version>3.3.0</version>
139143
<executions>
140144
<execution>
141145
<id>attach-sources</id>
@@ -145,6 +149,18 @@
145149
</execution>
146150
</executions>
147151
</plugin>
152+
<!-- Central Publishing Plugin for Maven Central -->
153+
<plugin>
154+
<groupId>org.sonatype.central</groupId>
155+
<artifactId>central-publishing-maven-plugin</artifactId>
156+
<version>0.9.0</version>
157+
<extensions>true</extensions>
158+
<configuration>
159+
<publishingServerId>central</publishingServerId>
160+
<tokenAuth>true</tokenAuth>
161+
<autoPublish>true</autoPublish>
162+
</configuration>
163+
</plugin>
148164
</plugins>
149165
</build>
150166

@@ -156,14 +172,20 @@
156172
<plugin>
157173
<groupId>org.apache.maven.plugins</groupId>
158174
<artifactId>maven-gpg-plugin</artifactId>
159-
<version>1.5</version>
175+
<version>3.1.0</version>
160176
<executions>
161177
<execution>
162178
<id>sign-artifacts</id>
163179
<phase>verify</phase>
164180
<goals>
165181
<goal>sign</goal>
166182
</goals>
183+
<configuration>
184+
<gpgArguments>
185+
<arg>--pinentry-mode</arg>
186+
<arg>loopback</arg>
187+
</gpgArguments>
188+
</configuration>
167189
</execution>
168190
</executions>
169191
</plugin>

0 commit comments

Comments
 (0)