1 name: format 2 3 on: [push, pull_request] 4 5 jobs: 6 format: 7 runs-on: ubuntu-24.04 8 env: 9 CLANG_FORMAT_VERSION: -15 10 steps: 11 - uses: actions/checkout@v4 12 with: 13 fetch-depth: 0 14 - name: Dependencies 15 run: | 16 sudo apt -q update 17 sudo apt install -q -y "clang-format${CLANG_FORMAT_VERSION}" 18 - name: Check 19 run: | 20 if [[ -n "${GITHUB_BASE_REF}" ]]; then 21 # pull request, check head branch against base branch 22 GITHUB_BEFORE="$(git ls-remote origin "${GITHUB_BASE_REF}" | cut -f1)" 23 elif [[ "${GITHUB_REF}" != "refs/heads/main" ]]; then 24 # workflow triggered from some branch other than main, assume that 25 # the branch will eventually be merged into main 26 GITHUB_BEFORE="$(git ls-remote origin refs/heads/main | cut -f1)" 27 else 28 # main branch, compare against previous state 29 # (jq comes preinstalled on github runners) 30 GITHUB_BEFORE="$(jq -r '.before' "${GITHUB_EVENT_PATH}")" 31 fi 32 33 # github interleaves stderr and stdout, redirect everything to stdout 34 /bin/bash -eu build-aux/ci/format-code.sh "${GITHUB_BEFORE}..${GITHUB_SHA}" 2>&1 35