diff --git a/.github/workflows/checkpatch.yml b/.github/workflows/checkpatch.yml deleted file mode 100644 index 5b4bad13..00000000 --- a/.github/workflows/checkpatch.yml +++ /dev/null @@ -1,31 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: checkpatch review - -# Controls when the workflow will run -on: - # Triggers the workflow on push or pull request events but only for the "main" branch - push: - branches: [ "main", "next" ] - pull_request: - branches: [ "main", "next" ] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - my_review: - name: checkpatch review - runs-on: ubuntu-latest - continue-on-error: true - steps: - - name: 'Calculate PR commits + 1' - run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> $GITHUB_ENV - - uses: actions/checkout@v3 - with: - ref: ${{ github.event.pull_request.head.sha }} - fetch-depth: ${{ env.PR_FETCH_DEPTH }} - - name: Run checkpatch review - uses: webispy/checkpatch-action@v9 - diff --git a/.github/workflows/format_check.yml b/.github/workflows/format_check.yml new file mode 100644 index 00000000..d7a7dbe8 --- /dev/null +++ b/.github/workflows/format_check.yml @@ -0,0 +1,69 @@ +name: 'Format Check' + +on: + push: + branches: + - 'main' + paths: + - '**/*.{c,cpp,cc,cxx,h,hpp}' + + pull_request: + types: + - opened + - edited + - reopened + - synchronize + branches: + - 'main' + paths: + - '**/*.{c,cpp,cc,cxx,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 + + - 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: | + 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