name: Check formatting

on:
  push:
    branches:
      - main
  pull_request:

jobs:
  check-qml:
    runs-on: ubuntu-latest
    container:
      image: ghcr.io/${{ github.repository_owner }}/shell-arch-env:latest

    steps:
      - uses: actions/checkout@v6

      - name: Check QML format
        shell: fish {0}
        run: |
          /usr/lib/qt6/bin/qmlformat --version
          for file in (string match -v 'build/*' **.qml)
            /usr/lib/qt6/bin/qmlformat $file | diff -u $file - || exit 1
          end
          python3 scripts/qml-lint-conventions.py

  check-cpp:
    runs-on: ubuntu-latest
    container:
      image: ghcr.io/${{ github.repository_owner }}/shell-arch-env:latest

    steps:
      - uses: actions/checkout@v6

      - name: Check C++ format
        shell: fish {0}
        run: |
          clang-format --version
          find plugin extras -name '*.cpp' -o -name '*.hpp' \
            | xargs clang-format --dry-run --Werror
