Check code formatting #15
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "Check code formatting" | |
permissions: | |
contents: read | |
on: | |
pull_request: | |
branches: | |
- master | |
jobs: | |
code_formatter: | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Checkout through merge base | |
uses: rmacklin/fetch-through-merge-base@v0 | |
with: | |
base_ref: ${{ github.event.pull_request.base.ref }} | |
head_ref: ${{ github.event.pull_request.head.sha }} | |
deepen_length: 500 | |
- name: Get changed files | |
id: changed-files | |
uses: tj-actions/changed-files@v39 | |
with: | |
separator: "," | |
skip_initial_fetch: true | |
- name: "Listed files" | |
env: | |
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} | |
run: | | |
echo "Formatting files:" | |
echo "$CHANGED_FILES" | |
- name: Install clang-format | |
uses: aminya/setup-cpp@v1 | |
with: | |
clangformat: 18.1.8 | |
- name: Run clang-format on changed files | |
run: | | |
echo "$CHANGED_CPP_FILES" | xargs -r clang-format-18 -i | |
- name: Check for formatting changes | |
run: | | |
# Check if any files were modified by clang-format | |
if [[ `git status --porcelain` ]]; then | |
echo "Code is not formatted. Please run clang-format." | |
git diff | |
exit 1 | |
fi | |