diff --git a/.githooks/pre-push b/.githooks/pre-push index 654793a..9f3b84a 100755 --- a/.githooks/pre-push +++ b/.githooks/pre-push @@ -1,12 +1,9 @@ #!/bin/sh # Push content subrepo before pushing main repo -remote="$1" -#export GIT_TRACE=1 -#export GIT_TRACE_PACKET=1 -#export GIT_TRACE_PERFORMANCE=1 -#export GIT_SSH_COMMAND="ssh -vvv" -source "$(pwd)/.env" +remote="$1" + +. "$(pwd)/.env" if [ "$SKIP_TESTS" = "true" ]; then exit 0 fi @@ -14,15 +11,32 @@ set -eu set -x -# Only run for specific branches +hook_input=$(cat) +echo "$hook_input" + read_branches() { - while IFS=' ' read -r _ _ remote_ref _; do + matched=false + seen_refs=false + + echo "$hook_input" | while IFS=' ' read -r _ _ remote_ref _; do + seen_refs=true case "$remote_ref" in refs/heads/testing|refs/heads/staging|refs/heads/main|refs/heads/production) - return 0 + echo "Matched deployable branch: ${remote_ref#refs/heads/}" + exit 0 + ;; + *) + echo "Non-deployable branch: ${remote_ref#refs/heads/}" ;; esac done + + if ! $seen_refs; then + echo "No refs were pushed. Nothing to process." + return 2 + fi + + echo "No deployable branches matched." return 1 } @@ -35,16 +49,24 @@ " } -if ! read_branches; then - echo "Skipping tests: not pushing testing, staging, main, or production." -else - COMMIT_HASH=$(git rev-parse HEAD) +read_branches_result=2 +read_branches || read_branches_result=$? - if ! "./scripts/pre-push-tests.sh" "$COMMIT_HASH"; then - echo "Tests failed. Aborting push." - exit 1 - fi -fi +case "$read_branches_result" in + 0) + COMMIT_HASH=$(git rev-parse HEAD) + if ! ./scripts/pre-push-tests.sh "$COMMIT_HASH"; then + echo "Tests failed. Aborting push." + exit 1 + fi + ;; + 1) + echo "Skipping tests: no deployable branches pushed." + ;; + 2) + echo "No refs detected. Possibly a dry push or no changes." + ;; +esac cd content git push "$remote" main --force diff --git a/Jenkinsfile b/Jenkinsfile index 8ecdc4e..584cf79 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -234,7 +234,6 @@ skipInstall = true } } - skipInstall = false if (!skipInstall) { sh """