name: Coding Style

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  clang-format:
    runs-on: ubuntu-latest

    container:
      image: opensuse/tumbleweed

    steps:
    - name: dependencies
      run: zypper -n install clang git findutils file
    - uses: actions/checkout@v2
    - name: format
      run: find -type f \( -name "*.[c|h]" -or -name "*.cc" \) -exec clang-format -style=file -i {} \;
    - name: verify
      run: /bin/bash -c "git status --short | file - | grep empty"
      id: verify
    - name: diagnostics
      if: failure() && steps.verify.outcome == 'failure'
      run: git diff
