Skip to content

Commit

Permalink
Add default pre-commit hooks (#405)
Browse files Browse the repository at this point in the history
These have mostly no effect and just make sure that trailing newlines
are used properly, linebreaks are linux-like and trailing whitespace is
removed.
  • Loading branch information
aaronmondal committed Nov 19, 2023
1 parent 9543964 commit 228bdc4
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 10 deletions.
2 changes: 1 addition & 1 deletion config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,4 @@ This store is special. It's only job is to verify the content as it is fetched a
},
// Place rest of configuration here ...
}
```
```
2 changes: 1 addition & 1 deletion deployment-examples/terraform/AWS/lambdas.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ resource "aws_lambda_function" "update_scheduler_ips_lambda" {
}
}

data "archive_file" "update_scheduler_ips" {
data "archive_file" "update_scheduler_ips" {
type = "zip"
source_file = "scripts/lambdas/update_scheduler_ips.py"
output_path = ".update_scheduler_ips.zip"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
set -euxo pipefail

if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
echo "This script must be run as root"
exit 1
fi

Expand Down
2 changes: 1 addition & 1 deletion integration_tests/simple_cache_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# This is a sanity check test to ensure we are caching test results.

if [[ $UNDER_TEST_RUNNER -ne 1 ]]; then
echo "This script should be run under run_integration_tests.sh"
echo "This script should be run under run_integration_tests.sh"
exit 1
fi
set -x
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/simple_prometheus_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# This is a sanity check test to ensure we are caching test results.

if [[ $UNDER_TEST_RUNNER -ne 1 ]]; then
echo "This script should be run under run_integration_tests.sh"
echo "This script should be run under run_integration_tests.sh"
exit 1
fi

Expand Down
2 changes: 1 addition & 1 deletion integration_tests/simple_remote_execution_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# This test is also here to ensure GrpcStore is being used properly.

if [[ $UNDER_TEST_RUNNER -ne 1 ]]; then
echo "This script should be run under run_integration_tests.sh"
echo "This script should be run under run_integration_tests.sh"
exit 1
fi
set -xo pipefail
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/simple_tls_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.

if [[ $UNDER_TEST_RUNNER -ne 1 ]]; then
echo "This script should be run under run_integration_tests.sh"
echo "This script should be run under run_integration_tests.sh"
exit 1
fi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2082,4 +2082,4 @@ message RequestMetadata {
// There is no expectation that this value will have any particular structure,
// or equality across invocations, though some client tools may offer these guarantees.
string configuration_id = 7;
}
}
2 changes: 1 addition & 1 deletion run_integration_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ for pattern in "${TEST_PATTERNS[@]}"; do
FILENAME=$(basename $fullpath)
echo "Running test $FILENAME"
sudo docker-compose up -d
if perl -e 'alarm shift; exec @ARGV' 30 bash -c 'until sudo docker-compose logs | grep -q "Ready, listening on"; do sleep 1; done'
if perl -e 'alarm shift; exec @ARGV' 30 bash -c 'until sudo docker-compose logs | grep -q "Ready, listening on"; do sleep 1; done'
then
echo "String 'Ready, listening on' found in the logs."
else
Expand Down
53 changes: 52 additions & 1 deletion tools/pre-commit-hooks.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,55 @@
{ pkgs, ... }:
let

excludes = ["^gencargo/" "^proto/genproto"];

in
{
# TODO(aaronmondal): Add hooks here.
# Default hooks
trailing-whitespace-fixer = {
inherit excludes;
enable = true;
name = "trailing-whitespace";
description = "Remove trailing whitespace";
entry = "${pkgs.python311Packages.pre-commit-hooks}/bin/trailing-whitespace-fixer";
types = [ "text" ];
};
end-of-file-fixer = {
inherit excludes;
enable = true;
name = "end-of-file-fixer";
description = "Remove trailing whitespace";
entry = "${pkgs.python311Packages.pre-commit-hooks}/bin/end-of-file-fixer";
types = [ "text" ];
};
fix-byte-order-marker = {
inherit excludes;
enable = true;
name = "fix-byte-order-marker";
entry = "${pkgs.python311Packages.pre-commit-hooks}/bin/fix-byte-order-marker";
};
mixed-line-ending = {
inherit excludes;
enable = true;
name = "mixed-line-ending";
entry = "${pkgs.python311Packages.pre-commit-hooks}/bin/mixed-line-ending";
types = [ "text" ];
};
check-case-conflict = {
inherit excludes;
enable = true;
name = "check-case-conflict";
entry = "${pkgs.python311Packages.pre-commit-hooks}/bin/check-case-conflict";
types = [ "text" ];
};
detect-private-key = {
excludes = excludes ++ [
# This is an integration testfile that is not intended for production.
"deployment-examples/docker-compose/example-do-not-use-in-prod-key.pem"
];
enable = true;
name = "detect-private-key";
entry = "${pkgs.python311Packages.pre-commit-hooks}/bin/detect-private-key";
types = [ "text" ];
};
}

0 comments on commit 228bdc4

Please sign in to comment.