forked from notofonts/noto-source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_travis
executable file
·235 lines (205 loc) · 7.74 KB
/
build_travis
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
#!/bin/bash
#
# Copyright 2016 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
source util.sh
function main() {
branch="${TRAVIS_BRANCH}"
event="${TRAVIS_EVENT_TYPE}"
commit_range="${TRAVIS_COMMIT_RANGE}"
staging_branch='staging'
# do nothing unless pushing to staging or main
if [[ ( "${branch}" != 'main' && "${branch}" != "${staging_branch}" ) ||
"${event}" != 'push' ]]; then
exit 0
fi
outdir='instance_ttf'
cached_outdir='output'
change_hash="$(get_hash)"
cmp_dir="${change_hash}/comparisons"
cmp_report="${cmp_dir}/report.txt"
cache_branch='gh-pages'
tmp_branch="${staging_branch}-${change_hash}"
# configure git for bot account
git config 'user.name' 'noto-buildbot'
git config 'user.email' 'noto-buildbot@google.com'
git_url='github.com/googlei18n/noto-source'
credentials="noto-buildbot:${noto_buildbot_token}"
# always reset staging on push to main
if [[ "${branch}" == 'main' ]]; then
git branch "${staging_branch}" origin/main
git push --force "https://${credentials}@${git_url}.git"\
"${staging_branch}" >/dev/null 2>&1
# do nothing if resetting staging
elif [[ "${branch}" == "${staging_branch}" ]]; then
git remote set-branches --add origin main
git fetch origin main
git checkout -b main origin/main
if [[ "$(get_hash)" == "${change_hash}" ]]; then
exit 0
else
git checkout "${staging_branch}"
fi
fi
setup_fontmake
# build the updated sources
echo "building sources changed from ${commit_range}"
git diff --name-only "${commit_range}" | while read src; do
if [[ "${src}" =~ src/[^/]+\.glyphs ]]; then
build_glyphs "${src}" 'ttf'
elif [[ "${src}" =~ src/[^/]+/[^/]+\.plist ]]; then
build_plist "${src}" 'ttf'
elif [[ "${src}" =~ src/[^/]+/[^/]+\.glyphs ]]; then
for plist_src in $(dirname "${src}")/*.plist; do
build_plist "${plist_src}" 'ttf'
done
fi
done
if [[ -e "${outdir}" ]]; then
echo 'new output:'
ls "${outdir}"
else
echo 'no sources changed'
exit 0
fi
# switch to cache branch and make sure there's a directory for cached fonts
git remote set-branches --add origin "${cache_branch}"
git fetch origin "${cache_branch}"
git checkout "${cache_branch}"
if [[ ! -d "${cached_outdir}" ]]; then
mkdir "${cached_outdir}"
fi
if [[ "${branch}" == 'main' ]]; then
# cache new output
for ttf in ${outdir}/*.ttf; do
mv "${ttf}" "${cached_outdir}"
done
git add "${cached_outdir}"
# clean up old content
old_content="$(python generate_old_content.py\
"${staging_branch}" "${credentials}")"
echo "${old_content}" | while read content; do
if [[ "${content}" =~ directory:.+ ]]; then
git rm -r "${content/directory:/}"
elif [[ "${content}" =~ branch:.+ ]]; then
git push "https://${credentials}@${git_url}.git"\
--delete "${content/branch:/}" >/dev/null 2>&1
elif [[ -n "${content}" ]]; then
echo 'Unexpected output received from generate_old_content.py:'
echo "${content}"
break
fi
done
git commit -m 'Update cached output' --amend
git push --force "https://${credentials}@${git_url}.git"\
"${cache_branch}" >/dev/null 2>&1
# nothing else to do if pushed to main
exit 0
fi
# otherwise, compare new output with old
#TODO add more tests and comparisons (fontreport, notolint, unit tests)
setup_diffing
mkdir -p "${cmp_dir}"
echo 'running notodiff rendering check...'
notodiff -t 'rendered' --render-path "${cmp_dir}" --diff-threshold 0.001\
-m '*.ttf' --before "${cached_outdir}" --after "${outdir}"\
--verbose 'INFO' >> "${cmp_report}"
echo 'running fontdiff...'
for ttf in ${outdir}/*.ttf; do
ttf_basename="$(basename "${ttf}")"
cached_ttf="${cached_outdir}/${ttf_basename}"
if [[ ! -e "${cached_ttf}" ]]; then
echo "Cached font not found for ${ttf}"
continue
fi
#TODO add comprehensive text samples to noto-source and use those here
echo "checking ${ttf} against ${cached_ttf}"
specimen="$(python generate_fontdiff_input.py\
"${ttf}" 'nototools/sample_texts')"
if [[ "${specimen}" == 'None' ]]; then
echo 'no input text found'
continue
fi
out_pdf="${ttf_basename/%.ttf/.pdf}"
./fontdiff --before "${cached_ttf}" --after "${ttf}"\
--specimen "${specimen}" --out "${out_pdf}"
exit_status="$?"
msg="fontdiff exit status for ${ttf}: ${exit_status}"
echo "${msg}"
if [[ "${exit_status}" -ne 0 ]]; then
echo "${msg}" >> "${cmp_report}"
mv "${out_pdf}" "${cmp_dir}"
fi
done
# check that some comparisons were made
if [[ ! $(ls "${cmp_dir}"/*/*.png "${cmp_dir}"/*.pdf) ]]; then
echo 'No comparisons made for these changes'
exit 1
fi
# generate comparison summary and upload
python generate_html.py "${commit_range}" "${cmp_dir}"
git add "${change_hash}"
git commit -m 'Review commit' --amend
git push --force "https://${credentials}@${git_url}.git"\
"${cache_branch}" >/dev/null 2>&1
# create temporary branch to merge into main and reset staging
git branch "${tmp_branch}" "${staging_branch}"
git branch -D "${staging_branch}"
git branch "${staging_branch}" origin/main
git push "https://${credentials}@${git_url}.git"\
"${tmp_branch}" >/dev/null 2>&1
git push --force "https://${credentials}@${git_url}.git"\
"${staging_branch}" >/dev/null 2>&1
# create pull request
pull_request_json="{
\"title\": \"Review request\",
\"body\": \"Review report of changes at
https://googlei18n.github.io/noto-source/${change_hash}.\",
\"head\": \"${tmp_branch}\",
\"base\": \"main\"
}"
curl -u "${credentials}" -d "${pull_request_json//$'\n'/}"\
'https://api.github.com/repos/googlei18n/noto-source/pulls'
#TODO find and post a comment on the original PR to staging
}
function setup_fontmake() {
# install fontmake
git clone https://github.com/googlei18n/fontmake.git
cd fontmake
pip install -r requirements.txt .
cd ..
}
function setup_diffing() {
# install notodiff and dependencies
pip install Pillow
wget https://www.freedesktop.org/software/harfbuzz/release/harfbuzz-1.3.2.tar.bz2
tar xjf harfbuzz-1.3.2.tar.bz2
cd harfbuzz-1.3.2
./configure
make
PATH="${PATH}:$(pwd)/util"
cd ..
git clone https://github.com/googlei18n/nototools.git
cd nototools
pip install .
cd ..
# install fontdiff
wget https://github.com/googlei18n/fontdiff/releases/download/v0.1.1/fontdiff-linux.zip
unzip fontdiff-linux.zip
mv fontdiff-linux/fontdiff .
}
function get_hash() {
echo "$(git log -1 | awk '/commit [a-z0-9]+/ { print $2 }')"
}
main "$@"