mirror of
https://github.com/status-im/spiff-arena.git
synced 2025-01-12 11:14:50 +00:00
Jakub Sokołowski
1e8e6a7968
Primarily this is supposed to fix the `git pull` aciton triggered by webhooks from GitHub. But in addition to that the point is to simplify that committing wrapper which has far too much in it. Instead of passing everything as CLI arguments one should make use of already supported environment variables and the `env` argument to `subprocess` functions like `run()`. Writing extra logic in the wrapper only makes it unnecessarily complicated. By passing both user, email, and the SSH options in `run_shell_command` we avoid the need to repeat the same boilerplate to provide Git config and SSH credentials. Signed-off-by: Jakub Sokołowski <jakub@status.im>
44 lines
1.0 KiB
Bash
Executable File
44 lines
1.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
function error_handler() {
|
|
>&2 echo "Exited with BAD EXIT CODE '${2}' in ${0} script at line: ${1}."
|
|
exit "$2"
|
|
}
|
|
trap 'error_handler ${LINENO} $?' ERR
|
|
set -o errtrace -o errexit -o nounset -o pipefail
|
|
|
|
# HELP: git adds and commits the entire BPMN models directory, including all process groups
|
|
|
|
bpmn_models_absolute_dir="$1"
|
|
git_commit_message="$2"
|
|
git_branch="$3"
|
|
|
|
if [[ -z "${3:-}" ]]; then
|
|
>&2 echo "usage: $(basename "${0}") [bpmn_models_absolute_dir] [git_commit_message] [git_branch]"
|
|
exit 1
|
|
fi
|
|
|
|
function failed_to_get_lock() {
|
|
>&2 echo "ERROR: Failed to get lock."
|
|
exit 1
|
|
}
|
|
|
|
function run() {
|
|
cd "${bpmn_models_absolute_dir}"
|
|
git add .
|
|
|
|
# https://unix.stackexchange.com/a/155077/456630
|
|
if [ -z "$(git status --porcelain)" ]; then
|
|
echo "No changes to commit"
|
|
return
|
|
fi
|
|
|
|
git commit -m "${git_commit_message}"
|
|
git push --set-upstream origin "${git_branch}"
|
|
}
|
|
|
|
exec {lock_fd}>/var/lock/mylockfile || failed_to_get_lock
|
|
flock --timeout 60 "${lock_fd}" || failed_to_get_lock
|
|
run
|
|
flock -u "${lock_fd}"
|