name: Release to Maven Central

on:
  workflow_dispatch:

jobs:
  build:
    name: Release project
    runs-on: ubuntu-latest

    steps:

      - name: Check out sources
        uses: actions/checkout@v4

      - name: Set up JDK 17
        uses: actions/setup-java@v3
        with:
          distribution: 'temurin'
          java-version: 17
          cache: 'maven'

      - name: Install GPG key
        run: |
          echo "${{ secrets.GPG_PRIVATE_KEY }}" > gpg.asc
          echo "${{ secrets.GPG_PASSPHRASE }}" | gpg --batch --yes --passphrase-fd 0 --import gpg.asc

      - name: Release to Sonatype OSSRH
        env:
          SONATYPE_USER: ${{ secrets.OSSRH_S01_TOKEN_USERNAME }}
          SONATYPE_PASSWORD: ${{ secrets.OSSRH_S01_TOKEN_PASSWORD }}
          MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
        run: |
          ./mvnw -B clean install -DskipTests
          ./mvnw -B clean deploy -Psonatype -s settings.xml
