github: Add format check. #6
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 'Format Check' | |
on: | |
push: | |
branches: | |
- 'main' | |
paths: | |
- '**/*.c' | |
- '**/*.cpp' | |
- '**/*.h' | |
- '**/*.hpp' | |
pull_request: | |
types: | |
- opened | |
- edited | |
- reopened | |
- synchronize | |
branches: | |
- 'main' | |
paths: | |
- '**/*.c' | |
- '**/*.cpp' | |
- '**/*.h' | |
- '**/*.hpp' | |
workflow_dispatch: | |
inputs: | |
logLevel: | |
description: 'Log level' | |
required: true | |
default: 'warning' | |
jobs: | |
format-check: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
submodules: false | |
persist-credentials: false | |
- name: Install clang-format | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y clang-format colordiff | |
- name: Get changed files | |
id: changed-files | |
uses: tj-actions/changed-files@v46 | |
with: | |
files: | | |
cores/arduino/**/*.{c,cpp,cc,cxx,h,hpp} | |
!cores/arduino/api/** | |
loader/**/*.{c,cpp,cc,cxx,h,hpp} | |
!loader/llext_exports.c | |
libraries/**/*.{c,cpp,cc,cxx,h,hpp} | |
- name: Run clang-format check | |
if: steps.changed-files.outputs.any_changed == 'true' | |
run: | | |
clang-format --version | |
exit_code=0 | |
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do | |
file_fmt="${file}.tmp" | |
clang-format ${file} > ${file_fmt} | |
diff -q -u ${file} ${file_fmt} >> /dev/null 2>&1 || { | |
echo "❌ Formatting issues found in: $file" | |
colordiff -u ${file} ${file_fmt} || true | |
exit_code=1 | |
} | |
done | |
exit $exit_code |