mirror of
https://github.com/ovh/debian-cis.git
synced 2025-06-23 11:04:32 +02:00
feat: add basic pre commit
Ensure a check has a corresponding test
This commit is contained in:
10
.pre-commit-config.yaml
Normal file
10
.pre-commit-config.yaml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
repos:
|
||||||
|
- repo: local
|
||||||
|
hooks:
|
||||||
|
- id: check_has_test
|
||||||
|
name: check_has_test.sh
|
||||||
|
description: Ensure a check has a corresponding test
|
||||||
|
entry: hooks/check_has_test.sh
|
||||||
|
language: script
|
||||||
|
pass_filenames: true
|
||||||
|
files: "^bin/hardening/"
|
21
hooks/check_has_test.sh
Executable file
21
hooks/check_has_test.sh
Executable file
@ -0,0 +1,21 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
test_path="tests/hardening"
|
||||||
|
failure=0
|
||||||
|
failed_checks=""
|
||||||
|
|
||||||
|
for check in "$@"; do
|
||||||
|
base_name=$(basename "$check")
|
||||||
|
if [ ! -f $test_path/"$base_name" ]; then
|
||||||
|
failure=1
|
||||||
|
failed_checks="$failed_checks $base_name"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $failure -ne 0 ]; then
|
||||||
|
for check in $failed_checks; do
|
||||||
|
echo "missing file $test_path/$check"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit $failure
|
Reference in New Issue
Block a user