---
# This action is centrally managed in https://github.com/<organization>/.github/
# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in
# the above-mentioned repo.

name: Clang Format Lint

on:
  pull_request:
    branches: [master, nightly]
    types: [opened, synchronize, reopened]

jobs:
  check_src:
    name: Check src
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Check
        id: check
        run: |
          if [ -d "./src" ]
          then
            FOUND=true
          else
            FOUND=false
          fi

          echo "src=${FOUND}" >> $GITHUB_OUTPUT

    outputs:
      src: ${{ steps.check.outputs.src }}

  lint:
    name: Clang Format Lint
    needs: [check_src]
    if: ${{ needs.check_src.outputs.src == 'true' }}
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Clang format lint
        uses: DoozyX/clang-format-lint-action@v0.14
        with:
          source: './src'
          extensions: 'cpp,h,m,mm'
          clangFormatVersion: 13
          style: file
          inplace: false

      - name: Upload Artifacts
        if: failure()
        uses: actions/upload-artifact@v3
        with:
          name: clang-format-fixes
          path: src/
