feat: warn and exit non-zero when attempting to rebuild from a non-existent branch

Closes #4898
This commit is contained in:
Jose Diaz-Gonzalez
2022-04-02 04:22:44 -04:00
parent 5fc738f001
commit 68c0d7e964
3 changed files with 42 additions and 9 deletions

View File

@@ -96,8 +96,7 @@ cmd-git-hook() {
plugn trigger deploy-source-set "$APP" "git-push" "$newrev"
else
if [[ $(find "$PLUGIN_PATH"/enabled/*/receive-branch 2>/dev/null | wc -l) != 1 ]]; then
# shellcheck disable=SC2086
plugn trigger receive-branch $APP $newrev $refname
plugn trigger receive-branch "$APP" "$newrev" "$refname"
plugn trigger deploy-source-set "$APP" "git-push" "$newrev"
elif [[ -z "$(fn-git-deploy-branch "$APP" "")" ]]; then
echo $'\e[1G\e[K'"-----> Set ${refname/refs\/heads\//} to DOKKU_DEPLOY_BRANCH."
@@ -116,7 +115,7 @@ git_build() {
declare desc="setup and call git_build_app_repo"
local APP="$1" REV="$2"
local DOKKU_DEPLOY_BRANCH ENV_VAR_NAME REF
if [[ $# -ge 2 ]]; then
if [[ -n "$REV" ]]; then
ENV_VAR_NAME="$(fn-plugin-property-get "git" "$APP" "rev-env-var")"
if [[ -z "$ENV_VAR_NAME" ]] && ! fn-plugin-property-exists "git" "$APP" "rev-env-var"; then
ENV_VAR_NAME="GIT_REV"
@@ -130,14 +129,16 @@ git_build() {
DOKKU_DEPLOY_BRANCH="$(fn-git-deploy-branch "$APP")"
if [[ -f "$DOKKU_ROOT/$APP/refs/heads/$DOKKU_DEPLOY_BRANCH" ]]; then
REF=$(<"$DOKKU_ROOT/$APP/refs/heads/$DOKKU_DEPLOY_BRANCH")
else
echo $'\e[1G\e[K'"-----> WARNING: Cannot build from '$DOKKU_DEPLOY_BRANCH' as there are no commits stored at that branch."
fi
fi
if [[ -z "$REF" ]]; then
return
return 1
fi
# shellcheck disable=SC2086
git_build_app_repo $APP $REF
git_build_app_repo "$APP" "$REF"
}
git_receive_app() {
@@ -148,10 +149,11 @@ git_receive_app() {
if [[ ! -d "$DOKKU_ROOT/$APP/refs" ]]; then
true
else
local exit_code=0
acquire_app_deploy_lock "$APP" "exclusive"
# shellcheck disable=SC2086
git_build $APP $REV
git_build "$APP" "$REV" || exit_code="$?"
release_app_deploy_lock "$APP"
return "$exit_code"
fi
}

View File

@@ -3,4 +3,12 @@ source "$PLUGIN_AVAILABLE_PATH/git/functions"
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
git_receive_app "$@"
trigger-git-receive-app() {
declare desc="builds the app from the local git repository"
declare trigger="receive-app"
git_receive_app "$@"
return $?
}
trigger-git-receive-app "$@"