Skip to content

Commit 282cfee

Browse files
author
zhanq
committed
feat: add Maven project metadata and release automation configuration
1 parent 42a1eec commit 282cfee

File tree

4 files changed

+344
-97
lines changed

4 files changed

+344
-97
lines changed

.github/workflows/release.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Release to Maven Central
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*' # 当推送以 v 开头的标签时触发,如 v5.2.5
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: 检出代码
17+
uses: actions/checkout@v4
18+
19+
- name: 设置 JDK 8
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+
28+
- name: 配置 GPG
29+
uses: crazy-max/ghaction-import-gpg@v6
30+
with:
31+
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
32+
passphrase: ${{ secrets.GPG_PASSPHRASE }}
33+
34+
- name: 获取版本号
35+
id: get_version
36+
run: |
37+
VERSION=${GITHUB_REF#refs/tags/v}
38+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
39+
echo "发布版本: $VERSION"
40+
41+
- name: 更新版本号
42+
run: |
43+
VERSION=${{ steps.get_version.outputs.VERSION }}
44+
# 更新根 pom.xml 版本
45+
mvn versions:set -DnewVersion=$VERSION -DgenerateBackupPoms=false
46+
# 更新子模块版本
47+
mvn versions:update-child-modules -DgenerateBackupPoms=false
48+
49+
- name: 编译
50+
run: mvn clean compile -pl jiguang-sdk
51+
52+
- name: 发布到 Maven Central
53+
run: |
54+
mvn clean deploy -P release -pl jiguang-sdk -DskipTests
55+
env:
56+
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
57+
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
58+
GPG_TTY: $(tty)
59+
60+
- name: 发布结果通知
61+
if: success()
62+
run: |
63+
echo "✅ jiguang-sdk v${{ steps.get_version.outputs.VERSION }} 已成功发布到 Maven Central"
64+
echo "📦 可通过以下依赖使用:"
65+
echo "<dependency>"
66+
echo " <groupId>io.github.jpush</groupId>"
67+
echo " <artifactId>jiguang-sdk</artifactId>"
68+
echo " <version>${{ steps.get_version.outputs.VERSION }}</version>"
69+
echo "</dependency>"
70+
71+
- name: 失败通知
72+
if: failure()
73+
run: |
74+
echo "❌ 发布失败,请检查日志"

RELEASE.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# 自动发布配置说明
2+
3+
本文档说明如何配置和使用自动发布流程,将 `jiguang-sdk` 自动发布到 Maven Central。
4+
5+
## 配置步骤
6+
7+
### 1. 配置 GitHub Secrets
8+
9+
在 GitHub 仓库的 Settings > Secrets and variables > Actions 中添加以下 secrets:
10+
11+
#### Maven Central 相关
12+
- `OSSRH_USERNAME`: Sonatype OSSRH 用户名
13+
- `OSSRH_TOKEN`: Sonatype OSSRH 密码或令牌
14+
15+
#### GPG 签名相关
16+
- `GPG_PRIVATE_KEY`: GPG 私钥(完整的 ASCII 格式)
17+
- `GPG_PASSPHRASE`: GPG 私钥的密码短语
18+
19+
### 2. GPG 密钥生成和配置
20+
21+
如果还没有 GPG 密钥,请按照以下步骤生成:
22+
23+
```bash
24+
# 生成 GPG 密钥对
25+
gpg --full-generate-key
26+
27+
# 选择:
28+
# - 密钥类型:RSA and RSA (default)
29+
# - 密钥大小:4096
30+
# - 有效期:0 (不过期) 或根据需要设置
31+
# - 输入用户信息(姓名、邮箱等)
32+
# - 设置密码短语
33+
34+
# 查看生成的密钥
35+
gpg --list-secret-keys --keyid-format LONG
36+
37+
# 导出私钥(用于 GPG_PRIVATE_KEY)
38+
gpg --armor --export-secret-keys YOUR_KEY_ID
39+
40+
# 导出公钥并上传到密钥服务器
41+
gpg --armor --export YOUR_KEY_ID
42+
gpg --send-keys YOUR_KEY_ID --keyserver keys.openpgp.org
43+
```
44+
45+
### 3. Maven Central 账户配置
46+
47+
确保已经在 Sonatype OSSRH 注册并验证了域名 `io.github.jpush`
48+
49+
## 使用方法
50+
51+
### 发布新版本
52+
53+
1. **更新版本号**
54+
```bash
55+
# 更新根目录和 jiguang-sdk 模块的版本号
56+
mvn versions:set -DnewVersion=5.2.5 -DgenerateBackupPoms=false
57+
mvn versions:update-child-modules -DgenerateBackupPoms=false
58+
```
59+
60+
2. **提交更改**
61+
```bash
62+
git add .
63+
git commit -m "release: 准备发布版本 5.2.5"
64+
git push origin main
65+
```
66+
67+
3. **打标签触发发布**
68+
```bash
69+
git tag v5.2.5
70+
git push origin v5.2.5
71+
```
72+
73+
### 自动化流程
74+
75+
当推送标签后,GitHub Actions 会自动执行以下步骤:
76+
77+
1. ✅ 检出代码
78+
2. ✅ 设置 JDK 8 环境
79+
3. ✅ 配置 GPG 签名
80+
4. ✅ 从标签获取版本号
81+
5. ✅ 更新项目版本号
82+
6. ✅ 编译和测试 jiguang-sdk 模块
83+
7. ✅ 使用 release profile 发布到 Maven Central
84+
8. ✅ 发布结果通知
85+
86+
## 验证发布
87+
88+
发布成功后,可以通过以下方式验证:
89+
90+
1. **检查 Maven Central**
91+
访问 https://central.sonatype.com/artifact/io.github.jpush/jiguang-sdk 查看新版本
92+
93+
2. **本地测试**
94+
```xml
95+
<dependency>
96+
<groupId>io.github.jpush</groupId>
97+
<artifactId>jiguang-sdk</artifactId>
98+
<version>5.2.5</version>
99+
</dependency>
100+
```
101+
102+
## 注意事项
103+
104+
### 版本规范
105+
- 标签格式:`v{version}`(如 `v5.2.5`
106+
- 版本号遵循语义化版本规范:`MAJOR.MINOR.PATCH`
107+
108+
### 发布限制
109+
- 只发布 `jiguang-sdk` 模块,不包含示例项目
110+
- 自动签名并上传源码包和文档包
111+
- 发布后自动释放到 Maven Central(约需 10-30 分钟同步)
112+
113+
### 故障排查
114+
- 检查 GitHub Actions 日志
115+
- 确认所有 secrets 配置正确
116+
- 验证 GPG 密钥和 Maven Central 权限
117+
118+
## 手动发布(备用方案)
119+
120+
如果自动发布失败,可以使用手动方式:
121+
122+
```bash
123+
# 本地发布到 Maven Central
124+
mvn clean deploy -P release -pl jiguang-sdk -DskipTests
125+
126+
# 或者先部署到暂存区
127+
mvn clean deploy -P release -pl jiguang-sdk -DskipTests -DaltDeploymentRepository=ossrh::default::https://s01.oss.sonatype.org/content/repositories/snapshots
128+
```
129+
130+
---
131+
132+
📝 **重要提醒**:首次配置时,请先在测试分支验证流程,确保所有配置正确后再在主分支使用。

jiguang-sdk/pom.xml

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,45 @@
2626
<jackson-datatype-jsr310.version>2.15.3</jackson-datatype-jsr310.version>
2727
</properties>
2828

29+
<name>Jiguang SDK</name>
30+
<description>Jiguang SDK For Rest API</description>
31+
<url>https://github.com/jpush/jiguang-sdk-java</url>
32+
33+
<licenses>
34+
<license>
35+
<name>MIT License</name>
36+
<url>https://github.com/jpush/jiguang-sdk-java/blob/main/LICENSE</url>
37+
<distribution>repo</distribution>
38+
</license>
39+
</licenses>
40+
41+
<developers>
42+
<developer>
43+
<id>jpush</id>
44+
<name>JPush</name>
45+
<email>[email protected]</email>
46+
<organization>Jiguang</organization>
47+
<organizationUrl>https://www.jiguang.cn</organizationUrl>
48+
</developer>
49+
</developers>
50+
51+
<scm>
52+
<connection>scm:git:git://github.com/jpush/jiguang-sdk-java.git</connection>
53+
<developerConnection>scm:git:ssh://github.com/jpush/jiguang-sdk-java.git</developerConnection>
54+
<url>https://github.com/jpush/jiguang-sdk-java/tree/main</url>
55+
</scm>
56+
57+
<distributionManagement>
58+
<snapshotRepository>
59+
<id>ossrh</id>
60+
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
61+
</snapshotRepository>
62+
<repository>
63+
<id>ossrh</id>
64+
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
65+
</repository>
66+
</distributionManagement>
67+
2968
<dependencies>
3069
<!-- lombok -->
3170
<dependency>
@@ -80,4 +119,103 @@
80119
</dependency>
81120
</dependencies>
82121

122+
<build>
123+
<plugins>
124+
<!-- 编译插件 -->
125+
<plugin>
126+
<groupId>org.apache.maven.plugins</groupId>
127+
<artifactId>maven-compiler-plugin</artifactId>
128+
<version>3.11.0</version>
129+
<configuration>
130+
<source>8</source>
131+
<target>8</target>
132+
<encoding>UTF-8</encoding>
133+
</configuration>
134+
</plugin>
135+
136+
<!-- 源码包插件 -->
137+
<plugin>
138+
<groupId>org.apache.maven.plugins</groupId>
139+
<artifactId>maven-source-plugin</artifactId>
140+
<version>3.3.0</version>
141+
<executions>
142+
<execution>
143+
<id>attach-sources</id>
144+
<goals>
145+
<goal>jar-no-fork</goal>
146+
</goals>
147+
</execution>
148+
</executions>
149+
</plugin>
150+
151+
<!-- 文档包插件 -->
152+
<plugin>
153+
<groupId>org.apache.maven.plugins</groupId>
154+
<artifactId>maven-javadoc-plugin</artifactId>
155+
<version>3.5.0</version>
156+
<configuration>
157+
<encoding>UTF-8</encoding>
158+
<charset>UTF-8</charset>
159+
<docencoding>UTF-8</docencoding>
160+
<failOnError>false</failOnError>
161+
<failOnWarnings>false</failOnWarnings>
162+
<quiet>true</quiet>
163+
</configuration>
164+
<executions>
165+
<execution>
166+
<id>attach-javadocs</id>
167+
<goals>
168+
<goal>jar</goal>
169+
</goals>
170+
</execution>
171+
</executions>
172+
</plugin>
173+
</plugins>
174+
</build>
175+
176+
<profiles>
177+
<!-- 发布配置 -->
178+
<profile>
179+
<id>release</id>
180+
<build>
181+
<plugins>
182+
<!-- GPG 签名插件 -->
183+
<plugin>
184+
<groupId>org.apache.maven.plugins</groupId>
185+
<artifactId>maven-gpg-plugin</artifactId>
186+
<version>3.1.0</version>
187+
<executions>
188+
<execution>
189+
<id>sign-artifacts</id>
190+
<phase>verify</phase>
191+
<goals>
192+
<goal>sign</goal>
193+
</goals>
194+
<configuration>
195+
<gpgArguments>
196+
<arg>--pinentry-mode</arg>
197+
<arg>loopback</arg>
198+
</gpgArguments>
199+
</configuration>
200+
</execution>
201+
</executions>
202+
</plugin>
203+
204+
<!-- Nexus 部署插件 -->
205+
<plugin>
206+
<groupId>org.sonatype.plugins</groupId>
207+
<artifactId>nexus-staging-maven-plugin</artifactId>
208+
<version>1.6.13</version>
209+
<extensions>true</extensions>
210+
<configuration>
211+
<serverId>ossrh</serverId>
212+
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
213+
<autoReleaseAfterClose>true</autoReleaseAfterClose>
214+
</configuration>
215+
</plugin>
216+
</plugins>
217+
</build>
218+
</profile>
219+
</profiles>
220+
83221
</project>

0 commit comments

Comments
 (0)