From 1e1f75e23ff19c2067ca63cc01647401b3ccf9e3 Mon Sep 17 00:00:00 2001 From: Jaime Date: Mon, 13 Oct 2025 15:05:29 +0200 Subject: [PATCH 1/3] First iteation of pre-push git hook, and behat timestamp file --- .gitignore | 1 + commands/web/behat | 4 ++++ scripts/git-hooks/pre-push | 24 ++++++++++++++++++++++++ scripts/git-hooks/pre-push.wip | 27 --------------------------- 4 files changed, 29 insertions(+), 27 deletions(-) create mode 100755 scripts/git-hooks/pre-push delete mode 100755 scripts/git-hooks/pre-push.wip diff --git a/.gitignore b/.gitignore index 0098a47..2b99cc0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea tampermonkey_scripts +.annertech_tests_timestamps diff --git a/commands/web/behat b/commands/web/behat index 8888048..b63b16e 100755 --- a/commands/web/behat +++ b/commands/web/behat @@ -26,3 +26,7 @@ fi # Run behat with the provided flags/arguments bin/behat "$@" + +# Create/update timestamp file +cd ../.. +touch .ddev/.annertech_tests_timestamps \ No newline at end of file diff --git a/scripts/git-hooks/pre-push b/scripts/git-hooks/pre-push new file mode 100755 index 0000000..9bf98c8 --- /dev/null +++ b/scripts/git-hooks/pre-push @@ -0,0 +1,24 @@ +#!/bin/sh + +# Annertech's tests timestamps file +TIMESTAMP_FILE=.ddev/.annertech_tests_timestamps + +# Check if the timestamp is more recent than 1 hour +one_hour_ago=$(date -d '-1 hour' "+%s") +last_test_run=$(date -r $TIMESTAMP_FILE "+%s") +if [ $one_hour_ago -gt $last_test_run ]; +then + read -r -p "You haven't run tests recently. Do you want to run them now? [y/N] " response < /dev/tty +case "$response" in [yY][eE][sS]|[yY]) + # Disallow the push + echo git push aborted. Run your testing suite and git push again + exit 1 + ;; + *) + echo pushing... + ;; +esac +fi + +# Allow the push. +exit 0 diff --git a/scripts/git-hooks/pre-push.wip b/scripts/git-hooks/pre-push.wip deleted file mode 100755 index da93aaa..0000000 --- a/scripts/git-hooks/pre-push.wip +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bash -#ddev-generated - -# Abort a push if no backstop test have been found - -# Directory to check -BASE_DIR="tests/backstop/backstop_data/bitmaps_test" - -# Today's date in YYYYMMDD format -TODAY=$(date +%Y%m%d) - -# Look for any folder that starts with today's date -MATCH=$(find "$BASE_DIR" -maxdepth 1 -type d -name "${TODAY}-*") - -if [ -z "$MATCH" ]; then - echo - echo "==================================================================================================" - echo "❌ Push aborted ❌" - echo "No folder found in $BASE_DIR starting with today's date ($TODAY)" - echo "Did you run Backstop tests?" - echo "==================================================================================================" - echo - exit 1 -fi - -# If a folder is found, allow the push -exit 0 From 7f2d7f0d69b9a748bd5f0f240d4067f481ba4a0f Mon Sep 17 00:00:00 2001 From: Jaime Date: Mon, 13 Oct 2025 15:34:41 +0200 Subject: [PATCH 2/3] Fixed path for timestamp file --- commands/web/behat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/web/behat b/commands/web/behat index b63b16e..7b6e8b9 100755 --- a/commands/web/behat +++ b/commands/web/behat @@ -29,4 +29,4 @@ bin/behat "$@" # Create/update timestamp file cd ../.. -touch .ddev/.annertech_tests_timestamps \ No newline at end of file +touch ${DDEV_APPROOT}/.ddev/.annertech_tests_timestamps \ No newline at end of file From fd3bbbee2aeceaf8290b625c84806f52512e0d6a Mon Sep 17 00:00:00 2001 From: Jaime Date: Mon, 13 Oct 2025 15:47:37 +0200 Subject: [PATCH 3/3] Indentation --- scripts/git-hooks/pre-push | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/git-hooks/pre-push b/scripts/git-hooks/pre-push index 9bf98c8..a81ae03 100755 --- a/scripts/git-hooks/pre-push +++ b/scripts/git-hooks/pre-push @@ -9,15 +9,15 @@ last_test_run=$(date -r $TIMESTAMP_FILE "+%s") if [ $one_hour_ago -gt $last_test_run ]; then read -r -p "You haven't run tests recently. Do you want to run them now? [y/N] " response < /dev/tty -case "$response" in [yY][eE][sS]|[yY]) - # Disallow the push - echo git push aborted. Run your testing suite and git push again - exit 1 - ;; - *) - echo pushing... - ;; -esac + case "$response" in [yY][eE][sS]|[yY]) + # Disallow the push + echo git push aborted. Run your testing suite and git push again + exit 1 + ;; + *) + echo pushing... + ;; + esac fi # Allow the push.