name: Verifies documentation links

on:
  push:
  pull_request:
  schedule:
    - cron: "0 3 * * 1" # Every Monday at 03:00

jobs:
  verify-links:
    # Don't trigger on schedule event when in a fork
    if: github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository == 'arduino/arduino-cli')
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 1

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

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

      - name: Installs Go dependencies
        shell: bash
        run: 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
        run: task docs:build

      - name: Verify links
        run: task docs:check-links
