View raw

1 #!/bin/sh 2 3 # A sample pre-build hook 4 # 5 # Checks: 6 # 1. We have a clean checkout 7 # 2. A remote is configured 8 # 3. The branch has been pushed to the remote 9 # 4. The version we are deploying matches the remote 10 # 11 # These environment variables are available: 12 # KAMAL_RECORDED_AT 13 # KAMAL_PERFORMER 14 # KAMAL_VERSION 15 # KAMAL_HOSTS 16 # KAMAL_ROLE (if set) 17 # KAMAL_DESTINATION (if set) 18 19 if [ -n "$(git status --porcelain)" ]; then 20 echo "Git checkout is not clean, aborting..." >&2 21 git status --porcelain >&2 22 exit 1 23 fi 24 25 first_remote=$(git remote) 26 27 if [ -z "$first_remote" ]; then 28 echo "No git remote set, aborting..." >&2 29 exit 1 30 fi 31 32 current_branch=$(git branch --show-current) 33 34 if [ -z "$current_branch" ]; then 35 echo "Not on a git branch, aborting..." >&2 36 exit 1 37 fi 38 39 remote_head=$(git ls-remote $first_remote --tags $current_branch | cut -f1) 40 41 if [ -z "$remote_head" ]; then 42 echo "Branch not pushed to remote, aborting..." >&2 43 exit 1 44 fi 45 46 if [ "$KAMAL_VERSION" != "$remote_head" ]; then 47 echo "Version ($KAMAL_VERSION) does not match remote HEAD ($remote_head), aborting..." >&2 48 exit 1 49 fi 50 51 exit 0 52