Skip to content

Commit ea2df03

Browse files
committed
doing
1 parent 9df9bf5 commit ea2df03

File tree

3 files changed

+189
-3
lines changed

3 files changed

+189
-3
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Publish package to the Maven Central Repository
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- name: Set up Maven Central Repository
13+
uses: actions/setup-java@v4
14+
with:
15+
java-version: '17'
16+
distribution: 'temurin'
17+
server-id: central
18+
server-username: MAVEN_USERNAME
19+
server-password: MAVEN_PASSWORD
20+
gpg-private-key: ${{ secrets.GPG_SIGNING_KEY }}
21+
gpg-passphrase: MAVEN_GPG_PASSPHRASE
22+
- name: Set version
23+
run: ./mvnw versions:set -DnewVersion=${{ github.event.release.tag_name }}
24+
- name: Publish package
25+
run: ./mvnw -P release --batch-mode deploy -DskipTests
26+
env:
27+
MAVEN_USERNAME: ${{ secrets.CENTRAL_TOKEN_USERNAME }}
28+
MAVEN_PASSWORD: ${{ secrets.CENTRAL_TOKEN_PASSWORD }}
29+
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_SIGNING_KEY_PASSWORD }}

RELEASE.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Release Process
2+
3+
This project is configured to automatically publish to Maven Central Repository using GitHub Actions.
4+
5+
## Prerequisites
6+
7+
Before you can publish releases, you need to set up the following:
8+
9+
### 1. Create a Sonatype Account
10+
- Register at [Maven Central Sonatype](https://central.sonatype.org/register/central-portal/#create-an-account)
11+
12+
### 2. Register a Namespace
13+
- In your Sonatype account, [register a namespace](https://central.sonatype.org/register/namespace/) for `ms.imf`
14+
15+
### 3. Generate GPG Key Pair
16+
Follow the [GPG guide](https://central.sonatype.org/publish/requirements/gpg/) to create your signing key:
17+
18+
```bash
19+
gpg --gen-key
20+
gpg --list-keys
21+
gpg --armor --export-secret-keys YOUR_KEY_ID
22+
```
23+
24+
### 4. Generate Central Token
25+
- In your Sonatype account, [generate a user token](https://central.sonatype.org/publish/generate-token/)
26+
27+
### 5. Configure GitHub Secrets
28+
Add the following secrets to your GitHub repository settings:
29+
30+
- **`CENTRAL_TOKEN_USERNAME`**: The username from your Sonatype user token
31+
- **`CENTRAL_TOKEN_PASSWORD`**: The password from your Sonatype user token
32+
- **`GPG_SIGNING_KEY`**: Your exported private GPG key (from step 3)
33+
- **`GPG_SIGNING_KEY_PASSWORD`**: The password for your GPG key
34+
35+
## Publishing a Release
36+
37+
Once the prerequisites are set up, publishing a new version is simple:
38+
39+
1. **Create a GitHub Release**:
40+
- Go to your GitHub repository
41+
- Click "Releases" → "Create a new release"
42+
- Choose a tag (e.g., `1.0.1`, `2.0.0`)
43+
- Add release notes
44+
- Click "Publish release"
45+
46+
2. **Automatic Publishing**:
47+
- The GitHub Action will automatically trigger
48+
- It will set the project version to your release tag
49+
- Build and sign the artifacts
50+
- Deploy to Maven Central Repository
51+
52+
3. **Verification**:
53+
- Check the Actions tab to monitor the deployment
54+
- Once complete, your artifact will be available on [Maven Central](https://central.sonatype.com/)
55+
56+
## Release Profiles
57+
58+
The project includes two release profiles:
59+
60+
- **`release`**: New profile for Maven Central publishing via GitHub Actions
61+
- **`legacy-release`**: Previous profile for manual releases via OSSRH
62+
63+
## Manual Release (Alternative)
64+
65+
If you prefer to release manually, you can use the legacy profile:
66+
67+
```bash
68+
mvn -P legacy-release clean deploy
69+
```
70+
71+
## Troubleshooting
72+
73+
### Common Issues:
74+
75+
1. **GPG Signing Fails**: Ensure your GPG_SIGNING_KEY secret contains the complete private key
76+
2. **Authentication Fails**: Verify your Sonatype token credentials are correct
77+
3. **Namespace Issues**: Make sure you own the `ms.imf` namespace in Sonatype
78+
79+
### Getting Help:
80+
81+
- [Maven Central Publishing Guide](https://central.sonatype.org/publish/publish-portal-maven/)
82+
- [GitHub Actions Documentation](https://docs.github.com/en/actions)

pom.xml

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,76 @@
195195
</build>
196196
<profiles>
197197
<profile>
198-
<id>release-sign-artifacts</id>
198+
<id>release</id>
199+
<build>
200+
<plugins>
201+
<plugin>
202+
<groupId>org.sonatype.central</groupId>
203+
<artifactId>central-publishing-maven-plugin</artifactId>
204+
<version>0.4.0</version>
205+
<extensions>true</extensions>
206+
<configuration>
207+
<publishingServerId>central</publishingServerId>
208+
<tokenAuth>true</tokenAuth>
209+
<autoPublish>true</autoPublish>
210+
</configuration>
211+
</plugin>
212+
<plugin>
213+
<groupId>org.apache.maven.plugins</groupId>
214+
<artifactId>maven-source-plugin</artifactId>
215+
<version>3.3.0</version>
216+
<executions>
217+
<execution>
218+
<id>attach-sources</id>
219+
<phase>verify</phase>
220+
<goals>
221+
<goal>jar-no-fork</goal>
222+
</goals>
223+
</execution>
224+
</executions>
225+
</plugin>
226+
<plugin>
227+
<groupId>org.apache.maven.plugins</groupId>
228+
<artifactId>maven-javadoc-plugin</artifactId>
229+
<version>3.6.3</version>
230+
<executions>
231+
<execution>
232+
<id>attach-javadoc</id>
233+
<goals>
234+
<goal>jar</goal>
235+
</goals>
236+
</execution>
237+
</executions>
238+
<configuration>
239+
<failOnError>false</failOnError>
240+
<additionalOptions>-Xdoclint:none</additionalOptions>
241+
</configuration>
242+
</plugin>
243+
<plugin>
244+
<groupId>org.apache.maven.plugins</groupId>
245+
<artifactId>maven-gpg-plugin</artifactId>
246+
<version>3.1.0</version>
247+
<executions>
248+
<execution>
249+
<id>sign-artifacts</id>
250+
<phase>verify</phase>
251+
<goals>
252+
<goal>sign</goal>
253+
</goals>
254+
</execution>
255+
</executions>
256+
<configuration>
257+
<gpgArguments>
258+
<arg>--pinentry-mode</arg>
259+
<arg>loopback</arg>
260+
</gpgArguments>
261+
</configuration>
262+
</plugin>
263+
</plugins>
264+
</build>
265+
</profile>
266+
<profile>
267+
<id>legacy-release</id>
199268
<activation>
200269
<property>
201270
<name>performRelease</name>
@@ -207,7 +276,7 @@
207276
<plugin>
208277
<groupId>org.apache.maven.plugins</groupId>
209278
<artifactId>maven-gpg-plugin</artifactId>
210-
<version>1.6</version>
279+
<version>3.1.0</version>
211280
<executions>
212281
<execution>
213282
<id>sign-artifacts</id>
@@ -217,6 +286,12 @@
217286
</goals>
218287
</execution>
219288
</executions>
289+
<configuration>
290+
<gpgArguments>
291+
<arg>--pinentry-mode</arg>
292+
<arg>loopback</arg>
293+
</gpgArguments>
294+
</configuration>
220295
</plugin>
221296
<plugin>
222297
<groupId>org.sonatype.plugins</groupId>
@@ -250,7 +325,7 @@
250325
<connection>scm:git:https://github.com/imfms/git-hook-maven-plugin</connection>
251326
<developerConnection>scm:git:https://github.com/imfms/git-hook-maven-plugin</developerConnection>
252327
<url>https://github.com/imfms/git-hook-maven-plugin</url>
253-
<tag>5.3</tag>
328+
<tag>HEAD</tag>
254329
</scm>
255330

256331
<organization>

0 commit comments

Comments
 (0)