Skip to content

Commit

Permalink
refactor: move branch name fetching to new script
Browse files Browse the repository at this point in the history
Also properly detect injected branch name.
  • Loading branch information
Jose Diaz-Gonzalez committed Dec 4, 2020
1 parent 9f67113 commit d3c7094
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 24 deletions.
26 changes: 2 additions & 24 deletions bin/dokku-deploy
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,12 @@ ssh_remote="ssh://dokku@$(parse-ssh-host):$(parse-ssh-port)"

if [ "$COMMAND" = "review-apps:create" ] || [ "$COMMAND" = 'review-apps:destroy' ]; then
if [ -z "$REVIEW_APP_NAME" ]; then
CI_BRANCH_NAME=""
if [ -n "$CI_COMMIT_REF_NAME" ]; then
# gitlab-ci
CI_BRANCH_NAME="$CI_COMMIT_REF_NAME"
elif [ -n "$GITHUB_REF" ]; then
# github actions
CI_BRANCH_NAME="${GITHUB_REF#refs/heads/}"
elif [ -n "$CIRCLE_BRANCH" ]; then
# circleci
CI_BRANCH_NAME="$CIRCLE_BRANCH"
elif [ -n "$TRAVIS_BRANCH" ]; then
# travisci
CI_BRANCH_NAME="$TRAVIS_BRANCH"
elif [ -n "$SEMAPHORE_GIT_BRANCH" ]; then
# semaphoreci
CI_BRANCH_NAME="SEMAPHORE_GIT_BRANCH"
elif [ -n "$CI_BRANCH" ]; then
# cloudbees
CI_BRANCH_NAME="CI_BRANCH"
elif [ -n "$DRONE_COMMIT_BRANCH" ]; then
# drone
CI_BRANCH_NAME="DRONE_COMMIT_BRANCH"
else
CI_BRANCH_NAME="$(parse-ci-branch-name)"
if [ -z "$CI_BRANCH_NAME" ]; then
log-error "Unable to detect branch name and cannot generate review app name"
exit 1
fi

CI_BRANCH_NAME="$(echo "$CI_BRANCH_NAME" | tr '[:upper:]' '[:lower:]' | sed "s/[[:alpha:].-]/-/g")"
REVIEW_APP_NAME="review-${app_name}-${CI_BRANCH_NAME}"
log-info "No review app name specified, using $REVIEW_APP_NAME"
fi
Expand Down
32 changes: 32 additions & 0 deletions bin/parse-ci-branch-name
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh -l
set -e

value="$CI_BRANCH_NAME"
if [ -n "$CI_BRANCH_NAME" ]; then
true
elif [ -n "$CI_COMMIT_REF_NAME" ]; then
# gitlab-ci
value="$CI_COMMIT_REF_NAME"
elif [ -n "$GITHUB_REF" ]; then
# github actions
value="${GITHUB_REF#refs/heads/}"
elif [ -n "$CIRCLE_BRANCH" ]; then
# circleci
value="$CIRCLE_BRANCH"
elif [ -n "$TRAVIS_BRANCH" ]; then
# travisci
value="$TRAVIS_BRANCH"
elif [ -n "$SEMAPHORE_GIT_BRANCH" ]; then
# semaphoreci
value="SEMAPHORE_GIT_BRANCH"
elif [ -n "$CI_BRANCH" ]; then
# cloudbees
value="CI_BRANCH"
elif [ -n "$DRONE_COMMIT_BRANCH" ]; then
# drone
value="DRONE_COMMIT_BRANCH"
else
exit 0
fi

echo "$value" | tr '[:upper:]' '[:lower:]' | sed "s/[[:alpha:].-]/-/g"

0 comments on commit d3c7094

Please sign in to comment.