diff options
| author | Adam Malczewski <[email protected]> | 2026-03-30 19:03:22 +0900 |
|---|---|---|
| committer | Adam Malczewski <[email protected]> | 2026-03-30 19:03:22 +0900 |
| commit | 952c6b565832dd0dbcef7a9a80edc871f79e15a8 (patch) | |
| tree | 698db27a35f8f40356a0381a32a02767481dc6a9 /.kamal/hooks/pre-build.sample | |
| download | dispatch-api-main.tar.gz dispatch-api-main.zip | |
Diffstat (limited to '.kamal/hooks/pre-build.sample')
| -rwxr-xr-x | .kamal/hooks/pre-build.sample | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/.kamal/hooks/pre-build.sample b/.kamal/hooks/pre-build.sample new file mode 100755 index 0000000..c5a5567 --- /dev/null +++ b/.kamal/hooks/pre-build.sample @@ -0,0 +1,51 @@ +#!/bin/sh + +# A sample pre-build hook +# +# Checks: +# 1. We have a clean checkout +# 2. A remote is configured +# 3. The branch has been pushed to the remote +# 4. The version we are deploying matches the remote +# +# These environment variables are available: +# KAMAL_RECORDED_AT +# KAMAL_PERFORMER +# KAMAL_VERSION +# KAMAL_HOSTS +# KAMAL_ROLES (if set) +# KAMAL_DESTINATION (if set) + +if [ -n "$(git status --porcelain)" ]; then + echo "Git checkout is not clean, aborting..." >&2 + git status --porcelain >&2 + exit 1 +fi + +first_remote=$(git remote) + +if [ -z "$first_remote" ]; then + echo "No git remote set, aborting..." >&2 + exit 1 +fi + +current_branch=$(git branch --show-current) + +if [ -z "$current_branch" ]; then + echo "Not on a git branch, aborting..." >&2 + exit 1 +fi + +remote_head=$(git ls-remote $first_remote --tags $current_branch | cut -f1) + +if [ -z "$remote_head" ]; then + echo "Branch not pushed to remote, aborting..." >&2 + exit 1 +fi + +if [ "$KAMAL_VERSION" != "$remote_head" ]; then + echo "Version ($KAMAL_VERSION) does not match remote HEAD ($remote_head), aborting..." >&2 + exit 1 +fi + +exit 0 |
