name: publish-documentation

on:
  push:
    branches: [ master ]
  workflow_dispatch:

jobs:
  publish:
    runs-on: ubuntu-latest

    steps:
      - name: Repository checkout
        uses: actions/checkout@v3
      - name: JDK setup
        uses: actions/setup-java@v3
        with:
          java-version: 11
          distribution: temurin
      - name: Save version
        shell: bash
        run: |
          echo "KTX_VERSION=$(cat version.txt)" >> $GITHUB_ENV
      - name: Gradle setup
        uses: gradle/gradle-build-action@v2
      - name: Dokka
        run: ./gradlew dokkaHtmlMultiModule
      - name: Publish GitHub pages
        uses: JamesIves/github-pages-deploy-action@releases/v4
        with:
          token: ${{ secrets.accessToken }}
          branch: gh-pages
          folder: build/dokka/htmlMultiModule
          repository-name: libktx/docs
          commit-message: 'Documentation of KTX ${{ env.KTX_VERSION }}.'
