From 98c81513aa0f933544a86725dc9d3e2b64ceceff Mon Sep 17 00:00:00 2001 From: Kazuhiro NISHIYAMA Date: Tue, 8 Dec 2020 23:15:11 +0900 Subject: [PATCH] Accept first pushed branch as deploy-branch And set to DOKKU_DEPLOY_BRANCH. Idea from https://github.com/dokku/dokku/pull/4167#issuecomment-717607136 --- plugins/git/functions | 5 ++++- plugins/git/internal-functions | 3 ++- tests.mk | 5 +++++ tests/test_deploy | 5 +++-- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/plugins/git/functions b/plugins/git/functions index 91fc4464a..fd8a9a6e8 100755 --- a/plugins/git/functions +++ b/plugins/git/functions @@ -139,12 +139,15 @@ cmd-git-hook() { # if block if you wish to run it for others as well. if [[ $refname == "refs/heads/${DOKKU_DEPLOY_BRANCH}" ]]; then # broken out into plugin so we might support other methods to receive an app - # shellcheck disable=SC2086 git_receive_app "$APP" "$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 + elif [[ -z "$(fn-git-deploy-branch "$APP" "")" ]]; then + echo $'\e[1G\e[K'"-----> Set ${refname/refs\/heads\//} to DOKKU_DEPLOY_BRANCH." + fn-plugin-property-write "git" "$app" "deploy-branch" "${refname/refs\/heads\//}" + git_receive_app "$APP" "$newrev" else echo $'\e[1G\e[K'"-----> WARNING: deploy did not complete, you must push to ${DOKKU_DEPLOY_BRANCH}." echo $'\e[1G\e[K'"-----> for example, try 'git push ${refname/refs\/heads\//}:${DOKKU_DEPLOY_BRANCH}'" diff --git a/plugins/git/internal-functions b/plugins/git/internal-functions index b41010739..525ad122e 100755 --- a/plugins/git/internal-functions +++ b/plugins/git/internal-functions @@ -85,6 +85,7 @@ fn-git-last-updated-at() { fn-git-deploy-branch() { declare desc="retrieve the deploy branch for a given application" local APP="$1" + local DEFAULT_BRANCH="${2-master}" local DOKKU_DEPLOY_BRANCH="$(fn-plugin-property-get "git" "$APP" "deploy-branch" "")" local DOKKU_GLOBAL_DEPLOY_BRANCH="$(fn-plugin-property-get "git" "--global" "deploy-branch" "")" @@ -93,6 +94,6 @@ fn-git-deploy-branch() { elif [[ -n "$DOKKU_GLOBAL_DEPLOY_BRANCH" ]]; then echo "$DOKKU_GLOBAL_DEPLOY_BRANCH" else - echo "master" + echo "$DEFAULT_BRANCH" fi } diff --git a/tests.mk b/tests.mk index 63fd1774c..0e5f4312c 100644 --- a/tests.mk +++ b/tests.mk @@ -182,6 +182,10 @@ deploy-test-checks-root: @echo deploying checks-root app... cd tests && ./test_deploy ./apps/checks-root dokku.me '' true +deploy-test-main-branch: + @echo deploying checks-root app to main branch... + cd tests && ./test_deploy ./apps/checks-root dokku.me '' true main + deploy-test-clojure: @echo deploying config app... cd tests && ./test_deploy ./apps/clojure dokku.me @@ -253,6 +257,7 @@ deploy-test-static: deploy-tests: @echo running deploy tests... @$(QUIET) $(MAKE) deploy-test-checks-root + @$(QUIET) $(MAKE) deploy-test-main-branch @$(QUIET) $(MAKE) deploy-test-go-fail-predeploy @$(QUIET) $(MAKE) deploy-test-go-fail-postdeploy @$(QUIET) $(MAKE) deploy-test-config diff --git a/tests/test_deploy b/tests/test_deploy index 20e36b2c4..4a2dc5eee 100755 --- a/tests/test_deploy +++ b/tests/test_deploy @@ -6,6 +6,7 @@ APP="$1" TARGET="$2" FORWARDED_PORT="$3" SHOULD_FAIL="$4" +BRANCH="${5:-master}" REMOTE="dokku@$TARGET" REPO="test-$(basename "$APP")-$RANDOM" @@ -43,9 +44,9 @@ git add . [[ -x pre-commit ]] && ./pre-commit "$REMOTE" "$REPO" git commit -m 'initial commit' if [[ "$SHOULD_FAIL" == true ]]; then - git push target master && succeeded git-push + git push target "master:$BRANCH" && succeeded git-push else - git push target master || failed git-push + git push target "master:$BRANCH" || failed git-push fi if [[ -x post-deploy ]]; then ./post-deploy "$REMOTE" "$REPO" || failed post-deploy