chore: Update clang-format and prettier with pre-commit (#5709)

The change updates how clang-format is called in CI and locally, and adds prettier to the pre-commit hook. Proto files are now also formatted, while external files are excluded.
This commit is contained in:
Bart
2025-08-22 13:37:11 -04:00
committed by GitHub
parent 095dc4d9cc
commit c14ce956ad
9 changed files with 103 additions and 117 deletions

View File

@@ -2,21 +2,11 @@
"architecture": [
{
"platform": "linux/amd64",
"runner": [
"self-hosted",
"Linux",
"X64",
"heavy"
]
"runner": ["self-hosted", "Linux", "X64", "heavy"]
},
{
"platform": "linux/arm64",
"runner": [
"self-hosted",
"Linux",
"ARM64",
"heavy-arm64"
]
"runner": ["self-hosted", "Linux", "ARM64", "heavy-arm64"]
}
],
"os": [
@@ -159,12 +149,6 @@
"compiler_version": "19"
}
],
"build_type": [
"Debug",
"Release"
],
"cmake_args": [
"-Dunity=OFF",
"-Dunity=ON"
]
"build_type": ["Debug", "Release"],
"cmake_args": ["-Dunity=OFF", "-Dunity=ON"]
}

View File

@@ -2,12 +2,7 @@
"architecture": [
{
"platform": "macos/arm64",
"runner": [
"self-hosted",
"macOS",
"ARM64",
"mac-runner-m1"
]
"runner": ["self-hosted", "macOS", "ARM64", "mac-runner-m1"]
}
],
"os": [
@@ -18,10 +13,7 @@
"compiler_version": ""
}
],
"build_type": [
"Debug",
"Release"
],
"build_type": ["Debug", "Release"],
"cmake_args": [
"-Dunity=OFF -DCMAKE_POLICY_VERSION_MINIMUM=3.5",
"-Dunity=ON -DCMAKE_POLICY_VERSION_MINIMUM=3.5"

View File

@@ -2,9 +2,7 @@
"architecture": [
{
"platform": "windows/amd64",
"runner": [
"windows-latest"
]
"runner": ["windows-latest"]
}
],
"os": [
@@ -15,12 +13,6 @@
"compiler_version": ""
}
],
"build_type": [
"Debug",
"Release"
],
"cmake_args": [
"-Dunity=OFF",
"-Dunity=ON"
]
"build_type": ["Debug", "Release"],
"cmake_args": ["-Dunity=OFF", "-Dunity=ON"]
}

View File

@@ -13,9 +13,9 @@ defaults:
shell: bash
jobs:
clang-format:
pre-commit:
runs-on: ubuntu-latest
container: ghcr.io/xrplf/ci/tools-rippled-clang-format
container: ghcr.io/xrplf/ci/tools-rippled-pre-commit
steps:
# The $GITHUB_WORKSPACE and ${{ github.workspace }} might not point to the
# same directory for jobs running in containers. The actions/checkout step
@@ -38,48 +38,11 @@ jobs:
echo 'Checking environment variables.'
env | sort
echo 'Checking pre-commit version.'
pre-commit --version
echo 'Checking clang-format version.'
clang-format --version
- name: Format code
run: find include src tests -type f \( -name '*.cpp' -o -name '*.hpp' -o -name '*.h' -o -name '*.ipp' \) -exec clang-format -i {} +
- name: Check for differences
env:
MESSAGE: |
One or more files did not conform to the formatting specified in
.clang-format. Maybe you did not run 'git-clang-format' or
'clang-format' before committing, or your version of clang-format
has an incompatibility with the one used here (see the "Check
configuration" step above).
Run 'git-clang-format --extensions cpp,h,hpp,ipp develop' in your
repo, and then commit and push the changes.
run: |
DIFF=$(git status --porcelain)
if [ -n "${DIFF}" ]; then
# Print the files that changed to give the contributor a hint about
# what to expect when running git-clang-format on their own machine.
git status
echo "${MESSAGE}"
exit 1
fi
prettier:
runs-on: ubuntu-latest
container: ghcr.io/xrplf/ci/tools-rippled-prettier
steps:
- name: Configure git safe.directory
run: |
git config --global --add safe.directory $GITHUB_WORKSPACE
git config --global --add safe.directory ${{ github.workspace }}
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Check configuration
run: |
echo 'Checking path.'
echo ${PATH} | tr ':' '\n'
echo 'Checking environment variables.'
env | sort
echo 'Checking NPM version.'
npm --version
@@ -90,22 +53,22 @@ jobs:
echo 'Checking prettier version.'
prettier --version
- name: Format code
run: prettier --check .
run: pre-commit run --show-diff-on-failure --color=always --all-files
- name: Check for differences
env:
MESSAGE: |
One or more files did not conform to the formatting rules specified
by Prettier. Maybe you did not run 'prettier' before committing, or
your version of prettier has an incompatibility with the one used
here (see the "Check configuration" step above).
One or more files did not conform to the formatting. Maybe you did
not run 'pre-commit' before committing, or your version of
'clang-format' or 'prettier' has an incompatibility with the ones
used here (see the "Check configuration" step above).
Run 'prettier --check .' in your repo, and then commit and push the
changes.
Run 'pre-commit run --all-files' in your repo, and then commit and
push the changes.
run: |
DIFF=$(git status --porcelain)
if [ -n "${DIFF}" ]; then
# Print the files that changed to give the contributor a hint about
# what to expect when running prettier on their own machine.
# what to expect when running pre-commit on their own machine.
git status
echo "${MESSAGE}"
exit 1

View File

@@ -69,7 +69,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: No-op
run: echo ''
run: true
check-format:
needs: should-run
@@ -86,7 +86,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: No-op
run: echo ''
run: true
outputs:
conan_remote_name: ${{ env.CONAN_REMOTE_NAME }}
conan_remote_url: ${{ env.CONAN_REMOTE_URL }}