name: Build and deploy JavaDocs

on:
  push:
    branches:
      - master

jobs:
  build-and-deploy-docs:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: set up JDK 8
        uses: actions/setup-java@v2
        with:
          java-version: '8'
          distribution: 'adopt'

      - name: Cache Gradle dependencies
        uses: actions/cache@v2
        with:
          path: ~/.gradle/caches
          key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
          restore-keys: ${{ runner.os }}-gradle

      - name: Build JavaDocs
        run: ./gradlew aggregatedJavadocs

      - name: Deploy JavaDocs
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./build/docs
