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