name: Validate content with Vale

on:
  pull_request:
    paths:
      - 'content/**'

  # Allows manual workflow run (must in default branch to work)
  workflow_dispatch:

jobs:
  lint-content:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout the docs repo
        uses: actions/checkout@v3

      - name: Get changed files
        id: changed-files
        uses: tj-actions/changed-files@v35
        with:
          files: content/**

      - name: Install Vale
        env:
          VALE_VERSION: "2.22.0"
        run: wget https://github.com/errata-ai/vale/releases/download/v${{env.VALE_VERSION}}/vale_${{env.VALE_VERSION}}_Linux_64-bit.tar.gz && tar -xvzf vale_${{env.VALE_VERSION}}_Linux_64-bit.tar.gz

      - name: Run Vale
        if: steps.changed-files.outputs.any_changed == 'true'
        # Run vale and display the output. Fail if the output is greater than 1 line.
        # Vale uses a 0 return code for warnings and suggestions. These should be considered failures.
        run: |
          ./vale --config="./utils/vale/.vale.ini" ${{ steps.changed-files.outputs.all_changed_files }} | tee /dev/stderr | wc -l | { read wc; test $wc -eq 1; }
