feat: warn and exit non-zero when attempting to rebuild from a non-existent branch
Closes #4898
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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 "$@"
|
||||
|
||||
@@ -12,6 +12,29 @@ teardown() {
|
||||
global_teardown
|
||||
}
|
||||
|
||||
@test "(git) push to non-deploy branch" {
|
||||
run /bin/bash -c "dokku git:set $TEST_APP deploy-branch custom-branch"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
GIT_REMOTE_BRANCH=custom-branch run deploy_app
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku git:set $TEST_APP deploy-branch non-existing-branch"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku ps:rebuild $TEST_APP"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_output_contains "Cannot build from 'non-existing-branch' as there are no commits stored at that branch."
|
||||
assert_failure
|
||||
}
|
||||
|
||||
@test "(git) deploy specific branch" {
|
||||
run /bin/bash -c "dokku git:set --global deploy-branch global-branch"
|
||||
echo "output: $output"
|
||||
|
||||
Reference in New Issue
Block a user