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 committed 2022-04-16 01:40:22 -04:00
1 parent 5fc738f001
commit 68c0d7e964
3 files changed
+42 -9

No files matched your search

+10 -8
View File
@@ -96,8 +96,7 @@ cmd-git-hook() {
plugn trigger deploy-source-set "$APP" "git-push" "$newrev" plugn trigger deploy-source-set "$APP" "git-push" "$newrev"
else else
if [[ $(find "$PLUGIN_PATH"/enabled/*/receive-branch 2>/dev/null | wc -l) != 1 ]]; then 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" plugn trigger deploy-source-set "$APP" "git-push" "$newrev"
elif [[ -z "$(fn-git-deploy-branch "$APP" "")" ]]; then elif [[ -z "$(fn-git-deploy-branch "$APP" "")" ]]; then
echo $'\e[1G\e[K'"-----> Set ${refname/refs\/heads\//} to DOKKU_DEPLOY_BRANCH." 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" declare desc="setup and call git_build_app_repo"
local APP="$1" REV="$2" local APP="$1" REV="$2"
local DOKKU_DEPLOY_BRANCH ENV_VAR_NAME REF 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")" 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 if [[ -z "$ENV_VAR_NAME" ]] && ! fn-plugin-property-exists "git" "$APP" "rev-env-var"; then
ENV_VAR_NAME="GIT_REV" ENV_VAR_NAME="GIT_REV"
@@ -130,14 +129,16 @@ git_build() {
DOKKU_DEPLOY_BRANCH="$(fn-git-deploy-branch "$APP")" DOKKU_DEPLOY_BRANCH="$(fn-git-deploy-branch "$APP")"
if [[ -f "$DOKKU_ROOT/$APP/refs/heads/$DOKKU_DEPLOY_BRANCH" ]]; then if [[ -f "$DOKKU_ROOT/$APP/refs/heads/$DOKKU_DEPLOY_BRANCH" ]]; then
REF=$(<"$DOKKU_ROOT/$APP/refs/heads/$DOKKU_DEPLOY_BRANCH") 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
fi fi
if [[ -z "$REF" ]]; then if [[ -z "$REF" ]]; then
return return 1
fi fi
# shellcheck disable=SC2086
git_build_app_repo $APP $REF git_build_app_repo "$APP" "$REF"
} }
git_receive_app() { git_receive_app() {
@@ -148,10 +149,11 @@ git_receive_app() {
if [[ ! -d "$DOKKU_ROOT/$APP/refs" ]]; then if [[ ! -d "$DOKKU_ROOT/$APP/refs" ]]; then
true true
else else
local exit_code=0
acquire_app_deploy_lock "$APP" "exclusive" acquire_app_deploy_lock "$APP" "exclusive"
# shellcheck disable=SC2086 git_build "$APP" "$REV" || exit_code="$?"
git_build $APP $REV
release_app_deploy_lock "$APP" release_app_deploy_lock "$APP"
return "$exit_code"
fi fi
} }
+9 -1
View File
@@ -3,4 +3,12 @@ source "$PLUGIN_AVAILABLE_PATH/git/functions"
set -eo pipefail set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x [[ $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 "$@"
+23
View File
@@ -12,6 +12,29 @@ teardown() {
global_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" { @test "(git) deploy specific branch" {
run /bin/bash -c "dokku git:set --global deploy-branch global-branch" run /bin/bash -c "dokku git:set --global deploy-branch global-branch"
echo "output: $output" echo "output: $output"