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