Skip to content

Commit

Permalink
switch to pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Zehvogel committed Sep 19, 2023
1 parent 95cba0d commit f2e41d7
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 28 deletions.
21 changes: 21 additions & 0 deletions .github/scripts/clang-format-hook
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}
16 changes: 16 additions & 0 deletions .github/templates/apache-2.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Copyright (c) ${years} ${owner}.

This file is part of ${projectname}.
See ${projecturl} for further info.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
21 changes: 0 additions & 21 deletions .github/workflows/clang-format-check.yml

This file was deleted.

23 changes: 23 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: pre-commit

on: [push, pull_request]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: cvmfs-contrib/[email protected]
- uses: aidasoft/run-lcg-view@v4
with:
release-platform: LCG_101/x86_64-centos7-clang12-opt
run: |
export PYTHONPATH=$(python -m site --user-site):$PYTHONPATH
export PATH=/root/.local/bin:$PATH
pip install --upgrade --user pip
pip install pre-commit --user
# Use virtualenv from the LCG release
pip uninstall --yes virtualenv
pre-commit run --show-diff-on-failure \
--color=always \
--all-files
25 changes: 25 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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
- repo: https://github.com/johann-petrak/licenseheaders.git
rev: 'v0.8.8'
hooks:
- id: licenseheaders
args: ["-t", ".github/templates/apache-2.tmpl", "-y2014-2023",
"-o", "Key4hep-Project",
"-n", "Key4hep",
"-u", "https://key4hep.github.io/key4hep-doc/",
"-x", ".github/*", ".pre-commit-config.yaml", "README.md",
"doc/ReleaseNotes.md",
"-f"]
7 changes: 0 additions & 7 deletions ci/format.sh

This file was deleted.

0 comments on commit f2e41d7

Please sign in to comment.