Skip to content

Commit 696c01b

Browse files
committed
build:add gitHub workflow
1 parent 1dbd312 commit 696c01b

3 files changed

Lines changed: 177 additions & 18 deletions

File tree

.github/workflows/ci.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
branches: [main, master]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Java
18+
uses: actions/setup-java@v4
19+
with:
20+
java-version: '21'
21+
distribution: 'temurin'
22+
cache: maven
23+
24+
- name: Build and test
25+
run: mvn --batch-mode clean verify
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Publish to Maven Central
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
inputs:
8+
version:
9+
description: Release version without v prefix (e.g. 1.0.2)
10+
required: true
11+
type: string
12+
13+
jobs:
14+
publish:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
23+
- name: Resolve version
24+
run: |
25+
if [ "${{ github.event_name }}" = "release" ]; then
26+
VERSION="${{ github.event.release.tag_name }}"
27+
else
28+
VERSION="${{ inputs.version }}"
29+
fi
30+
VERSION="${VERSION#v}"
31+
echo "Publishing version: $VERSION"
32+
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
33+
34+
- name: Set up Java
35+
uses: actions/setup-java@v4
36+
with:
37+
java-version: '21'
38+
distribution: 'temurin'
39+
cache: maven
40+
server-id: central
41+
server-username: MAVEN_USERNAME
42+
server-password: MAVEN_PASSWORD
43+
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
44+
gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }}
45+
46+
- name: Set project version
47+
run: mvn --batch-mode versions:set -DnewVersion="$VERSION" -DgenerateBackupPoms=false
48+
49+
- name: Publish to Maven Central
50+
run: mvn --batch-mode clean deploy -Prelease -DskipTests
51+
env:
52+
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
53+
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
54+
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}

pom.xml

Lines changed: 98 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222
<distribution>repo</distribution>
2323
</license>
2424
</licenses>
25+
26+
<developers>
27+
<developer>
28+
<name>top-kgame</name>
29+
<email>chinazhangk@gmail.com</email>
30+
<organization>top-kgame</organization>
31+
<organizationUrl>https://github.com/top-kgame</organizationUrl>
32+
</developer>
33+
</developers>
34+
2535
<!-- SCM信息(便于开发跟踪) -->
2636
<scm>
2737
<!-- 只读访问URL -->
@@ -41,6 +51,7 @@
4151
<maven.compiler.release>21</maven.compiler.release> <!-- 确保使用JDK21的API -->
4252
<java.version>21</java.version>
4353
<log4j.version>2.25.3</log4j.version>
54+
<central-publishing.version>0.11.0</central-publishing.version>
4455
</properties>
4556

4657
<!-- 依赖管理 -->
@@ -72,22 +83,21 @@
7283
</dependencies>
7384

7485
<!-- 构建配置 -->
86+
<pluginRepositories>
87+
<pluginRepository>
88+
<id>central-direct</id>
89+
<url>https://repo.maven.apache.org/maven2</url>
90+
<releases>
91+
<enabled>true</enabled>
92+
</releases>
93+
<snapshots>
94+
<enabled>false</enabled>
95+
</snapshots>
96+
</pluginRepository>
97+
</pluginRepositories>
98+
7599
<build>
76100
<plugins>
77-
<!-- 必须配置源码和Javadoc打包 -->
78-
<plugin>
79-
<groupId>org.apache.maven.plugins</groupId>
80-
<artifactId>maven-source-plugin</artifactId>
81-
<version>3.3.0</version>
82-
<executions>
83-
<execution>
84-
<id>attach-sources</id>
85-
<goals>
86-
<goal>jar-no-fork</goal>
87-
</goals>
88-
</execution>
89-
</executions>
90-
</plugin>
91101
<!-- 模块化支持(Java 9+) -->
92102
<plugin>
93103
<groupId>org.apache.maven.plugins</groupId>
@@ -113,10 +123,80 @@
113123
</build>
114124

115125
<distributionManagement>
116-
<repository>
117-
<id>github</id>
118-
<url>https://maven.pkg.github.com/top-kgame/GServerECS</url>
119-
</repository>
126+
<repository>
127+
<id>github</id>
128+
<url>https://maven.pkg.github.com/top-kgame/GServerECS</url>
129+
</repository>
120130
</distributionManagement>
121131

132+
<profiles>
133+
<profile>
134+
<id>release</id>
135+
<build>
136+
<plugins>
137+
<plugin>
138+
<groupId>org.apache.maven.plugins</groupId>
139+
<artifactId>maven-source-plugin</artifactId>
140+
<version>3.3.1</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+
<plugin>
151+
<groupId>org.apache.maven.plugins</groupId>
152+
<artifactId>maven-javadoc-plugin</artifactId>
153+
<version>3.6.3</version>
154+
<executions>
155+
<execution>
156+
<id>attach-javadocs</id>
157+
<goals>
158+
<goal>jar</goal>
159+
</goals>
160+
</execution>
161+
</executions>
162+
<configuration>
163+
<source>21</source>
164+
<doclint>none</doclint>
165+
</configuration>
166+
</plugin>
167+
<plugin>
168+
<groupId>org.apache.maven.plugins</groupId>
169+
<artifactId>maven-gpg-plugin</artifactId>
170+
<version>3.2.4</version>
171+
<executions>
172+
<execution>
173+
<id>sign-artifacts</id>
174+
<phase>verify</phase>
175+
<goals>
176+
<goal>sign</goal>
177+
</goals>
178+
<configuration>
179+
<gpgArguments>
180+
<arg>--pinentry-mode</arg>
181+
<arg>loopback</arg>
182+
</gpgArguments>
183+
</configuration>
184+
</execution>
185+
</executions>
186+
</plugin>
187+
<plugin>
188+
<groupId>org.sonatype.central</groupId>
189+
<artifactId>central-publishing-maven-plugin</artifactId>
190+
<version>${central-publishing.version}</version>
191+
<extensions>true</extensions>
192+
<configuration>
193+
<publishingServerId>central</publishingServerId>
194+
<deploymentName>${project.artifactId}-${project.version}</deploymentName>
195+
</configuration>
196+
</plugin>
197+
</plugins>
198+
</build>
199+
</profile>
200+
</profiles>
201+
122202
</project>

0 commit comments

Comments
 (0)