Skip to content

Commit fead41e

Browse files
committed
Use Github actions and repository secrets to create Maven Central deployment
1 parent 073e52d commit fead41e

File tree

2 files changed

+98
-1
lines changed

2 files changed

+98
-1
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Release New Version
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
releaseVersion:
6+
description: 'Release version'
7+
required: false
8+
9+
env:
10+
MAVEN_OPTS: -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
11+
JAVA_TOOL_OPTIONS: -Duser.name=io.github.java-native
12+
GITHUB_BOT_NAME: github-actions
13+
GITHUB_BOT_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com
14+
15+
jobs:
16+
maven-central-release:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v2
20+
- run: git config --global user.email "${GITHUB_BOT_EMAIL}"
21+
- run: git config --global user.name "${GITHUB_BOT_NAME}"
22+
- name: Set up JDK 11
23+
uses: actions/setup-java@v2
24+
with:
25+
java-version: 11
26+
distribution: temurin
27+
server-id: ossrh
28+
server-username: OSSRH_TOKEN_USERNAME
29+
server-password: OSSRH_TOKEN_PASSWORD
30+
gpg-private-key: ${{ secrets.JAVA_NATIVE_PGP_KEY }}
31+
gpg-passphrase: PGP_KEY_PASSPHRASE
32+
- name: Set release version if provided as input
33+
if: github.event.inputs.releaseVersion != ''
34+
run: echo "VERSIONS=-DreleaseVersion=${{ github.event.inputs.releaseVersion }}" >> $GITHUB_ENV
35+
- name: Publish artifacts to Maven Central
36+
run: mvn -B release:prepare release:perform -P package,maven-central-release ${VERSIONS}
37+
env:
38+
OSSRH_TOKEN_USERNAME: ${{ secrets.OSSRH_TOKEN_USERNAME }}
39+
OSSRH_TOKEN_PASSWORD: ${{ secrets.OSSRH_TOKEN_PASSWORD }}
40+
PGP_KEY_PASSPHRASE: ${{ secrets.JAVA_NATIVE_PGP_KEY_PASSPHRASE }}
41+
- name: Push changes back to repo
42+
run: git push && git push --tags --force

pom.xml

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<connection>scm:git:https://github.com/java-native/jssc.git</connection>
3535
<developerConnection>scm:git:git@github.com:java-native/jssc.git</developerConnection>
3636
<url>https://github.com/java-native/jssc</url>
37+
<tag>HEAD</tag>
3738
</scm>
3839

3940
<repositories>
@@ -70,10 +71,13 @@
7071
<plugin.assembly.version>3.1.1</plugin.assembly.version>
7172
<plugin.compiler.version>3.8.0</plugin.compiler.version>
7273
<plugin.enforcer.version>3.0.0-M3</plugin.enforcer.version>
74+
<plugin.gpg.version>3.0.1</plugin.gpg.version>
7375
<plugin.jar.version>3.1.1</plugin.jar.version>
7476
<plugin.javadoc.version>3.1.1</plugin.javadoc.version>
7577
<plugin.nar.version>3.6.0</plugin.nar.version>
78+
<plugin.nexus-staging.version>1.6.7</plugin.nexus-staging.version>
7679
<plugin.osmaven.version>1.7.0</plugin.osmaven.version>
80+
<plugin.release.version>3.0.0-M4</plugin.release.version>
7781
<plugin.signature.version>1.1</plugin.signature.version>
7882
<plugin.source.version>3.0.1</plugin.source.version>
7983
<plugin.surfire.version>3.0.0-M4</plugin.surfire.version>
@@ -431,7 +435,7 @@
431435
<execution>
432436
<id>attach-sources</id>
433437
<goals>
434-
<goal>jar</goal>
438+
<goal>jar-no-fork</goal>
435439
</goals>
436440
</execution>
437441
</executions>
@@ -558,5 +562,56 @@
558562
</properties>
559563
</profile>
560564

565+
<profile>
566+
<id>maven-central-release</id>
567+
<build>
568+
<plugins>
569+
<plugin>
570+
<groupId>org.apache.maven.plugins</groupId>
571+
<artifactId>maven-gpg-plugin</artifactId>
572+
<version>${plugin.gpg.version}</version>
573+
<executions>
574+
<execution>
575+
<id>sign-artifacts</id>
576+
<phase>verify</phase>
577+
<goals>
578+
<goal>sign</goal>
579+
</goals>
580+
</execution>
581+
</executions>
582+
<configuration>
583+
<keyname>java-native</keyname>
584+
<passphraseServerId>gpg.passphrase</passphraseServerId>
585+
<gpgArguments>
586+
<arg>--pinentry-mode</arg>
587+
<arg>loopback</arg>
588+
</gpgArguments>
589+
</configuration>
590+
</plugin>
591+
<plugin>
592+
<groupId>org.apache.maven.plugins</groupId>
593+
<artifactId>maven-release-plugin</artifactId>
594+
<version>${plugin.release.version}</version>
595+
<configuration>
596+
<tagNameFormat>v@{project.version}</tagNameFormat>
597+
<pushChanges>false</pushChanges>
598+
<localCheckout>true</localCheckout>
599+
<goals>deploy</goals>
600+
</configuration>
601+
</plugin>
602+
<plugin>
603+
<groupId>org.sonatype.plugins</groupId>
604+
<artifactId>nexus-staging-maven-plugin</artifactId>
605+
<version>${plugin.nexus-staging.version}</version>
606+
<extensions>true</extensions>
607+
<configuration>
608+
<serverId>ossrh</serverId>
609+
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
610+
</configuration>
611+
</plugin>
612+
</plugins>
613+
</build>
614+
</profile>
615+
561616
</profiles>
562617
</project>

0 commit comments

Comments
 (0)