name: Build Docs
on:
  push:
  release:
    types: [published]

jobs:
  docs:
    runs-on: ubuntu-latest
    if: github.event_name == 'release' || contains(github.event.head_commit.message, 'build docs')
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '7.4'
          extensions: iconv
          tools: phive
      - name: Install phpDocumentor
        run: phive install phpDocumentor --trust-gpg-keys 67F861C3D889C656,6DA3ACC4991FFAE5
      - name: Build class reference
        run: ./tools/phpDocumentor
      - name: Build documentation
        run: |
          cd ./docs
          yarn install
          yarn build
          sudo mv public/* ../build
      - name: Publish docs
        uses: JamesIves/github-pages-deploy-action@3.7.1
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          BRANCH: gh-pages
          FOLDER: build
          CLEAN: true
