From f827e6216b1847f01118e92c35b79aae40f85d6f Mon Sep 17 00:00:00 2001 From: Miguel da Costa Martins Marcelino Date: Wed, 29 Apr 2026 13:09:22 +0000 Subject: [PATCH] chore: Add pre-push hooks Adding pre-push hooks to cloudflared. While developing in cloudflared, I found myself constantly bumping into issues in CI, as I was forgetting to run linters and tests at times. We should run these before pushing any code to our repo. --- .githooks/pre-push | 29 +++++++++++++++++++++++++++++ Makefile | 6 ++++++ README.md | 9 ++++++++- 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100755 .githooks/pre-push diff --git a/.githooks/pre-push b/.githooks/pre-push new file mode 100755 index 00000000..35446bdc --- /dev/null +++ b/.githooks/pre-push @@ -0,0 +1,29 @@ +#!/bin/sh +# Pre-push hook for cloudflared +# Runs linting and tests before allowing pushes + +set -e + +echo "========================================" +echo "Running pre-push checks..." +echo "========================================" + +# Run formatting check +echo "" +echo "==> Checking formatting..." +make fmt-check + +# Run linter +echo "" +echo "==> Running linter..." +make lint + +# Run tests +echo "" +echo "==> Running tests..." +make test + +echo "" +echo "========================================" +echo "All pre-push checks passed!" +echo "========================================" diff --git a/Makefile b/Makefile index 8490480e..95619ad0 100644 --- a/Makefile +++ b/Makefile @@ -289,3 +289,9 @@ ci-test: fmt-check lint test .PHONY: ci-fips-test ci-fips-test: @FIPS=true $(MAKE) ci-test + +.PHONY: install-hooks +install-hooks: + git config core.hooksPath .githooks + @echo "Git hooks installed from .githooks/" + @echo "Pre-push hook will run: make fmt-check lint test" diff --git a/README.md b/README.md index 7c5b60db..74d00eea 100644 --- a/README.md +++ b/README.md @@ -79,4 +79,11 @@ To locally run the tests run `make test` To format the code and keep a good code quality use `make fmt` and `make lint` ### Mocks -After changes on interfaces you might need to regenerate the mocks, so run `make mock` +After changes on interfaces you might need to regenerate the mocks, so run `make mocks` + +### Git Hooks +To avoid CI errors, you can install pre-push hooks that run linting and tests before each push: +```bash +make install-hooks +``` +This will configure git to use the hooks in `.githooks/` that run `make fmt-check lint test` before each push.