name: clang-format-check

on:
  workflow_dispatch:
  pull_request:
    branches:
      - 'develop'

concurrency:
  # Cancel in-progress jobs for the same pull request
  group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
  cancel-in-progress: true

jobs:
  format:
    runs-on: ubuntu-24.04
    steps:

    - name: Checkout
      uses: actions/checkout@v4
      with:
        fetch-depth: 0
        submodules: false

    - name: Update References
      shell: bash
      run: |
        git fetch origin develop

    - name: Setup Ubuntu Environment
      shell: bash
      run: |
        sudo apt-get install clang-format-19
        sudo rm -f /usr/bin/clang-format
        sudo ln -s /usr/bin/clang-format-19 /usr/bin/clang-format

    - name: Check Formatting
      shell: bash
      run: |
        MERGE_BASE=$(git merge-base origin/develop ${{ github.event.pull_request.head.sha || github.ref }})
        echo "Comparing against ${MERGE_BASE}"
        git clang-format-19 --diff --style=file -v ${MERGE_BASE}
