-
Notifications
You must be signed in to change notification settings - Fork 42
/
build.sh
205 lines (163 loc) · 4.8 KB
/
build.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/usr/bin/env bash
#set -e
export ROOT=$(pwd)
git_clone () {
git clone "${1}" "${2}" #> /dev/null 2>&1
if [ "$?" != "0" ]; then
return 1
fi
return 0
}
git_update_repos () {
repos=$1
version=$2
folder=$3
isFromJson=$4
echo "node $ROOT/sync.js create-component.json $repos $version $isFromJson $folder"
node $ROOT/sync.js create-component.json "$repos" "$version" "$isFromJson" "$folder"
if [ "$?" != "0" ]; then
return 1
fi
#AU
git config --global user.email "${GIT_EMAIL}"
git config --global user.name "${GIT_NAME}"
git config --global push.default simple
git config credential.helper "store --file=.git/credential"
echo "https://${GH_TOKEN}:@github.com" > .git/credential
git add -A -f
if [ "$isFromJson" = "true" ]; then
git commit -m "based on https://github.com/fis-components/components/blob/master/packages/${folder}${repos}.json" -a
else
git commit -m "based on https://github.com/fis-components/components/blob/master/modules/${folder}${repos}.js" -a
fi
git push origin master
git tag -a "$version" -m "create tag $version"
git push --tags
bos_sync $repos $version
}
bos_sync () {
echo "BOS Sync ${1}@${2}"
bash $ROOT/bosSync.sh $1 $2
if [ "$?" != "0" ]; then
exit 1
fi
}
save_hash() {
echo "Save hash ${1}@${2}@${3}"
bash $ROOT/saveHash.sh $1 $2 $3
if [ "$?" != "0" ]; then
exit 1
fi
}
export -f git_clone
export -f git_update_repos
export -f bos_sync
export -f save_hash
sync () {
new=$1
repos=$2
build=$3
version=$4
build_dest=$5
tag=$6
rebuild=$7
folder=$8
isFromJson=$9
echo "Folder is $folder"
dest="$ROOT/_$new"
echo "=SYNC ${new} from ${repos}, version: ${version}"
if [ -d "_${new}" ]; then
rm -rf "_${new}"
echo "=LOCAL rm -rf _${new}"
fi
git_clone "https://github.com/fis-components/${new}" "_${new}"
if [ "$?" != "0" ]; then
# new origin
node $ROOT/sync.js create-repos "${new}" "${GH_TOKEN}" "${repos}" "$folder" "$isFromJson"
if [ "$?" != "0" ]; then
exit 1
fi
git_clone "https://github.com/fis-components/${new}" "_${new}"
if [ "$?" != "0" ]; then
exit 1
fi
else
cd "_${new}"
git pull --all
found=$(git tag | grep $version)
if [ "$found" != "" ]; then
if [ "$rebuild" = "true" ]; then
echo "= Tag $version already exists, now deleting..."
#AU
git config --global user.email "${GIT_EMAIL}"
git config --global user.name "${GIT_NAME}"
git config --global push.default simple
git config credential.helper "store --file=.git/credential"
echo "https://${GH_TOKEN}:@github.com" > .git/credential
git tag -d "$version"
git push origin :refs/tags/$version
echo "= Clean all files"
git ls-files | xargs git rm
git commit -am "rm all files"
git push
else
echo "=TAG tag $version exists. Skiped!"
exit 0
fi
fi
cd $ROOT
fi
if [ -d $new ]; then
rm -rf $new
echo "=LOCAL rm -rf $new"
fi
git_clone $repos $new
if [ "$?" = "0" ]; then
cd $new
git checkout $tag
if [ "$?" != "0" ]; then
echo "=GIT: git checkout $tag fail."
exit 1
fi
# run build
if [ "$build" != "" ]; then
echo '=BUILD '$new
touch package.json
eval $build || ('=BUILD build fail.' 2>&1 || exit 1)
fi
# if [ -d "$build_dest" ]; then
# cp -rf "./${build_dest}" "$dest"
# fi
# if [ -d "./dist" ]; then
# cp -rf "./dist" "$dest"
# fi
else
if [ "$build" != "" ]; then
mkdir -p $new
cd $new
touch package.json
echo '=BUILD '$new
eval $build || ('=BUILD build fail.' 2>&1 || exit 1)
fi
fi
node $ROOT/sync.js move "$new" "$version" "$(pwd)" "$dest" "$folder" "$isFromJson"
node $ROOT/sync.js convert "$new" "$version" "$dest" "$folder" "$isFromJson"
if [ "$?" != "0" ]; then
echo '=ROADMAP move fail'
exit 1
fi
cd "$dest"
echo "=CD $dest"
git_update_repos "$new" "$version" "$folder" "$isFromJson"
if [ "$isFromJson" = "true" ]; then
save_hash "$new" "$version" "$folder"
fi
cd $ROOT
}
export -f sync
main () {
echo '#START build.sh'
sync "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
echo '#END build.sh'
}
main "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"