name: Documentation

on:
  push:
    branches:
      - main
  pull_request:

jobs:
  docs:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Setup Lua
        uses: leafo/gh-actions-lua@v8
        with:
          luaVersion: 5.4
      - name: Install LDoc
        uses: leafo/gh-actions-luarocks@v4
      - name: Setup dependencies
        run: luarocks install ldoc
      - name: Build Docs
        run: |
          ldoc .
      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        if: ${{ github.ref == 'refs/heads/main' }}
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./docs
