name: Reusable Fast Checks

on:
  workflow_call:

permissions:
  contents: read
  checks: write
  pull-requests: read

jobs:
  run-checks:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v6
        with:
          fetch-depth: 0

      - name: Setup reviewdog
        uses: reviewdog/action-setup@v1.5.0

      - name: Setup dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y cppcheck libxml2-utils lua-check luajit yamllint

      - name: Run yamllint
        run: yamllint -c .yamllint.yaml .github

      - name: Run analysis with reviewdog
        if: github.event.pull_request != null && github.event.pull_request.head.repo.full_name == github.repository
        env:
          REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          REVIEWDOG_REPORTER: github-pr-check
        run: |
          reviewdog -reporter="${REVIEWDOG_REPORTER}" -runners=luac -fail-level=error -filter-mode=added
          reviewdog -reporter="${REVIEWDOG_REPORTER}" -runners=luacheck -filter-mode=added || true
          reviewdog -reporter="${REVIEWDOG_REPORTER}" -runners=xmllint -fail-level=error -filter-mode=added
          reviewdog -reporter="${REVIEWDOG_REPORTER}" -runners=cppcheck -filter-mode=added || true
