Adds hooks to MRSK. Currently just two hooks, pre-build and post-push. We could break the build and push into two separate commands if we found the need for post-build and/or pre-push hooks. Hooks are stored in `.mrsk/hooks`. Running `mrsk init` will now create that folder and add sample hook scripts. Hooks returning non-zero exit codes will abort the current command. Further potential work here: - We could replace the audit broadcast command with a post-deploy/post-rollback hook or similar - Maybe provide pre-command/post-command hooks that run after every mrsk invocation - Also look for hooks in `~/.mrsk/hooks`
50 lines
1.0 KiB
Bash
Executable File
50 lines
1.0 KiB
Bash
Executable File
#!/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:
|
|
# MRSK_RECORDED_AT
|
|
# MRSK_PERFORMER
|
|
# MRSK_VERSION
|
|
# MRSK_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 "No git remote set, 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 [ "$MRSK_VERSION" != "$remote_head" ]; then
|
|
echo "Version ($MRSK_VERSION) does not match remote HEAD ($remote_head), aborting..." >&2
|
|
exit 1
|
|
fi
|
|
|
|
exit 0
|