diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..9f3e95c --- /dev/null +++ b/.clang-format @@ -0,0 +1,2 @@ +--- +BasedOnStyle: Google diff --git a/.github/format-check b/.github/format-check new file mode 100755 index 0000000..1150e4f --- /dev/null +++ b/.github/format-check @@ -0,0 +1,25 @@ +#!/bin/bash +# formatting using the ldmx/dev image which has clang-format in it + +set -o errexit +set -o nounset + +if [ -z "${GITHUB_WORKSPACE+x}" ]; then + # we are not in github actions so we need to error out + echo "ERROR: this script expects to be run in GitHub actions so should not be run locally." + exit 1 +fi + +ldmx() { + docker \ + run \ + --rm \ + --volume ${GITHUB_WORKSPACE} \ + --env LDMX_BASE=${GITHUB_WORKSPACE} \ + ldmx/dev:latest \ + ${PWD} + $@ +} +find include/ -type f > ${TMPDIR:-/tmp}/files-to-format.list +find src/ -type f >> ${TMPDIR:-/tmp}/files-to-format.list +ldmx clang-format --verbose -Werror --dry-run $(cat ${TMPDIR:-/tmp}/files-to-format.list) diff --git a/.github/workflows/format-check.yml b/.github/workflows/format-check.yml new file mode 100644 index 0000000..bfe16ba --- /dev/null +++ b/.github/workflows/format-check.yml @@ -0,0 +1,14 @@ +name: Check Format +on: + push: + branches: + - 'trunk' + pull_request: + +jobs: + clang-format: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: run format check + run: ./.github/format-check