name: Docs

on:
  push:
    branches: [main]
    paths:
      - .github/workflows/docs.yml
      - docs/**
      - website/**

  pull_request:
    branches: [main]
    paths:
      - .github/workflows/docs.yml
      - docs/**
      - website/**

jobs:
  lint:
    name: Lint
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      - uses: actions/cache@v3
        with:
          path: |
            /usr/local/bin/vale*
          key: ${{ runner.os }}-docs-lint-tools
          restore-keys: |
            ${{ runner.os }}-docs-lint-tools

      - name: Install Vale
        run: |
          python -m venv venv && source venv/bin/activate
          pip install gh-release-install

          sudo venv/bin/gh-release-install \
            errata-ai/vale \
            vale_{version}_Linux_64-bit.tar.gz --extract vale \
            /usr/local/bin/vale \
            --version-file '{destination}.version'

      - name: Add annotations matchers
        run: |
          echo "::add-matcher::.github/annotations/vale.json"

      - name: Run Vale
        run: |
          make -C .github/vale/styles
          vale --output line docs website/src/pages || true
