name: validate-docs

on:
  pull_request:
    paths:
      # existing docs
      - "docs/**"
      # changes to the cli reference generator
      - "docsgen/**"
      # potential changes to commands documentation
      - "cli/**"
      # potential changes to gRPC documentation
      - "rpc/**"
      # changes to the workflow itself
      - ".github/workflows/validate-docs.yaml"
  push:
    # At this day, GitHub doesn't support YAML anchors, d'oh!
    paths:
      - "docs/**"
      - "docsgen/**"
      - "cli/**"
      - "rpc/**"
      - ".github/workflows/validate-docs.yaml"

jobs:
  validate:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Install Taskfile
        uses: Arduino/actions/setup-taskfile@master
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}
          version: 3.x

      - name: Setup Go
        uses: actions/setup-go@v2
        with:
          go-version: "1.14"

      - name: Install Go dependencies
        run: |
          go version
          go get -u github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc

      - name: Install protoc compiler
        uses: arduino/setup-protoc@v1
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}

      - name: Setup Python
        uses: actions/setup-python@v1
        with:
          python-version: "3.8"
          architecture: "x64"

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

      - name: Install Python dependencies
        run: |
          python3 -m pip install --upgrade pip
          python3 -m pip install -r ./requirements_docs.txt

      - name: Build docs website
        # Ensure the docs build is sane, these docs won't be published
        run: task docs:build
