diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 0000000..6d594a9 --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,26 @@ +name: Format + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + clang-format: + + runs-on: ubuntu-latest + permissions: + contents: read + + steps: + - uses: actions/checkout@v7 + + # Pinned so a new clang-format release cannot reformat the tree in CI. + - name: Install clang-format + run: sudo apt-get install -y clang-format-18 + + - name: Check formatting + env: + CLANG_FORMAT: clang-format-18 + run: ./format.sh --check diff --git a/format.sh b/format.sh new file mode 100755 index 0000000..e4eebd3 --- /dev/null +++ b/format.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +# Formats the shader sources in place with clang-format. +# Pass --check to report problems without writing. +# Set CLANG_FORMAT to pick a version, e.g. CLANG_FORMAT=clang-format-18. + +: "${CLANG_FORMAT:=clang-format}" + +if [ "$1" = "--check" ]; then + shift + set -- --dry-run --Werror "$@" +else + set -- -i "$@" +fi + +find shaders -type f \( -name '*.fsh' -o -name '*.vsh' -o -name '*.glsl' \) -exec "$CLANG_FORMAT" "$@" -- {} +