forked from keymanapp/lexical-models
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci.sh
224 lines (185 loc) · 6.28 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
#!/bin/bash
function display_usage {
echo "Usage: ci.sh [release|experimental[/m/model]]"
exit 1
}
#
# Prevents 'clear' on exit of mingw64 bash shell
#
SHLVL=0
#
# Define paths; note Windows hosted bash assumptions for now
#
MODELROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
JQ="$MODELROOT/tools/jq-win64.exe"
RSYNC="$MODELROOT/tools/rsync.exe"
CI_CACHE="$MODELROOT/.cache"
if [ ! -z "$SEVENZ_HOME" ]; then
APP7Z="$SEVENZ_HOME/7z"
else
APP7Z="/c/Program Files/7-Zip/7z.exe"
fi
. "$MODELROOT/servervars.sh"
. "$MODELROOT/resources/util.sh"
. "$MODELROOT/resources/rsync-tools.sh"
parse_args "$@"
setup_colors
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/" models/ 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_model_info
rsync_to_downloads_keyman_com "$CI_CACHE/data/" data/
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_models_by_target
zip_model_info
rsync_to_downloads_keyman_com "$CI_CACHE/data/" data/
}
##
## Main function
##
function upload_models_by_target {
if [[ "$TARGET" ]]; then
if [[ "$TARGET" == */* ]] && [[ (-d "$TARGET") ]]; then
group=$(cut -d / -f 1 <<< "$TARGET")
author=$(cut -d / -f 2 <<< "$TARGET")
echo "${t_grn}--- Only uploading $group $TARGET ---${t_end}"
upload_model $group "$TARGET"
elif [[ "$TARGET" == "release" ]] || [[ "$TARGET" == "experimental" ]]; then
# Assuming release|experimental
echo "${t_grn}--- Only uploading $TARGET ---${t_end}"
upload_models "$TARGET"
else
echo "Invalid $TARGET"
display_usage
fi
else
upload_models release
upload_models experimental
fi
rsync_to_downloads_keyman_com "$CI_CACHE/upload/" models/ 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 model for upload
##
function upload_model {
local group=$1
local model=$2
local base_model=$(basename "$model")
local shortname=$(basename $(dirname "$model"))
local buildpath=$MODELROOT/$group/$shortname/$base_model/build
local model_info=$buildpath/$base_model.model_info
echo "${t_grn}Uploading $model${t_end}"
[ -f "$model_info" ] || die "Failed to locate $model_info"
local package_filename=`cat "$model_info" | $JQ -r '.packageFilename'`
local js_filename=`cat "$model_info" | $JQ -r '.jsFilename'`
# jq returns 'null' if the entry is missing, instead of ''
if [[ $package_filename == "null" ]]; then
die "Missing package filename for $model in .model_info"
else
[ -f "$buildpath/$package_filename" ] || die "Failed to locate $buildpath/$package_filename"
fi
if [[ $js_filename == "null" ]]; then
die "Missing javascript filename for $model in .model_info"
else
[ -f "$buildpath/$js_filename" ] || die "Failed to locate $buildpath/$js_filename"
fi
local package_version=`cat "$model_info" | $JQ -r '.version'`
local package_name=`cat "$model_info" | $JQ -r '.name'`
local package_upload_path=$base_model/$package_version/$package_filename
local model_info_upload_path=$base_model/$package_version/$base_model.model_info
local js_upload_path=$base_model/$package_version/$js_filename
local package_url=$DOWNLOADS_KEYMAN_COM_URL/models/$package_upload_path
local model_info_url=$DOWNLOADS_KEYMAN_COM_URL/models/$model_info_upload_path
local installer_url=$DOWNLOADS_KEYMAN_COM_URL/models/$installer_upload_path
local js_url=$DOWNLOADS_KEYMAN_COM_URL/models/$js_upload_path
echo "${t_grn}Package name: $package_name, version: $package_version${t_end}"
prepare_for_upload "$model_info" "$model_info_upload_path"
prepare_for_upload "$buildpath/$js_filename" "$js_upload_path"
prepare_for_upload "$buildpath/$package_filename" "$package_upload_path"
}
##
## (Tweaked clone of build_models in compile.sh)
##
function upload_models {
# $1 = path to build models
# for each model, if a build.sh file exists, call it, otherwise, run the default
# build based on the folder name and location.
# excluded folders are: shared and template
local group=$1
local excluded_folders=" shared template "
echo "Uploading models for $1"
local shortname
for shortname in "$MODELROOT/$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 model
for model in "$shortname"*/ ; do
upload_model "$group" "$model"
done
fi
fi
done
return 0
}
##
## zips all .model_info files from .cache/upload/ into .cache/data/model_info.zip
##
function zip_model_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/*/*/*.model_info)
printf "%s\n" "${files[@]}" > .cache/model_info.list
"$APP7Z" a ".cache/data/model_info.zip" @.cache/model_info.list
rm .cache/model_info.list
}
############################################################################################
run
############################################################################################
# EOF
############################################################################################