Skip to content

Commit e0d3e48

Browse files
committed
devops: use node.js to gzip logs
This way we can keep streaming logs to STDOUT.
1 parent ea95a91 commit e0d3e48

File tree

3 files changed

+46
-20
lines changed

3 files changed

+46
-20
lines changed

browser_patches/checkout_build_archive_upload.sh

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
22
set -e
33
set +x
4+
set -o pipefail
45

56
if [[ ($1 == '--help') || ($1 == '-h') ]]; then
67
echo "usage: $(basename $0) [firefox-linux|firefox-win32|firefox-win64|webkit-gtk|webkit-wpe|webkit-gtk-wpe|webkit-win64|webkit-mac-10.14|webkit-mac-10.15] [-f|--force]"
@@ -116,7 +117,7 @@ trap "rm -rf ${ZIP_PATH}; rm -rf ${LOG_PATH}; cd $(pwd -P);" INT TERM EXIT
116117
cd "$(dirname "$0")"
117118
BUILD_NUMBER=$(cat ./$BROWSER_NAME/BUILD_NUMBER)
118119
BUILD_BLOB_PATH="${BROWSER_NAME}/${BUILD_NUMBER}/${BUILD_BLOB_NAME}"
119-
LOG_BLOB_PATH="${BROWSER_NAME}/${BUILD_NUMBER}/${BUILD_BLOB_NAME%.zip}.log.zip"
120+
LOG_BLOB_PATH="${BROWSER_NAME}/${BUILD_NUMBER}/${BUILD_BLOB_NAME%.zip}.log.gz"
120121

121122
# pull from upstream and check if a new build has to be uploaded.
122123
if ! [[ ($2 == '-f') || ($2 == '--force') ]]; then
@@ -132,52 +133,44 @@ else
132133
echo "Force-rebuilding the build."
133134
fi
134135

135-
FAILED_STEP=""
136136
function generate_and_upload_browser_build {
137137
# webkit-gtk-wpe is a special build doesn't need to be built.
138138
if [[ "$BUILD_FLAVOR" == "webkit-gtk-wpe" ]]; then
139139
echo "-- combining binaries together"
140140
if ! ./webkit/download_gtk_and_wpe_and_zip_together.sh $ZIP_PATH; then
141-
FAILED_STEP="./download_gtk_and_wpe_and_zip_together.sh"
142-
return 1
141+
return 10
143142
fi
144143
echo "-- uploading"
145144
if ! ./upload.sh $BUILD_BLOB_PATH $ZIP_PATH; then
146-
FAILED_STEP="./upload.sh "
147-
return 1
145+
return 11
148146
fi
149147
return 0
150148
fi
151149

152150
# Other browser flavors follow typical build flow.
153151
echo "-- preparing checkout"
154152
if ! ./prepare_checkout.sh $BROWSER_NAME; then
155-
FAILED_STEP="./prepare_checkout.sh"
156-
return 1
153+
return 20
157154
fi
158155

159156
echo "-- cleaning"
160157
if ! ./$BROWSER_NAME/clean.sh; then
161-
FAILED_STEP="./clean.sh"
162-
return 1
158+
return 21
163159
fi
164160

165161
echo "-- building"
166162
if ! ./$BROWSER_NAME/build.sh "$EXTRA_BUILD_ARGS"; then
167-
FAILED_STEP="./build.sh "
168-
return 1
163+
return 22
169164
fi
170165

171166
echo "-- archiving to $ZIP_PATH"
172167
if ! ./$BROWSER_NAME/archive.sh $ZIP_PATH "$EXTRA_ARCHIVE_ARGS"; then
173-
FAILED_STEP="./archive.sh "
174-
return 1
168+
return 23
175169
fi
176170

177171
echo "-- uploading"
178172
if ! ./upload.sh $BUILD_BLOB_PATH $ZIP_PATH; then
179-
FAILED_STEP="./upload.sh "
180-
return 1
173+
return 24
181174
fi
182175
return 0
183176
}
@@ -186,7 +179,7 @@ source ./buildbots/send_telegram_message.sh
186179
BUILD_ALIAS="$BUILD_FLAVOR r$BUILD_NUMBER"
187180
send_telegram_message "$BUILD_ALIAS -- started"
188181

189-
if generate_and_upload_browser_build 2>&1 | ./sanitize_env.js | zip > $LOG_PATH; then
182+
if generate_and_upload_browser_build 2>&1 | ./sanitize_and_compress_log.js $LOG_PATH; then
190183
# Report successful build. Note: we don't know how to get zip size on MINGW.
191184
if [[ $(uname) == MINGW* ]]; then
192185
send_telegram_message "$BUILD_ALIAS -- uploaded"
@@ -200,6 +193,24 @@ if generate_and_upload_browser_build 2>&1 | ./sanitize_env.js | zip > $LOG_PATH;
200193
send_telegram_message "<b>$BROWSER_NAME r${BUILD_NUMBER} COMPLETE! ✅</b> $LAST_COMMIT_MESSAGE"
201194
fi
202195
else
196+
RESULT_CODE="$?"
197+
if (( RESULT_CODE == 10 )); then
198+
FAILED_STEP="./download_gtk_and_wpe_and_zip_together.sh"
199+
elif (( RESULT_CODE == 11 )); then
200+
FAILED_STEP="./upload.sh"
201+
elif (( RESULT_CODE == 20 )); then
202+
FAILED_STEP="./prepare_checkout.sh"
203+
elif (( RESULT_CODE == 21 )); then
204+
FAILED_STEP="./clean.sh"
205+
elif (( RESULT_CODE == 22 )); then
206+
FAILED_STEP="./build.sh"
207+
elif (( RESULT_CODE == 23 )); then
208+
FAILED_STEP="./archive.sh"
209+
elif (( RESULT_CODE == 24 )); then
210+
FAILED_STEP="./upload.sh"
211+
else
212+
FAILED_STEP="<unknown step>"
213+
fi
203214
# Upload logs only in case of failure and report failure.
204215
./upload.sh ${LOG_BLOB_PATH} ${LOG_PATH} || true
205216
send_telegram_message "$BUILD_ALIAS -- ${FAILED_STEP} failed! ❌ <a href='https://playwright.azureedge.net/builds/${LOG_BLOB_PATH}'>see logs</a>"

browser_patches/sanitize_env.js renamed to browser_patches/sanitize_and_compress_log.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,15 @@
1616
*/
1717

1818
const fs = require('fs');
19+
const zlib = require('zlib');
1920
const readline = require('readline');
2021

22+
if (process.argv.length < 3) {
23+
console.log('ERROR: output file path has to be specified!');
24+
process.exit(1);
25+
}
26+
const OUTPUT_PATH = process.argv[2];
27+
2128
// These env variable values should be removed from logs no matter what.
2229
const BLOCKLIST_ENV_KEYS = new Set([
2330
'AZ_ACCOUNT_NAME',
@@ -58,9 +65,17 @@ const rl = readline.createInterface({
5865
crlfDelay: Infinity,
5966
});
6067

68+
const gzip = zlib.createGzip();
69+
gzip.pipe(fs.createWriteStream(OUTPUT_PATH));
70+
6171
rl.on('line', line => {
6272
for (const [key, value] of sanitizeEnv)
6373
line = line.split(value).join(`<${key}>`);
6474
console.log(line);
75+
gzip.write(line + '\n');
76+
});
77+
78+
rl.on('close', () => {
79+
gzip.end();
6580
});
6681

browser_patches/upload.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ if [[ ("$2" == '--check') ]]; then
4444
fi
4545

4646
if ! [[ -f $ZIP_PATH ]]; then
47-
echo "ERROR: $ZIP_PATH does not exist"
47+
echo "ERROR: ${ZIP_PATH} does not exist"
4848
exit 1
4949
fi
50-
if ! [[ $ZIP_PATH == *.zip ]]; then
51-
echo "ERROR: $ZIP_PATH is not a zip archive (must have a .zip extension)"
50+
if [[ "${ZIP_PATH}" != *.zip && "${ZIP_PATH}" != *.gz ]]; then
51+
echo "ERROR: ${ZIP_PATH} is not an archive (must have a .zip or .gz extension)"
5252
exit 1
5353
fi
5454
if [[ $(uname) == MINGW* ]]; then

0 commit comments

Comments
 (0)