diff --git a/.githooks/post-receive b/.githooks/post-receive index 009704c..7f75f18 100644 --- a/.githooks/post-receive +++ b/.githooks/post-receive @@ -1,8 +1,26 @@ #!/bin/bash -set -euo pipefail # -e: exit on error, -u: exit on unset var, -o pipefail: catch errors in pipes + +# Only run for specific branches +read_branches() { + while IFS=' ' read -r _ _ remote_ref _; do + case "$remote_ref" in + refs/heads/testing|refs/heads/staging|refs/heads/main|refs/heads/production) + return 0 + ;; + esac + done + return 1 +} + +if ! read_branches; then + echo "Skipping deployment: not pushing testing, staging, main, or production." + exit 0 +fi TIMESTAMP=$(date +%Y%m%d-%H%M%S) +set -euo pipefail # -e: exit on error, -u: exit on unset var, -o pipefail: catch errors in pipes + get_deploy_env_file() { branch="$1" echo "/srv/jasonpoage.com/${branch}.env" diff --git a/.githooks/read_branches.sh b/.githooks/read_branches.sh new file mode 100644 index 0000000..10acc81 --- /dev/null +++ b/.githooks/read_branches.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +set -eu + +# Only run for specific branches +read_branches() { + while IFS=' ' read -r _ _ remote_ref _; do + case "$remote_ref" in + refs/heads/testing|refs/heads/staging|refs/heads/main|refs/heads/production) + return 0 + ;; + esac + done + return 1 +}