4jcraft/.github/workflows/clang-format.yml
Tropical c45a7b473f feat: add clang-format config and formatting workflows
Co-Authored-By: MatthewBeshay <92357869+MatthewBeshay@users.noreply.github.com>

#163 got deleted.
2026-03-13 15:09:54 -05:00

69 lines
1.8 KiB
YAML

name: Clang Format
on:
push:
paths:
- '**.cpp'
- '**.h'
- '**.c'
- '**.cc'
- '**.cxx'
- '**.hh'
- '**.hpp'
- '**.hxx'
- '**.inl'
- '.clang-format'
- '.github/workflows/clang-format.yml'
- '.github/scripts/check-clang-format.sh'
pull_request:
paths:
- '**.cpp'
- '**.h'
- '**.c'
- '**.cc'
- '**.cxx'
- '**.hh'
- '**.hpp'
- '**.hxx'
- '**.inl'
- '.clang-format'
- '.github/workflows/clang-format.yml'
- '.github/scripts/check-clang-format.sh'
jobs:
clang-format:
runs-on: ubuntu-24.04
concurrency:
group: clang-format-${{ github.ref }}
cancel-in-progress: true
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install clang-format
run: |
sudo apt-get update
sudo apt-get install -y clang-format-19
- name: Check changed files
env:
CLANG_FORMAT_BIN: clang-format-19
EVENT_NAME: ${{ github.event_name }}
PR_BASE_REF: ${{ github.event.pull_request.base.ref }}
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
BEFORE_SHA: ${{ github.event.before }}
CURRENT_SHA: ${{ github.sha }}
run: |
set -euo pipefail
BASE_SHA=""
if [ "$EVENT_NAME" = "pull_request" ]; then
git fetch --no-tags origin "$PR_BASE_REF" --depth=1
BASE_SHA="$(git merge-base "origin/$PR_BASE_REF" "$CURRENT_SHA")"
elif [ -n "$BEFORE_SHA" ] && [ "$BEFORE_SHA" != "0000000000000000000000000000000000000000" ]; then
BASE_SHA="$BEFORE_SHA"
fi
bash ./.github/scripts/check-clang-format.sh "$BASE_SHA" "$CURRENT_SHA"