forked from keymanapp/lexical-models
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathci.sh
More file actions
executable file
·177 lines (143 loc) · 4.81 KB
/
ci.sh
File metadata and controls
executable file
·177 lines (143 loc) · 4.81 KB
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
#!/usr/bin/env bash
#
# Keyman is copyright (C) SIL Global. MIT License.
#
# Uploads models to downloads.keyman.com
#
# TODO(lowpri): convert to builder-style script
set -e
set -u
#
# 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"
CI_CACHE="$MODELROOT/.cache"
if [ ! -z "${SEVENZ_HOME+x}" ]; then
APP7Z="$SEVENZ_HOME/7z"
else
APP7Z="/c/Program Files/7-Zip/7z.exe"
fi
. "$MODELROOT/resources/util.inc.sh"
. "$MODELROOT/resources/rsync-tools.inc.sh"
function run {
if [ ! -d "$CI_CACHE" ]; then
mkdir "$CI_CACHE"
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/ false
}
##
## Main function
##
function upload_models_by_target {
upload_models release
upload_models experimental
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
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
echo "- Uploading $group/$base_shortname"
local model
for model in "$shortname"*/ ; do
upload_model "$group" "$model"
done
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
############################################################################################