Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 0 additions & 58 deletions .github/workflows/clang-format.yaml

This file was deleted.

60 changes: 57 additions & 3 deletions .github/workflows/pr-test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: PR Test
name: PR Checks

on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- dev
- main
Expand All @@ -11,7 +12,60 @@ env:
BUILD_TYPE: test

jobs:
format:
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0

- name: Install clang-format
run: |
sudo apt-get update
sudo apt-get install -y clang-format

- name: Get changed files
id: changed-files
run: |
# Get the list of changed C/C++ files in the PR
git fetch origin ${{ github.base_ref }}
CHANGED_FILES=$(git diff --name-only --diff-filter=ACM origin/${{ github.base_ref }}...HEAD | grep -E '\.(cpp|hpp|h|c|cc|cxx)$' || true)
echo "files<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGED_FILES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

- name: Run clang-format
if: steps.changed-files.outputs.files != ''
run: |
FILES="${{ steps.changed-files.outputs.files }}"
if [ -n "$FILES" ]; then
echo "Formatting files:"
echo "$FILES"
echo "$FILES" | xargs -r clang-format -i --style=file --fallback-style=LLVM
fi

- name: Commit formatted changes
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"

if git diff --quiet; then
echo "No formatting changes needed"
else
git add -A
git commit -m "refactor: Apply clang-format to PR files [skip ci]"
git push
fi

changes:
needs: format
if: always()
runs-on: ubuntu-latest
permissions:
pull-requests: read
Expand All @@ -38,8 +92,8 @@ jobs:
- '.github/workflows/pr-test.yml'

test:
needs: changes
if: needs.changes.outputs.cpp == 'true'
needs: [format, changes]
if: always() && needs.changes.outputs.cpp == 'true'
strategy:
fail-fast: false
matrix:
Expand Down