-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Thin wrapper around clang-format for easier to parse output from the | ||
# pre-commit hook. | ||
# | ||
# Needs to work with multiple input files as pre-commit passes multiple files to | ||
# the "executables" | ||
|
||
# Make sure that diff is actually recent enough (diffutils >= 3.4) to support | ||
# colored output | ||
COLOR_OUTPUT=$(diff --color=always <(echo) <(echo) > /dev/null 2>&1 && echo "--color=always") | ||
|
||
success=0 | ||
for file in ${@}; do | ||
if ! $(clang-format --style=file --Werror --dry-run ${file} > /dev/null 2>&1); then | ||
echo "Necessary changes for: '${file}' (run 'clang-format --style=file -i ${file}' to fix it)" | ||
diff ${COLOR_OUTPUT} -u ${file} <(clang-format --style=file ${file}) | tail -n +3 | ||
success=1 | ||
fi | ||
done | ||
exit ${success} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: pre-commit | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
pre-commit: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: cvmfs-contrib/github-action-cvmfs@v4 | ||
- uses: aidasoft/run-lcg-view@v4 | ||
with: | ||
container: el9 | ||
view-path: /cvmfs/sw-nightlies.hsf.org/key4hep | ||
run: | | ||
echo "::group::Setup pre-commit" | ||
# Newer versions of git are more cautious around the github runner | ||
# environment and without this git rev-parse --show-cdup in pre-commit | ||
# fails | ||
git config --global --add safe.directory $(pwd) | ||
python -m venv /root/pre-commit-venv | ||
source /root/pre-commit-venv/bin/activate | ||
pip install pre-commit | ||
echo "::endgroup::" | ||
echo "::group::Run pre-commit" | ||
pre-commit run --show-diff-on-failure \ | ||
--color=always \ | ||
--all-files | ||
echo "::endgroup::" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v3.4.0 | ||
hooks: | ||
- id: mixed-line-ending | ||
- id: trailing-whitespace | ||
exclude: (doc/ReleaseNotes.md) | ||
- repo: local | ||
hooks: | ||
- id: clang-format | ||
name: clang-format | ||
entry: .github/scripts/clang-format-hook | ||
types: [c++] | ||
language: system |