|
| 1 | +#!/bin/env bash |
| 2 | + |
1 | 3 | # Common functions used by other CI scripts.
|
2 | 4 | # "Include" this file by sourcing (not executing) it:
|
3 | 5 | # . buildspec/shared/common.sh
|
4 | 6 |
|
| 7 | +# Ignore these patterns when deciding if the build should fail. |
| 8 | +# - "waiting for browser": from `ssoAccessTokenProvider.test.ts`, unclear how to fix it. |
| 9 | +# - "Webview is disposed": only happens on vscode "minimum" (1.68.0) |
| 10 | +# - "HTTPError: Response code …": caused by github rate-limiting. |
| 11 | +_ignore_pat='Timed-out waiting for browser login flow\|HTTPError: Response code 403\|HTTPError: Response code 404' |
| 12 | +if [ "$VSCODE_TEST_VERSION" = 'minimum' ]; then |
| 13 | + _ignore_pat="$_ignore_pat"'\|Webview is disposed' |
| 14 | +fi |
| 15 | + |
5 | 16 | # Expects stdin + two args:
|
6 |
| -# 1: grep pattern |
7 |
| -# 2: message shown at end of report, if pattern was found in stdin. |
| 17 | +# 1: error code to return on failure |
| 18 | +# 2: grep pattern |
| 19 | +# 3: message shown at end of report, if pattern was found in stdin. |
8 | 20 | # Usage:
|
9 |
| -# echo foo | run_and_report '.*' 'You must fix this. See https://example.com' |
| 21 | +# echo foo | run_and_report 1 '.*' 'You must fix this. See https://example.com' |
10 | 22 | run_and_report() {
|
11 | 23 | set -o pipefail
|
12 |
| - local pat="${1}" |
13 |
| - local msg="${2}" |
| 24 | + local errcode="${1}" |
| 25 | + local pat="${2}" |
| 26 | + local msg="${3}" |
14 | 27 | local r=0
|
15 | 28 | mkfifo testout
|
16 | 29 | (cat testout &)
|
17 | 30 | # Capture messages that we may want to fail (or report) later.
|
18 | 31 | tee testout \
|
19 | 32 | | { grep > testout-err --line-buffered -E "$pat" || true; }
|
| 33 | + |
20 | 34 | echo ''
|
21 |
| - if grep "$pat" testout-err | sort; then |
22 |
| - printf '\nERROR: Found %s "%s" in test output (see above).\n%s\n\n' \ |
23 |
| - "$(grep "${pat}" testout-err | wc -l | tr -d ' ')" \ |
| 35 | + |
| 36 | + if grep -v "${_ignore_pat}" testout-err | grep "$pat" | sort; then |
| 37 | + printf '\nERROR: Test output matched this pattern %s times:\n "%s"\n%s\n\n' \ |
| 38 | + "$(grep -c "${pat}" testout-err)" \ |
24 | 39 | "$pat" \
|
25 | 40 | " ${msg}"
|
26 |
| - # TODO: fail the CI job |
27 |
| - # r=1 |
28 |
| - r=0 |
| 41 | + r=${errcode} |
| 42 | + else |
| 43 | + printf '\nOK: Not found in test output: "%s"\n' "$pat" |
29 | 44 | fi
|
| 45 | + |
30 | 46 | rm -f testout testout-err
|
31 | 47 | return "$r"
|
32 | 48 | }
|
0 commit comments