name: Compatibility Data Validator
description: Checks Windows compatibility data files
inputs:
  repositorySecret:
    description: GitHub token for API access
    required: true
  workingDirectory:
    description: Working directory for checks
    required: false
    default: ${{ github.workspace }}
runs:
  using: composite
  steps:
    - name: Check Runner Operating System 🏃‍♂️
      if: runner.os == 'Windows'
      shell: bash
      run: |
        : Check Runner Operating System 🏃‍♂️
        echo "services-validation action requires a macOS-based or Linux-based runner."
        exit 2

    - name: Install and Configure Python 🐍
      shell: bash
      run: |
        : Install and Configure Python 🐍
        if [[ "${RUNNER_DEBUG}" ]]; then set -x; fi

        echo ::group::Python Set Up
        if [[ "${RUNNER_OS}" == Linux ]]; then
          eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
          echo "/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin" >> $GITHUB_PATH
        fi
        brew install --quiet python3

        python3 -m venv .venv

        source .venv/bin/activate
        python3 -m pip install jsonschema json_source_map
        echo ::endgroup::

    - name: Validate Compatibility Files JSON Schema 🕵️
      shell: bash
      working-directory: ${{ inputs.workingDirectory }}
      run: |
        : Validate services file JSON schema 🕵️
        if [[ "${RUNNER_DEBUG}" ]]; then set -x; fi
        shopt -s extglob

        echo ::group::Schema Validation
        source .venv/bin/activate
        python3 -u \
          .github/scripts/utils.py/check-jsonschema.py \
          --loglevel INFO \
          plugins/win-capture/data/@(compatibility|package).json
        echo ::endgroup::

    - name: Annotate Schema Validation Errors 🏷️
      uses: yuzutech/annotations-action@0e061a6e3ac848299310b6429b60d67cafd4e7f8
      if: failure()
      with:
        repo-token: ${{ inputs.repositorySecret }}
        title: Compatibility JSON Errors
        input: ${{ inputs.workingDirectory }}/validation_errors.json
