Skip to content

GitHub Actions: Add workflow to run clang-format #237

GitHub Actions: Add workflow to run clang-format

GitHub Actions: Add workflow to run clang-format #237

Workflow file for this run

name: StyleCheck
on:
push:
branches-ignore:
- "dependabot/*"
pull_request:
workflow_dispatch:
jobs:
spacing:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install
run: sudo apt-get install moreutils
- name: Fix spacing
run: |
# Fix mixed tabs and spaces
find . \( -path ./Externals -o -path ./sdk -o -path ./src/utils/mp_gpprof_server/libraries -o -path ./res \) -prune -o -iregex '.*\.\(cs\|rc\|yaml\|yml\|md\|txt\|cmake\|sh\)' -type f -exec bash -c 'expand -t 4 "$0" | sponge "$0"' {} \;
# Fix trailing white spaces
find . \( -path ./Externals -o -path ./sdk -o -path ./src/utils/mp_gpprof_server/libraries -o -path ./res \) -prune -o -iregex '.*\.\(h\|hpp\|inl\|c\|cpp\|cs\|rc\|yaml\|yml\|md\|txt\|cmake\|sh\)' -type f -exec bash -c 'sed -i '' -e "s/[[:space:]]*$//" "$0"' {} \;
# Ensure files end with a new line
find . \( -path ./Externals -o -path ./sdk -o -path ./src/utils/mp_gpprof_server/libraries -o -path ./res \) -prune -o -iregex '.*\.\(h\|hpp\|inl\|c\|cpp\|cs\|rc\|yaml\|yml\|md\|txt\|cmake\|sh\)' -type f -exec bash -c 'tail -c1 < "$0" | read -r _ || echo >> "$0"' {} \;
- name: Report result
run: |
if [ -z "$(git status -s)" ]; then
echo Everything seems to be in order
else
echo Formatting problems found!
git diff --color=always --minimal
exit 1
fi
encoding:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install
run: sudo apt-get install dos2unix recode
- name: Fix encoding
run: |
# Ensure that files are UTF-8 encoded
find . \( -path ./Externals -o -path ./sdk -o -path ./src/utils/mp_gpprof_server/libraries -o -path ./res \) -prune -o -iregex '.*\.\(h\|hpp\|inl\|c\|cpp\|yaml\|yml\|md\|txt\|cmake\|sh\)' -type f -exec bash -c 'recode UTF-8 "$0" 2> /dev/null' {} \;
# Ensure that files have LF line endings and do not contain a BOM
find . \( -path ./Externals -o -path ./sdk -o -path ./src/utils/mp_gpprof_server/libraries -o -path ./res \) -prune -o -iregex '.*\.\(h\|hpp\|inl\|c\|cpp\|yaml\|yml\|md\|txt\|cmake\|sh\)' -type f -exec bash -c 'dos2unix "$0" 2> /dev/null' {} \;
- name: Report result
run: |
if [ -z "$(git status -s)" ]; then
echo Everything seems to be in order
else
echo Encoding problems found!
git diff --color=always --minimal
exit 1
fi
clang-format:
runs-on: ubuntu-latest
env:
LLVM_VERSION: 18
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install clang-format
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh ${{ env.LLVM_VERSION }}
rm -rf llvm.sh
sudo apt install clang-format-${{ env.LLVM_VERSION }}
git config --global clangFormat.binary "clang-format-${{ env.LLVM_VERSION }}"
- name: Fix formatting (pull_request)
if: ${{ github.event_name == 'pull_request' }}
continue-on-error: true
run: git clang-format-${{ env.LLVM_VERSION }} ${{ github.event.pull_request.base.sha }} --verbose
- name: Fix formatting (push)
if: ${{ github.event_name == 'push' }}
continue-on-error: true
run: git clang-format-${{ env.LLVM_VERSION }} HEAD~1 --verbose
- name: Ignore changes in external code
run: |
git restore ./Externals
git restore ./res
git restore ./sdk
git restore ./src/utils/mp_gpprof_server/libraries
- name: Report result
run: |
if [ -z "$(git status -s)" ]; then
echo Everything seems to be in order
else
echo Formatting problems found!
git diff --color=always --minimal
exit 1
fi