-
-
Notifications
You must be signed in to change notification settings - Fork 276
/
ci.sh
executable file
·326 lines (278 loc) · 8.49 KB
/
ci.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
#!/usr/bin/env bash
set -e
set -u
function display_usage {
echo "
Usage: ci.sh [flags] [release|legacy|experimental[/k/keyboard]]
Flags:
-no-exe Ignored, legacy flag
-upload-only Only upload keyboards already prepared
-zip-only Only prepare and transfer the database
-prepare-and-upload-only Prepare and upload keyboards but not database
"
exit 1
}
#
# Prevents 'clear' on exit of mingw64 bash shell
#
SHLVL=0
#
# Define paths; note Windows hosted bash assumptions for now
#
KEYBOARDROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
. "$KEYBOARDROOT/tools/jq.inc.sh"
RSYNC="$KEYBOARDROOT/tools/rsync.exe"
CI_CACHE="$KEYBOARDROOT/.cache"
if [ ! -z "${SEVENZ_HOME+x}" ]; then
APP7Z="$SEVENZ_HOME/7z"
else
APP7Z="/c/Program Files/7-Zip/7z.exe"
fi
. "$KEYBOARDROOT/servervars.sh"
. "$KEYBOARDROOT/resources/util.inc.sh"
. "$KEYBOARDROOT/resources/rsync-tools.sh"
function parse_args {
DO_CODESIGN=false
DO_UPLOAD_ONLY=false
DO_ZIP_ONLY=false
DO_DATA=true
DO_EXE=false
TARGET=
FLAG_COLOR=
START=
START_BASE=
START_KEYBOARD=
DO_UPDATE_COMPILER=true
FORCE_UPDATE_COMPILER=false
local lastkey=
local key
# Parse args
for key in "$@"; do
if [[ -z "$lastkey" ]]; then
case "$key" in
-upload-only)
DO_UPLOAD_ONLY=true
;;
-codesign)
DO_CODESIGN=true
;;
-zip-only)
DO_ZIP_ONLY=true
;;
-no-update-compiler)
DO_UPDATE_COMPILER=false
;;
-force-update-compiler)
FORCE_UPDATE_COMPILER=true
;;
-prepare-and-upload-only)
DO_DATA=false
;;
-no-exe)
# Ignore this flag; legacy only
;;
-no-color)
FLAG_COLOR=-no-color
;;
-color)
FLAG_COLOR=-color
;;
-start)
lastkey=$key
;;
-h|-\?)
display_usage
;;
*)
TARGET="$key"
esac
else
case "$lastkey" in
-start)
START="$key"
START_BASE=`dirname "$START"`
START_KEYBOARD=`basename "$START"`
if [[ "START_BASE" == "." ]]; then
START_BASE="$START"
fi
;;
esac
lastkey=
fi
done
}
parse_args "$@"
function run {
if [ ! -d "$CI_CACHE" ]; then
mkdir "$CI_CACHE"
fi
if [[ $DO_UPLOAD_ONLY == true ]]; then
if [ ! -d "$CI_CACHE/upload" ]; then
mkdir "$CI_CACHE/upload"
fi
rsync_to_downloads_keyman_com "$CI_CACHE/upload/" keyboards/ true
exit 0
fi
if [[ $DO_ZIP_ONLY == true ]]; then
if [ ! -d "$CI_CACHE/data" ]; then
mkdir "$CI_CACHE/data"
fi
if [ ! -d "$CI_CACHE/upload" ]; then
mkdir "$CI_CACHE/upload"
fi
zip_keyboard_info
rsync_to_downloads_keyman_com "$CI_CACHE/data/" data/ false
exit 0
fi
if [ -d "$CI_CACHE/upload" ]; then
rm -rf "$CI_CACHE/upload"
fi
mkdir "$CI_CACHE/upload"
if [ -d "$CI_CACHE/data" ]; then
rm -rf "$CI_CACHE/data"
fi
mkdir "$CI_CACHE/data"
upload_keyboards_by_target
if [[ $DO_DATA == true ]]; then
zip_keyboard_info
rsync_to_downloads_keyman_com "$CI_CACHE/data/" data/ false
fi
}
##
## Main function
##
function upload_keyboards_by_target {
if [[ "$TARGET" ]]; then
if [[ "$TARGET" == */* ]] && [[ (-d "$TARGET") ]]; then
group=$(cut -d / -f 1 <<< "$TARGET")
echo "${t_grn}--- Only uploading $group $TARGET ---${t_end}"
upload_keyboard $group "$TARGET"
elif [[ "$TARGET" == "release" ]] || [[ "$TARGET" == "legacy" ]] || [[ "$TARGET" == "experimental" ]]; then
# Assuming release|legacy|experimental
echo "${t_grn}--- Only uploading $TARGET ---${t_end}"
upload_keyboards "$TARGET"
else
echo "Invalid $TARGET"
display_usage
fi
else
upload_keyboards release
upload_keyboards legacy
upload_keyboards experimental
fi
rsync_to_downloads_keyman_com "$CI_CACHE/upload/" keyboards/ true
}
##
## Prepare for upload puts a file into the upload cache
## in preparation for it being rsync'd to the server
##
function prepare_for_upload {
local source_filename=$1
local upload_filename=$2
local upload_path=`dirname "$upload_filename"`
mkdir -p "$CI_CACHE/upload/$upload_path"
cp "$source_filename" "$CI_CACHE/upload/$upload_filename"
}
##
## Prepares a single keyboard for upload
##
function upload_keyboard {
local group=$1
local keyboard=$2
local base_keyboard=$(basename "$keyboard")
local shortname=$(basename $(dirname "$keyboard"))
local buildpath=$KEYBOARDROOT/$group/$shortname/$base_keyboard/build
local keyboard_info=$buildpath/$base_keyboard.keyboard_info
echo "${t_grn}Uploading $keyboard${t_end}"
[ -f "$keyboard_info" ] || die "Failed to locate $keyboard_info"
local package_filename=`cat "$keyboard_info" | $JQ -r '.packageFilename'`
local js_filename=`cat "$keyboard_info" | $JQ -r '.jsFilename'`
local min_required_version=`cat "$keyboard_info" | $JQ -r '.minKeymanVersion'`
local platform_windows=`cat "$keyboard_info" | $JQ -r '.platformSupport.windows'`
# jq returns 'null' if the entry is missing, instead of ''
if [[ $package_filename == "null" ]]; then
package_filename=
else
[ -f "$buildpath/$package_filename" ] || die "Failed to locate $buildpath/$package_filename"
fi
if [[ $js_filename == "null" ]]; then
js_filename=
else
[ -f "$buildpath/$js_filename" ] || die "Failed to locate $buildpath/$js_filename"
fi
local package_version=`cat "$keyboard_info" | $JQ -r '.version'`
local package_name=`cat "$keyboard_info" | $JQ -r '.name'`
local package_upload_path=$base_keyboard/$package_version/$package_filename
local keyboard_info_upload_path=$base_keyboard/$package_version/$base_keyboard.keyboard_info
local js_upload_path=$base_keyboard/$package_version/$js_filename
echo "${t_grn}Package name: $package_name${t_end}"
prepare_for_upload "$buildpath/$base_keyboard.keyboard_info" "$keyboard_info_upload_path"
if [[ ! -z $js_filename ]]; then
prepare_for_upload "$buildpath/$js_filename" "$js_upload_path"
fi
if [[ ! -z $package_filename ]]; then
prepare_for_upload "$buildpath/$package_filename" "$package_upload_path"
fi
}
##
## (Tweaked clone of build_keyboards in compile.sh)
##
function upload_keyboards {
# $1 = path to build keyboards
# for each keyboard, if a build.sh file exists, call it, otherwise, run the default
# build based on the folder name and location.
# excluded folders are: shared, packages and template
local group=$1
local excluded_folders=" shared packages template "
echo "Uploading keyboards for $1"
local shortname
for shortname in "$KEYBOARDROOT/$group/"*/ ; do
local base_shortname=$(basename "$shortname")
if [[ "$base_shortname" == '*' ]]; then
return 0
fi
if [[ "$excluded_folders" == *" $base_shortname "* ]]; then
echo "- Skipping folder $group/$base_shortname"
else
if [[ "$base_shortname" < "$START" ]]; then
echo "- Skipping folder $group/$base_shortname, before $START"
else
echo "- Uploading $group/$base_shortname"
local keyboard
for keyboard in "$shortname"*/ ; do
upload_keyboard "$group" "$keyboard"
done
fi
fi
done
#
# If a packages/ folder exists, we now need to build it. We have to wait until the keyboards are built because it
# depends on files created by the keyboards
#
if [ -d "$KEYBOARDROOT/$group/packages" ]; then
echo "- Building $group/packages"
local package
for package in "$KEYBOARDROOT/$group/packages/"*/ ; do
upload_keyboard "$group" "$package"
done
fi
return 0
}
##
## zips all .keyboard_info files from .cache/upload/ into .cache/data/keyboard_info.zip
##
function zip_keyboard_info {
# We use an @list file to give a specific list of files to
# 7z so that it does not include pathnames in the archive
# The "./" on the front of the search is also needed to force 7Z to not
# include pathnames in the archive
local files=(./.cache/upload/*/*/*.keyboard_info)
printf "%s\n" "${files[@]}" > .cache/keyboard_info.list
"$APP7Z" a ".cache/data/keyboard_info.zip" @.cache/keyboard_info.list
rm .cache/keyboard_info.list
}
############################################################################################
run
############################################################################################
# EOF
############################################################################################