Skip to content

apply updated code style #13

apply updated code style

apply updated code style #13

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
- name: Install clang-format
run: wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - && sudo apt-get install -y clang-format-18
- name: Add git safe directory
run: git config --global --add safe.directory '*' && git fetch origin main
# This command is used to address potential issues with Git's safe directory feature.
# By setting '*' as a safe directory, we allow Git operations to proceed without errors
# related to directory safety, ensuring smooth execution of the submodules updating.
- name: Run clang-format on changed files
run: |
# Get list of changed files
CHANGED_FILES=$(git diff --name-only --diff-filter=ACM origin/master...HEAD --)
CHANGED_CPP_FILES = $(echo "$CHANGED_FILES" | grep -E '^(runtime-light|runtime-common)/.*\.(cpp|h|inl)$')
# Apply clang-format to each changed source file
echo "$CHANGED_CPP_FILES" | xargs -r clang-format-18 -style=file -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