This repository was archived by the owner on Apr 14, 2018. It is now read-only.
forked from lvivier/step-gh-pages
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathrun.sh
executable file
·151 lines (114 loc) · 3.27 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/sh
set -e
set +o pipefail
for variable in $(getAllStepVars)
do
if [ "${!variable}" == "false" ]; then
s_info "\"$variable\" was set to false, we will unset it therefore"
unset $variable
fi
done
if [ -n "$WERCKER_GIT_PUSH_GH_TOKEN" ]; then
setMessage "Your gh_token may be compromised. Please check https://github.com/leipert/step-git-push for more info"
fail "Your gh_token may be compromised. Please check https://github.com/leipert/step-git-push for more info"
fi
# LOAD OUR FUNCTIONS
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
. ${DIR}/functions.sh
repo=$(getRepoPath)
info "using github repo \"$repo\""
remoteURL=$(getRemoteURL)
if [ -z $remoteURL ]; then
s_fail "missing option \"gh_oauth\" or \"host\", aborting"
fi
s_info "remote URL will be $remoteURL"
baseDir=$(getBaseDir)
# setup branch
remoteBranch=$(getBranch)
cd $baseDir
rm -rf .git
localBranch="master"
# remove existing files
targetDir="/tmp/git-push"
rm -rf $targetDir
destDir=$targetDir
if [ -n "$WERCKER_GIT_PUSH_DESTDIR" ]; then
destDir=$targetDir/$WERCKER_GIT_PUSH_DESTDIR
fi
s_debug "before init"
# init repository
if [ -n "$WERCKER_GIT_PUSH_DISCARD_HISTORY" ]; then
initEmptyRepoAt $targetDir
else
cloneRepo $remoteURL $targetDir
if checkBranchExistence $targetDir $remoteBranch; then
checkoutBranch $targetDir $remoteBranch
localBranch=$remoteBranch
s_info "branch $remoteBranch exists on remote $remoteURL"
else
initEmptyRepoAt $targetDir
fi
fi
info "Initialized Repo in $targetDir"
cd $targetDir
mkdir -p $destDir
cd $destDir
echo $destDir $targetDir
s_debug "before clean"
if [ -n "$WERCKER_GIT_PUSH_CLEAN_REMOVED_FILES" ]; then
info "We will clean in $destDir"
ls -A | grep -v .git | xargs rm -rf
mkdir -p $destDir
fi
cd $targetDir
ls -A
cp -rf $baseDir* $destDir
s_debug "before config"
git config user.email "[email protected]"
git config user.name "werckerbot"
# generate cname file
createCNAME $targetDir
s_debug "base:" $baseDir: `ls -A $baseDir`
s_debug "target:" $targetDir: `ls -A $targetDir`
s_debug "dest:" $destDir: `ls -A $destDir`
tag=$WERCKER_GIT_PUSH_TAG
s_debug "before tagExtraction: $tag"
tag=$(getTag $tag $targetDir/)
s_debug "Tag after targetDir $tag"
tag=$(getTag $tag $destDir/)
s_debug "Tag after destDir $tag"
tag=$(getTag $tag $baseDir/)
s_debug "Tag after baseDir $tag"
if [ -n "$tag" ]; then
s_info "The commit will be tagged with $tag"
fi
cd $targetDir
git add --all . > /dev/null
if git diff --cached --exit-code --quiet; then
s_success "Nothing changed. We do not need to push"
else
git commit -am "[ci skip] deploy from $WERCKER_STARTED_BY" --allow-empty > /dev/null
pushBranch $remoteURL $localBranch $remoteBranch
fi
if [ -n "$WERCKER_GIT_PUSH_TAG" ]; then
tags="$(git tag -l)"
if [[ "$tags" =~ "$tag" ]]; then
s_info "tag $tag already exists"
if [ -n "$WERCKER_GIT_PUSH_TAG_OVERWRITE" ]; then
if git diff --exit-code --quiet $localBranch $tag; then
s_success "Nothing changed. We do not need to overwrite tag $tag"
else
s_info "tag $tag will be overwritten"
deleteTag $remoteURL $tag
pushTag $remoteURL $tag
fi
fi
else
pushTag $remoteURL $tag
fi
fi
s_debug "before unset"
for variable in $(getAllStepVars)
do
unset $variable
done