Skip to content

Commit

Permalink
Use Github actions and repository secrets to create Maven Central dep…
Browse files Browse the repository at this point in the history
…loyment
  • Loading branch information
pietrygamat committed Aug 6, 2021
1 parent 2c9e48c commit 4558bc6
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 1 deletion.
41 changes: 41 additions & 0 deletions .github/workflows/maven-central-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Maven Central Relase
on:
workflow_dispatch:
inputs:
releaseVersion:
description: 'Release version'
required: false

env:
MAVEN_OPTS: -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
GITHUB_BOT_NAME: github-actions
GITHUB_BOT_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com

jobs:
maven-central-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: git config --global user.email "${GITHUB_BOT_EMAIL}"
- run: git config --global user.name "${GITHUB_BOT_NAME}"
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: 11
distribution: adopt
server-id: ossrh
server-username: OSSRH_TOKEN_USERNAME
server-password: OSSRH_TOKEN_PASSWORD
gpg-private-key: ${{ secrets.JAVA_NATIVE_PGP_KEY }}
gpg-passphrase: PGP_KEY_PASSPHRASE
- name: Set release version if provided as input
if: github.event.inputs.releaseVersion != ''
run: echo "VERSIONS=-DreleaseVersion=${{ github.event.inputs.releaseVersion }}" >> $GITHUB_ENV
- name: Publish artifacts to Maven Central
run: mvn -B release:prepare release:perform -P package,maven-central-release ${VERSIONS}
env:
OSSRH_TOKEN_USERNAME: ${{ secrets.OSSRH_TOKEN_USERNAME }}
OSSRH_TOKEN_PASSWORD: ${{ secrets.OSSRH_TOKEN_PASSWORD }}
PGP_KEY_PASSPHRASE: ${{ secrets.JAVA_NATIVE_PGP_KEY_PASSPHRASE }}
- name: Push changes back to repo
run: git push && git push --tags --force
56 changes: 55 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<connection>scm:git:https://github.com/java-native/jssc.git</connection>
<developerConnection>scm:git:[email protected]:java-native/jssc.git</developerConnection>
<url>https://github.com/java-native/jssc</url>
<tag>HEAD</tag>
</scm>

<repositories>
Expand Down Expand Up @@ -70,9 +71,11 @@
<plugin.assembly.version>3.1.1</plugin.assembly.version>
<plugin.compiler.version>3.8.0</plugin.compiler.version>
<plugin.enforcer.version>3.0.0-M3</plugin.enforcer.version>
<plugin.gpg.version>3.0.1</plugin.gpg.version>
<plugin.jar.version>3.1.1</plugin.jar.version>
<plugin.javadoc.version>3.1.1</plugin.javadoc.version>
<plugin.nar.version>3.6.0</plugin.nar.version>
<plugin.nexus-staging.version>1.6.7</plugin.nexus-staging.version>
<plugin.osmaven.version>1.7.0</plugin.osmaven.version>
<plugin.signature.version>1.1</plugin.signature.version>
<plugin.source.version>3.0.1</plugin.source.version>
Expand Down Expand Up @@ -431,7 +434,7 @@
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
Expand Down Expand Up @@ -558,5 +561,56 @@
</properties>
</profile>

<profile>
<id>maven-central-release</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>${plugin.gpg.version}</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
<configuration>
<keyname>java-native</keyname>
<passphraseServerId>gpg.passphrase</passphraseServerId>
<gpgArguments>
<arg>--pinentry-mode</arg>
<arg>loopback</arg>
</gpgArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<tagNameFormat>v@{project.version}</tagNameFormat>
<pushChanges>false</pushChanges>
<localCheckout>true</localCheckout>
<goals>deploy</goals>
</configuration>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>${plugin.nexus-staging.version}</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
</configuration>
</plugin>
</plugins>
</build>
</profile>

</profiles>
</project>

0 comments on commit 4558bc6

Please sign in to comment.