Accept first pushed branch as deploy-branch

And set to DOKKU_DEPLOY_BRANCH.

Idea from https://github.com/dokku/dokku/pull/4167#issuecomment-717607136
This commit is contained in:
Kazuhiro NISHIYAMA
2020-12-08 23:15:11 +09:00
parent cbd442fc2e
commit 98c81513aa
4 changed files with 14 additions and 4 deletions

View File

@@ -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 <dokku> ${refname/refs\/heads\//}:${DOKKU_DEPLOY_BRANCH}'"

View File

@@ -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
}

View File

@@ -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

View File

@@ -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