Enforce consistent coding style #2
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: Coding Style | |
| on: | |
| push: | |
| branches: [master] | |
| pull_request: | |
| branches: [master] | |
| permissions: | |
| contents: read | |
| jobs: | |
| detect-code-related-file-changes: | |
| runs-on: ubuntu-24.04 | |
| timeout-minutes: 5 | |
| outputs: | |
| has_code_related_changes: ${{ steps.filter.outputs.code }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: dorny/paths-filter@v3 | |
| id: filter | |
| with: | |
| filters: | | |
| code: | |
| - '**/*.c' | |
| - '**/*.h' | |
| - '**/*.sh' | |
| - '**/*.py' | |
| - '.clang-format' | |
| - '.ci/**' | |
| - '.github/workflows/**' | |
| coding-style: | |
| needs: [detect-code-related-file-changes] | |
| if: needs.detect-code-related-file-changes.outputs.has_code_related_changes == 'true' | |
| timeout-minutes: 10 | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Install formatting tools | |
| run: | | |
| set -euo pipefail | |
| # Install clang-format (Ubuntu 24.04 compatible GPG key method) | |
| sudo apt-get install -y gnupg | |
| sudo mkdir -p /etc/apt/keyrings | |
| # Download and verify LLVM GPG key | |
| wget -qO /tmp/llvm-snapshot.gpg.key https://apt.llvm.org/llvm-snapshot.gpg.key | |
| gpg --with-colons --import-options show-only --import /tmp/llvm-snapshot.gpg.key \ | |
| | grep -q "6084F3CF814B57C1CF12EFD515CF4D18AF4F7421" | |
| sudo gpg --dearmor -o /etc/apt/keyrings/llvm.gpg < /tmp/llvm-snapshot.gpg.key | |
| sudo chmod 644 /etc/apt/keyrings/llvm.gpg | |
| rm /tmp/llvm-snapshot.gpg.key | |
| echo "deb [signed-by=/etc/apt/keyrings/llvm.gpg] https://apt.llvm.org/noble/ llvm-toolchain-noble-20 main" \ | |
| | sudo tee /etc/apt/sources.list.d/llvm.list | |
| sudo apt-get update | |
| sudo apt-get install -y clang-format-20 | |
| # Install shfmt for shell script formatting | |
| SHFMT_URL="https://github.com/mvdan/sh/releases/download" | |
| SHFMT_VER="v3.12.0" | |
| SHFMT_SHA256="f1c0f576ae742f5486efcdb63f0c7f8c4cf491f08d8e0d34b0c7fb7a7b1c26f4" | |
| wget -qO /tmp/shfmt \ | |
| ${SHFMT_URL}/${SHFMT_VER}/shfmt_${SHFMT_VER}_linux_amd64 | |
| echo "${SHFMT_SHA256} /tmp/shfmt" | sha256sum -c | |
| chmod +x /tmp/shfmt | |
| sudo mv /tmp/shfmt /usr/local/bin/shfmt | |
| # Install black for Python formatting | |
| python3 -m pip install --upgrade pip | |
| python3 -m pip install black==24.10.0 | |
| - name: Check trailing newlines | |
| run: .ci/check-newline.sh | |
| - name: Check code formatting | |
| run: .ci/check-format.sh |