Publish #106
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish | |
on: | |
release: | |
types: [ published ] | |
workflow_dispatch: | |
inputs: | |
versionTag: | |
type: string | |
description: Version tag to use for the Maven JAR, e.g. "v1.0.12", "1.1.0-rc1" (no quotes) | |
required: true | |
releaseType: | |
description: 'Release type' | |
required: true | |
default: 'prerelease' | |
type: choice | |
options: | |
- prerelease | |
- release | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
build_and_publish: | |
name: Build and Publish Jar | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Get version tag | |
run: | | |
# Default to using the tag from the release event for the version string, stripping the prefix | |
VERSION=$( echo ${{ github.event.release.tag_name }} | sed -e 's/^v//' ) | |
# If there is no associated release event, use the input version string, still stripping the prefix | |
if [ "$VERSION" == "" ] ; then | |
VERSION=$( echo ${{ github.event.inputs.versionTag }} | sed -e 's/^v//' ) | |
fi | |
# Store version for later use. | |
echo "VERSION=$VERSION" | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: 11 | |
distribution: 'temurin' | |
- name: Build with Gradle | |
run: ./gradlew clean build --refresh-dependencies -Pversion=$VERSION | |
- name: Install gpg secret key | |
run: | | |
export GPG_TTY=$(tty) | |
echo -n "${{ secrets.OSSRH_GPG_SECRET_KEY }}" | base64 --decode | gpg --batch --import | |
gpg --list-secret-keys --keyid-format LONG | |
echo -n "${{ secrets.OSSRH_GPG_SECRET_KEY }}" | base64 --decode > $GITHUB_WORKSPACE/release.gpg | |
- name: Publish to Maven Central | |
run: | | |
./gradlew publishToSonatype $(if [ "${{github.event.release.prerelease}}" = "true" || "${{github.event.inputs.releaseType}}" = "prerelease" ]; then echo 'closeSonatypeStagingRepository'; else echo 'closeAndReleaseSonatypeStagingRepository'; fi) \ | |
-Pversion=$VERSION \ | |
-Psigning.keyId=B7D30ABE -Psigning.password="${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}" \ | |
-Psigning.secretKeyRingFile=$GITHUB_WORKSPACE/release.gpg \ | |
--info | |
env: | |
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} | |
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} |