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 7, 2021
1 parent 003dd4f commit 7ecae98
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
42 changes: 42 additions & 0 deletions .github/workflows/release-new-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Release New Version
on:
workflow_dispatch:
inputs:
releaseVersion:
description: 'Release version'
required: false

env:
MAVEN_OPTS: -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
JAVA_TOOL_OPTIONS: -Duser.name=io.github.java-native
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
57 changes: 56 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:git@github.com:java-native/jssc.git</developerConnection>
<url>https://github.com/java-native/jssc</url>
<tag>HEAD</tag>
</scm>

<repositories>
Expand Down Expand Up @@ -70,10 +71,13 @@
<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.release.version>3.0.0-M4</plugin.release.version>
<plugin.signature.version>1.1</plugin.signature.version>
<plugin.source.version>3.0.1</plugin.source.version>
<plugin.surfire.version>3.0.0-M4</plugin.surfire.version>
Expand Down Expand Up @@ -431,7 +435,7 @@
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
Expand Down Expand Up @@ -558,5 +562,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>${plugin.release.version}</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 7ecae98

Please sign in to comment.