name: Release to Maven Central
on:
  push:
    tags:
      - v[0-9].[0-9]+.[0-9]+
jobs:
  build:
    runs-on: ubuntu-18.04
    steps:
      - name: Get OPENRNDR release tag
        run: echo "OPENRNDR_VERSION=$(git ls-remote --refs --tags https://github.com/openrndr/openrndr | cut --delimiter='/' --fields=3 | sort --version-sort | tail --lines=1)" >> $GITHUB_ENV
      - uses: actions/checkout@v2
      - name: Get the version
        id: get_version
        run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\/v/}
      - uses: actions/setup-java@v1
        with:
          java-version: 17
      - name: Build ORX
        env:
          OPENRNDR_VERSION: ${{ env.OPENRNDR_VERSION }}
        run: ./gradlew -POPENRNDR.version=${{ env.OPENRNDR_VERSION }} -Prelease.useLastTag=true build
      - name: Decode
        run: |
          echo "${{secrets.SIGNING_SECRET_KEY_RING_FILE}}" > ~/.gradle/secring.gpg.b64
          base64 -d ~/.gradle/secring.gpg.b64 > ~/.gradle/secring.gpg
      - name: Publish
        run: ./gradlew publishToSonatype -POPENRNDR.version=${{env.OPENRNDR_VERSION}} -Prelease.useLastTag=true -Psigning.keyId=${{secrets.SIGNING_KEY_ID}} -Psigning.password=openrndr -Psigning.secretKeyRingFile=$(echo ~/.gradle/secring.gpg)
        env:
          OSSRH_USERNAME: ${{secrets.OSSRH_USERNAME}}
          OSSRH_PASSWORD: ${{secrets.OSSRH_PASSWORD}}