├── fixtures ├── package.json └── bower.json ├── wercker-step.yml ├── wercker.yml ├── tests ├── integration.sh └── unit.sh ├── README.md ├── run.sh └── functions.sh /fixtures/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version":"0.1.2" 3 | -------------------------------------------------------------------------------- /fixtures/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "version":"0.1.1" 3 | } 4 | -------------------------------------------------------------------------------- /wercker-step.yml: -------------------------------------------------------------------------------- 1 | name: git-push 2 | version: 0.7.7 3 | description: Deploy to a git branch in a given Repo 4 | keywords: 5 | - github 6 | - pages 7 | - deploy 8 | - git 9 | - bitbucket 10 | - push 11 | - tags 12 | -------------------------------------------------------------------------------- /wercker.yml: -------------------------------------------------------------------------------- 1 | box: wercker/default 2 | build: 3 | steps: 4 | - script: 5 | name: Run integration tests 6 | code: bash tests/integration.sh 7 | - script: 8 | name: Run unit tests 9 | code: bash tests/unit.sh 10 | - script: 11 | name: Remove unneeded files 12 | code: ls -A | grep -v .yml | grep -v .sh | grep -v .md | xargs rm -rf 13 | -------------------------------------------------------------------------------- /tests/integration.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set +e 3 | 4 | function info { 5 | echo INFO: $@ 6 | } 7 | 8 | function warning { 9 | echo WARNING: $@ 10 | } 11 | 12 | function success { 13 | echo SUCCESS: $@ 14 | } 15 | 16 | function fail { 17 | echo FATAL: $@ 18 | exit -1 19 | } 20 | 21 | function init { 22 | cd $currDir 23 | WERCKER_GIT_PUSH_REPO="leipert/xkcd-now-clock" 24 | WERCKER_GIT_PUSH_BRANCH="step-git-push-test" 25 | if [ -n "$GH_TOKEN" ]; then 26 | WERCKER_GIT_PUSH_GH_OAUTH="$GH_TOKEN" 27 | else 28 | WERCKER_GIT_PUSH_HOST="github.com" 29 | fi 30 | WERCKER_GIT_PUSH_BASEDIR="fixtures" 31 | WERCKER_GIT_PUSH_TAG="0.1.1" 32 | WERCKER_GIT_PUSH_DEBUG="true" 33 | WERCKER_GIT_PUSH_GH_PAGES_DOMAIN="foo.bar" 34 | } 35 | 36 | currDir=$( pwd ) 37 | . $currDir/functions.sh 38 | 39 | echo $currDir 40 | 41 | echo "foo" > $currDir/fixtures/foo 42 | init 43 | source $currDir/run.sh 44 | rm -rf $currDir/fixtures/foo 45 | 46 | init 47 | WERCKER_GIT_PUSH_CLEAN_REMOVED_FILES="true" 48 | WERCKER_GIT_PUSH_GH_PAGES_DOMAIN="foo2.bar" 49 | WERCKER_GIT_PUSH_TAG_OVERWRITE="true" 50 | source $currDir/run.sh 51 | 52 | init 53 | WERCKER_GIT_PUSH_CLEAN_REMOVED_FILES="false" 54 | WERCKER_GIT_PUSH_GH_PAGES_DOMAIN="false" 55 | WERCKER_GIT_PUSH_TAG_OVERWRITE="false" 56 | WERCKER_GIT_PUSH_TAG="bower" 57 | mkdir -p $currDir/fixtures/dest 58 | touch $currDir/fixtures/dest/foo 59 | WERCKER_GIT_PUSH_DESTDIR="dest" 60 | source $currDir/run.sh 61 | rm -rf $currDir/fixtures/dest 62 | 63 | init 64 | cd /tmp/git-push 65 | git push $(getRemoteURL) --delete $WERCKER_GIT_PUSH_TAG >/dev/null 2>&1 66 | git push $(getRemoteURL) --delete $WERCKER_GIT_PUSH_BRANCH >/dev/null 2>&1 67 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Git Branch Deploy 2 | 3 | A [wercker](http://wercker.com/) step to deploy to a certain git branch in a repo. Supports also [Github Pages](http://pages.github.com/). 4 | 5 | # IMPORTANT SECURITY NOTICE: 6 | 7 | If your wercker app is public and you use the setting `gh_token`, it could be that your Auth token has been compromised. 8 | 9 | Please change your token as quick as possible [here](https://github.com/settings/applications#personal-access-tokens) 10 | and use the `gh_oauth` option instead of `gh_token`. 11 | 12 | Sorry for the inconvience. I reworked the complete wercker step, added unit and integration tests and more importantly there is now a function, which replaces oauth tokens in logs with `oauth-token`. 13 | 14 | Builds containing `gh_token` will fail. 15 | 16 | ## Options 17 | 18 | You either have to define a `gh_oauth` token if you deploy to github or a `host` if you want to deploy via SSH. 19 | (Please use wercker steps `leipert/add-ssh-key-gh-bb` and `add-to-known_hosts` to setup your SSH token for github and bitbucket) 20 | 21 | - `gh_oauth` *optional* Github API access token, if you want to deploy to github. ([documentation](https://github.com/blog/1509-personal-api-tokens)). **don't share this on a public repo, use an environment variable!** 22 | - `host` *optional* Set this to a host like "example.org". Defaults to your build host or github if `gh_oauth` is used. 23 | - `user` *optional* Set this to the ssh user of your git instance. Defaults to git. 24 | - `repo` *optional* Set this to a repo like "username/repo". Defaults to your build repo. 25 | - `branch` *optional* If set this branch will be used as deploy goal. Defaults to build master 26 | - `basedir` *optional* Set this if your build step outputs to a folder 27 | - `destdir` *optional* Specifies the directory in the remote repo to copy the files to 28 | - `clean_removed_files` *optional* Cleans removed files if set. Default will keep old files if they are not overwritten. 29 | - `discard_history` **DANGER** *optional* Discards history of that branch. Use with care as it could destroy your whole programming history. 30 | - `gh_pages` *optional* Set this to true if you want to deploy to [Github Pages](http://pages.github.com/). The Branch will be set accordingly. 31 | - `gh_pages_domain` *optional* Custom domain ([documentation](https://help.github.com/articles/setting-up-a-custom-domain-with-pages)) 32 | - `tag` *optional* Adds a tag to the pushed commit. Valid options are bower, node or any string. 33 | - `tag_overwrite` *optional* If set, tags will be overwritten 34 | 35 | ## Example 36 | 37 | For Github Pages: 38 | ``` 39 | deploy: 40 | steps: 41 | - git-push: 42 | gh_oauth: $GH_TOKEN 43 | gh_pages: true 44 | gh_pages_domain: example.org 45 | basedir: build 46 | ``` 47 | Deploy with SSH 48 | ``` 49 | deploy: 50 | steps: 51 | # Add SSH-Key to 52 | - leipert/add-ssh-key-gh-bb: 53 | keyname: DEPLOY_SSH 54 | # Add bitbucket to known hosts, so they won't ask us whether we trust bitbucket 55 | - add-to-known_hosts: 56 | hostname: bitbucket.org 57 | fingerprint: 97:8c:1b:f2:6f:14:6b:5c:3b:ec:aa:46:46:74:7c:40 58 | - git-push: 59 | host: bitbucket.org 60 | repo: example/exampleRepo 61 | branch: example 62 | basedir: build 63 | ``` 64 | -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | set +o pipefail 4 | 5 | for variable in $(getAllStepVars) 6 | do 7 | if [ "${!variable}" == "false" ]; then 8 | s_info "\"$variable\" was set to false, we will unset it therefore" 9 | unset $variable 10 | fi 11 | done 12 | 13 | if [ -n "$WERCKER_GIT_PUSH_GH_TOKEN" ]; then 14 | setMessage "Your gh_token may be compromised. Please check https://github.com/leipert/step-git-push for more info" 15 | fail "Your gh_token may be compromised. Please check https://github.com/leipert/step-git-push for more info" 16 | fi 17 | 18 | # LOAD OUR FUNCTIONS 19 | DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) 20 | . ${DIR}/functions.sh 21 | 22 | repo=$(getRepoPath) 23 | 24 | info "using github repo \"$repo\"" 25 | 26 | remoteURL=$(getRemoteURL) 27 | if [ -z $remoteURL ]; then 28 | s_fail "missing option \"gh_oauth\" or \"host\", aborting" 29 | fi 30 | s_info "remote URL will be $remoteURL" 31 | 32 | baseDir=$(getBaseDir) 33 | 34 | # setup branch 35 | remoteBranch=$(getBranch) 36 | 37 | cd $baseDir 38 | rm -rf .git 39 | 40 | localBranch="master" 41 | 42 | # remove existing files 43 | targetDir="/tmp/git-push" 44 | rm -rf $targetDir 45 | 46 | destDir=$targetDir 47 | 48 | if [ -n "$WERCKER_GIT_PUSH_DESTDIR" ]; then 49 | destDir=$targetDir/$WERCKER_GIT_PUSH_DESTDIR 50 | fi 51 | 52 | s_debug "before init" 53 | 54 | # init repository 55 | if [ -n "$WERCKER_GIT_PUSH_DISCARD_HISTORY" ]; then 56 | initEmptyRepoAt $targetDir 57 | else 58 | cloneRepo $remoteURL $targetDir 59 | if checkBranchExistence $targetDir $remoteBranch; then 60 | checkoutBranch $targetDir $remoteBranch 61 | localBranch=$remoteBranch 62 | s_info "branch $remoteBranch exists on remote $remoteURL" 63 | else 64 | initEmptyRepoAt $targetDir 65 | fi 66 | fi 67 | 68 | info "Initialized Repo in $targetDir" 69 | 70 | cd $targetDir 71 | mkdir -p $destDir 72 | 73 | cd $destDir 74 | 75 | echo $destDir $targetDir 76 | 77 | s_debug "before clean" 78 | 79 | if [ -n "$WERCKER_GIT_PUSH_CLEAN_REMOVED_FILES" ]; then 80 | info "We will clean in $destDir" 81 | ls -A | grep -v .git | xargs rm -rf 82 | mkdir -p $destDir 83 | fi 84 | 85 | cd $targetDir 86 | 87 | ls -A 88 | 89 | cp -rf $baseDir* $destDir 90 | 91 | s_debug "before config" 92 | 93 | git config user.email "pleasemailus@wercker.com" 94 | git config user.name "werckerbot" 95 | 96 | # generate cname file 97 | createCNAME $targetDir 98 | s_debug "base:" $baseDir: `ls -A $baseDir` 99 | s_debug "target:" $targetDir: `ls -A $targetDir` 100 | s_debug "dest:" $destDir: `ls -A $destDir` 101 | 102 | tag=$WERCKER_GIT_PUSH_TAG 103 | s_debug "before tagExtraction: $tag" 104 | 105 | tag=$(getTag $tag $targetDir/) 106 | s_debug "Tag after targetDir $tag" 107 | tag=$(getTag $tag $destDir/) 108 | s_debug "Tag after destDir $tag" 109 | tag=$(getTag $tag $baseDir/) 110 | s_debug "Tag after baseDir $tag" 111 | 112 | if [ -n "$tag" ]; then 113 | s_info "The commit will be tagged with $tag" 114 | fi 115 | 116 | cd $targetDir 117 | 118 | git add --all . > /dev/null 119 | 120 | if git diff --cached --exit-code --quiet; then 121 | s_success "Nothing changed. We do not need to push" 122 | else 123 | git commit -am "[ci skip] deploy from $WERCKER_STARTED_BY" --allow-empty > /dev/null 124 | pushBranch $remoteURL $localBranch $remoteBranch 125 | fi 126 | 127 | if [ -n "$WERCKER_GIT_PUSH_TAG" ]; then 128 | tags="$(git tag -l)" 129 | if [[ "$tags" =~ "$tag" ]]; then 130 | s_info "tag $tag already exists" 131 | if [ -n "$WERCKER_GIT_PUSH_TAG_OVERWRITE" ]; then 132 | if git diff --exit-code --quiet $localBranch $tag; then 133 | s_success "Nothing changed. We do not need to overwrite tag $tag" 134 | else 135 | s_info "tag $tag will be overwritten" 136 | deleteTag $remoteURL $tag 137 | pushTag $remoteURL $tag 138 | fi 139 | fi 140 | else 141 | pushTag $remoteURL $tag 142 | fi 143 | fi 144 | 145 | 146 | s_debug "before unset" 147 | 148 | for variable in $(getAllStepVars) 149 | do 150 | unset $variable 151 | done 152 | -------------------------------------------------------------------------------- /functions.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function getAllStepVars { 4 | ( set -o posix ; set ) | grep WERCKER_GIT_PUSH | sed -E 's/=.+//g' | xargs 5 | } 6 | 7 | function sanitizeOutput { 8 | echo "$@" | sed -E 's_(.+://).+@_\1oauth-token@_g' 9 | } 10 | 11 | function s_info { 12 | info "$(sanitizeOutput $@)" 13 | } 14 | 15 | function s_success { 16 | success "$(sanitizeOutput $@)" 17 | } 18 | 19 | function s_debug { 20 | if [ "$WERCKER_GIT_PUSH_DEBUG" == "true" ]; then 21 | info "DEBUG: $(sanitizeOutput $@)" 22 | fi 23 | } 24 | 25 | function s_warning { 26 | info "WARNING: $(sanitizeOutput $@)" 27 | } 28 | 29 | function s_fail { 30 | fail "$(sanitizeOutput $@)" 31 | } 32 | 33 | function s_setMessage { 34 | setMessage "$(sanitizeOutput $@)" 35 | } 36 | 37 | # RETURNS REPO_PATH SET in GIT_PUSH or current WERCKER 38 | function getRepoPath { 39 | if [ -n "$WERCKER_GIT_PUSH_REPO" ]; then 40 | echo "$WERCKER_GIT_PUSH_REPO" 41 | else 42 | echo "$WERCKER_GIT_OWNER/$WERCKER_GIT_REPOSITORY" 43 | fi 44 | } 45 | 46 | #RETURNS FULL REMOTE PATH OF THE REPO 47 | function getRemoteURL { 48 | repo=$(getRepoPath) 49 | if [ -n "$WERCKER_GIT_PUSH_GH_OAUTH" ]; then 50 | echo "https://$WERCKER_GIT_PUSH_GH_OAUTH@github.com/$repo.git" 51 | elif [ -n "$WERCKER_GIT_PUSH_HOST" ]; then 52 | git_user=$(getGitSSHUser) 53 | echo "$git_user@$WERCKER_GIT_PUSH_HOST:$repo.git" 54 | else 55 | echo "" 56 | fi 57 | } 58 | 59 | #RETURNS GIT SSH USER 60 | function getGitSSHUser { 61 | if [ -n "$WERCKER_GIT_PUSH_USER" ]; then 62 | echo "$WERCKER_GIT_PUSH_USER" 63 | else 64 | echo "git" 65 | fi 66 | } 67 | 68 | #RETURNS BRANCH WE WANT TO PUSH TO 69 | function getBranch { 70 | if [ -n "$WERCKER_GIT_PUSH_GH_PAGES" ]; then 71 | if [[ $(getRepoPath) =~ $WERCKER_GIT_OWNER\/$WERCKER_GIT_OWNER\.github\.(io|com)$ ]]; then 72 | echo "master" 73 | else 74 | echo "gh-pages" 75 | fi 76 | elif [ -n "$WERCKER_GIT_PUSH_BRANCH" ]; then 77 | echo "$WERCKER_GIT_PUSH_BRANCH" 78 | else 79 | echo "$WERCKER_GIT_BRANCH" 80 | fi 81 | } 82 | 83 | #RETURNS BASE DIR WE WANT TO PUSH FROM 84 | function getBaseDir { 85 | 86 | # if directory provided, cd to it 87 | if [ -n "$WERCKER_GIT_PUSH_BASEDIR" ]; then 88 | echo $(pwd)/$WERCKER_GIT_PUSH_BASEDIR/ 89 | else 90 | echo $(pwd)/ 91 | fi 92 | 93 | } 94 | 95 | function initEmptyRepoAt { 96 | 97 | cd 98 | rm -rf $1 99 | mkdir -p $1 100 | cd $1 101 | git init -q 102 | 103 | } 104 | 105 | function cloneRepo { 106 | result=$(git clone $1 $2 -q 2>&1) 107 | if [[ $? -ne 0 ]]; then 108 | s_warning "$result" 109 | s_fail "failed to clone repo" 110 | fi 111 | } 112 | 113 | function checkBranchExistence { 114 | cd $1 115 | git ls-remote -q --exit-code . origin/$2 > /dev/null 116 | } 117 | 118 | function checkoutBranch { 119 | cd $1 120 | result=$(git checkout $2 -q 2>&1) 121 | if [[ $? -ne 0 ]]; then 122 | s_warning "$result" 123 | s_fail "failed to checkout existing branch $2" 124 | fi 125 | } 126 | 127 | function getTagWithPython { 128 | result=$(cat $1 | python -c 'import sys, json; print json.load(sys.stdin)["version"]' 2>&1); 129 | if [[ $? -ne 0 ]]; then 130 | s_warning "$result" 131 | s_fail "Could not load version from $1" 132 | else 133 | echo "$result" 134 | fi 135 | } 136 | 137 | function getTagWithNode { 138 | result=$(node -p "require(\"$1\").version" 2>&1) 139 | if [[ $? -ne 0 ]]; then 140 | s_warning "$result" 141 | s_fail "Could not load version from $1" 142 | else 143 | echo "$result" 144 | fi 145 | } 146 | 147 | function getTagFromJSON { 148 | if [ -f $1$2 ]; then 149 | if [ -n "`which node`" ]; then 150 | getTagWithNode $1$2 151 | else 152 | if [ -n "`which python`" ]; then 153 | getTagWithPython $1$2 154 | else 155 | echo "$3" 156 | fi 157 | fi 158 | else 159 | echo "$3" 160 | fi 161 | } 162 | 163 | function getTag { 164 | if [ -n "$1" ]; then 165 | case $1 in 166 | "bower") getTagFromJSON $2 "bower.json" $1 ;; 167 | "node") getTagFromJSON $2 "package.json" $1 ;; 168 | *) echo $1;; 169 | esac 170 | fi 171 | } 172 | 173 | function createCNAME { 174 | if [ -n "$WERCKER_GIT_PUSH_GH_PAGES_DOMAIN" ]; then 175 | echo $WERCKER_GIT_PUSH_GH_PAGES_DOMAIN > "$1/CNAME" 176 | s_info "Will create CNAME file: $1/CNAME" 177 | fi 178 | } 179 | 180 | function pushBranch { 181 | result="$(git push -q -f $1 $2:$3 2>&1)" 182 | if [[ $? -ne 0 ]]; then 183 | s_warning "$result" 184 | s_fail "failed pushing to $3 on $1" 185 | else 186 | s_success "pushed to $3 on $1" 187 | fi 188 | } 189 | 190 | function pushTag { 191 | git tag -a $2 -m "Tagged by $WERCKER_STARTED_BY" -f > /dev/null 192 | result="$(git push --tags $1 2>&1)" 193 | if [[ $? -ne 0 ]]; then 194 | s_warning "$result" 195 | s_fail "failed pushing to tag $1 with $2" 196 | else 197 | s_success "tagged $1 with $2" 198 | fi 199 | } 200 | 201 | function deleteTag { 202 | git tag -d $2 > /dev/null 203 | result="$(git push $1 --delete refs/tags/$2 2>&1)" 204 | if [[ $? -ne 0 ]]; then 205 | s_warning "$result" 206 | s_fail "failed delete $2 from $1" 207 | fi 208 | } 209 | -------------------------------------------------------------------------------- /tests/unit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set +e 3 | 4 | failed=false 5 | throwError=false 6 | 7 | DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) 8 | . ${DIR}/../functions.sh 9 | 10 | function error { 11 | echo ERROR: $@ 12 | throwError=true 13 | } 14 | 15 | function s_info { 16 | echo INFO: $@ 17 | } 18 | 19 | function s_warning { 20 | echo > /dev/null 21 | } 22 | 23 | function success { 24 | echo SUCCESS: $@ 25 | } 26 | 27 | function s_fail { 28 | failed=true 29 | } 30 | 31 | function fail { 32 | echo "FATAL: $@" 33 | exit -1 34 | } 35 | 36 | currDir=$(pwd); 37 | 38 | cd $currDir; rm -rf foo 39 | 40 | # TEST URL SANITATION 41 | [ $(sanitizeOutput "https://1234@gh") != "https://oauth-token@gh" ] && error "We should replace oauth token in https" 42 | [ $(sanitizeOutput "http://1234@gh") != "http://oauth-token@gh" ] && error "We should replace oauth token in http" 43 | [ $(sanitizeOutput "git://1234:1224@gh") != "git://oauth-token@gh" ] && error "We should replace oauth token in git url" 44 | [ $(sanitizeOutput "git@github.com:leipert/step-git-push.git") != "git@github.com:leipert/step-git-push.git" ] && error "We should not replace oauth token in git url" 45 | 46 | WERCKER_GIT_REPOSITORY="step-git-push" 47 | WERCKER_GIT_OWNER="leipert" 48 | WERCKER_GIT_BRANCH="default" 49 | 50 | ## TEST getRepoPath 51 | 52 | WERCKER_GIT_PUSH_REPO="oxofrmbl" 53 | 54 | [ $(getRepoPath) != "oxofrmbl" ] && error "$(getRepoPath) != oxofrmbl" 55 | 56 | unset WERCKER_GIT_PUSH_REPO; 57 | 58 | [ $(getRepoPath) != "leipert/step-git-push" ] && error "$(getRepoPath) != leipert/step-git-push" 59 | 60 | ## Test getGitSSHUser 61 | 62 | WERCKER_GIT_PUSH_USER="foo" 63 | 64 | [ $(getGitSSHUser) != "foo" ] && error "$(getGitSSHUser) != foo" 65 | 66 | unset WERCKER_GIT_PUSH_USER 67 | 68 | [ $(getGitSSHUser) != "git" ] && error "$(getGitSSHUser) != git" 69 | 70 | ## Test getRemoteURL 71 | 72 | [ ! getRemoteURL ] && error "Script should error here" 73 | 74 | WERCKER_GIT_PUSH_GH_OAUTH=1234 75 | 76 | [ $(getRemoteURL) != "https://1234@github.com/leipert/step-git-push.git" ] && error "$(getRemoteURL) != https://1234@github.com/leipert/step-git-push.git" 77 | 78 | unset WERCKER_GIT_PUSH_GH_OAUTH 79 | WERCKER_GIT_PUSH_HOST="github.com" 80 | 81 | [ $(getRemoteURL) != "git@github.com:leipert/step-git-push.git" ] && error "$(getRemoteURL) != git@github.com:leipert/step-git-push.git" 82 | 83 | ## TEST getBranch 84 | 85 | [ $(getBranch) != "default" ] && error "$(getBranch) != default" 86 | 87 | WERCKER_GIT_PUSH_BRANCH="dist" 88 | 89 | [ $(getBranch) != "dist" ] && error "$(getBranch) != dist" 90 | 91 | WERCKER_GIT_PUSH_GH_PAGES="true" 92 | 93 | [ $(getBranch) != "gh-pages" ] && error "$(getBranch) != gh-pages" 94 | 95 | WERCKER_GIT_PUSH_REPO="leipert/leipert.github.io" 96 | [ $(getBranch) != "master" ] && error "$(getBranch) != master" 97 | 98 | ## TEST getBaseDir 99 | 100 | WERCKER_GIT_PUSH_BASEDIR="foo" 101 | 102 | [ $(getBaseDir) != $(pwd)/foo/ ] && error "$(getBaseDir) != "$(pwd)/foo/ 103 | 104 | unset WERCKER_GIT_PUSH_BASEDIR 105 | 106 | [ $(getBaseDir) != $(pwd)/ ] && error "$(getBaseDir) != "$(pwd)/ 107 | 108 | ## TEST init empty Repo 109 | 110 | #cd $(pwd); rm -rf foo 111 | 112 | initEmptyRepoAt $(pwd)/foo 113 | [ ! -d .git ] && error "Could not initialize empty repo" 114 | cd $currDir; rm -rf foo 115 | 116 | ## Test cloning of repo 117 | if [ -n "$GH_TOKEN" ]; then 118 | WERCKER_GIT_PUSH_GH_OAUTH="$GH_TOKEN" 119 | else 120 | WERCKER_GIT_PUSH_HOST="github.com" 121 | fi 122 | 123 | WERCKER_GIT_PUSH_REPO="leipert/non-existing" 124 | 125 | cloneRepo $(getRemoteURL) $currDir/foo 126 | [ $failed != "true" ] && error "A non existing repository should have not be cloned" 127 | failed=false; cd $currDir; rm -rf foo 128 | 129 | WERCKER_GIT_PUSH_REPO="leipert/step-git-push" 130 | 131 | cloneRepo $(getRemoteURL) $currDir/foo 132 | cd $currDir; 133 | 134 | ## Test of whether branch existence test works 135 | checkBranchExistence $currDir/foo "master" 136 | [ $? != "0" ] && error "master branch should exist" 137 | 138 | checkBranchExistence $currDir/foo "non-existing" 139 | [ $? == "0" ] && error "non existing branch should not exist" 140 | 141 | ## Test if we can checkout branches 142 | checkoutBranch $currDir/foo "master" 143 | [ $? != "0" ] && error "Should be able to checkout existing master branch" 144 | 145 | checkoutBranch $currDir/foo "non-existing" 146 | [ $failed != "true" ] && error "Should not be able to checkout non-existing branch" 147 | failed=false 148 | 149 | ## Test if we get the right tags 150 | 151 | [ $(getTag "foo") != "foo" ] && error "$(getTag) != foo" 152 | 153 | [ $(getTag "bower" $currDir/fixtures/) != "0.1.1" ] && error "$(getTag "bower" $currDir/fixtures/) != 0.1.1" 154 | 155 | getTag "node" $currDir/fixtures/ 156 | [ $failed != "true" ] && error "Malformatted package.json should fail" 157 | failed=false 158 | 159 | ## TEST CNAME Creation 160 | WERCKER_GIT_PUSH_GH_PAGES_DOMAIN="foo.bar" 161 | createCNAME $currDir/ > /dev/null 162 | [ ! -f $currDir/CNAME ] && error "This should create a CNAME file" 163 | rm -rf $currDir/CNAME 164 | 165 | rm -rf $currDir/foo 166 | if [ $throwError == "true" ]; then 167 | fail "Something failed" 168 | else 169 | success "UNIT TESTS RAN SUCCESSFUL" 170 | fi 171 | --------------------------------------------------------------------------------