name: Publish Release
on:
  release:
    types:
      - prereleased
      - released
env:
  ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SONATYPE_SIGNING_KEY }}
  ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SONATYPE_SIGNING_PASSWORD }}
jobs:
  publish-to-nexus:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-java@v3
        with:
          distribution: 'adopt'
          java-version: '17'
      - name: Publlish to Maven Central
        uses: burrunan/gradle-cache-action@v1
        with:
          gradle-version: wrapper
          arguments: publishToSonatype closeAndReleaseSonatypeStagingRepository
          properties: |
            release=true
        env:
          ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_USER }}
          ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_PASSWORD }}
  build-documentation:
    runs-on: ubuntu-latest
    needs:
      - publish-to-nexus
    steps:
      - uses: actions/checkout@v2
        with:
          token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
      - uses: actions/setup-java@v3
        with:
          distribution: 'adopt'
          java-version: '17'
      - name: Build New Documentation
        uses: burrunan/gradle-cache-action@v1
        with:
          gradle-version: wrapper
          arguments: dokkaHtmlMultiModule
          properties: |
            release=true
      - name: Push New Documentation
        uses: EndBug/add-and-commit@v8
        with:
          default_author: github_actions
          new_branch: main
          message: 'doc: Added Latest Documentation ✨'
