FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

ci: move bazel saucelabs execution to script to be used across all An… · javascriptStudy111/angular@4316352 · GitHub

Commit 4316352

Browse files
authored andcommitted
ci: move bazel saucelabs execution to script to be used across all Angular repos (angular#32141)
PR Close angular#32141
1 parent ee48623 commit 4316352

4 files changed

Lines changed: 218 additions & 33 deletions

File tree

‎.bazelrc‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,6 @@ build --incompatible_strict_action_env
3636
run --incompatible_strict_action_env
3737
test --incompatible_strict_action_env
3838

39-
###############################
40-
# Saucelabs support #
41-
# Turn on these settings with #
42-
# --config=saucelabs #
43-
###############################
44-
45-
# Expose SauceLabs environment to actions
46-
# These environment variables are needed by
47-
# web_test_karma to run on Saucelabs
48-
test:saucelabs --action_env=SAUCE_USERNAME
49-
test:saucelabs --action_env=SAUCE_ACCESS_KEY
50-
test:saucelabs --action_env=SAUCE_READY_FILE
51-
test:saucelabs --action_env=SAUCE_PID_FILE
52-
test:saucelabs --action_env=SAUCE_TUNNEL_IDENTIFIER
53-
test:saucelabs --define=KARMA_WEB_TEST_MODE=SL_REQUIRED
54-
5539
###############################
5640
# Release support #
5741
# Turn on these settings with #

‎.circleci/config.yml‎

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -256,23 +256,19 @@ jobs:
256256
- *init_environment
257257
- *setup_circleci_bazel_config
258258
- run:
259-
name: Preparing environment for running tests on Saucelabs.
260-
command: setSecretVar SAUCE_ACCESS_KEY $(echo $SAUCE_ACCESS_KEY | rev)
261-
- run:
262-
name: Starting Saucelabs tunnel
263-
command: ./scripts/saucelabs/start-tunnel.sh
264-
background: true
265-
# Waits for the Saucelabs tunnel to be ready. This ensures that we don't run tests
266-
# too early without Saucelabs not being ready.
267-
- run: ./scripts/saucelabs/wait-for-tunnel.sh
268-
# All web tests are contained within a single //:test_web_all target for Saucelabs
269-
# as running each set of tests as a separate target will attempt to acquire too
270-
# many browsers on Saucelabs (7 per target currently) and some tests will always
271-
# fail to acquire browsers. For example:
272-
# 14 02 2019 19:52:33.170:WARN [launcher]: chrome beta on SauceLabs have not captured in 180000 ms, killing.
273-
# //packages/forms/test:web_test_sauce TIMEOUT in 315.0s
274-
- run: yarn bazel test --config=saucelabs //:test_web_all
275-
- run: ./scripts/saucelabs/stop-tunnel.sh
259+
name: Run Bazel tests in saucelabs
260+
# All web tests are contained within a single //:test_web_all target for Saucelabs
261+
# as running each set of tests as a separate target will attempt to acquire too
262+
# many browsers on Saucelabs (7 per target currently) and some tests will always
263+
# fail to acquire browsers. For example:
264+
# 14 02 2019 19:52:33.170:WARN [launcher]: chrome beta on SauceLabs have not captured in 180000 ms, killing.
265+
# //packages/forms/test:web_test_sauce TIMEOUT in 315.0s
266+
command: |
267+
./scripts/saucelabs/run-bazel-via-tunnel.sh \
268+
--tunnel-id angular-${CIRCLE_BUILD_NUM}-${CIRCLE_NODE_INDEX} \
269+
--username $SAUCE_USERNAME \
270+
--key $(echo $SAUCE_ACCESS_KEY | rev) \
271+
yarn bazel test //:test_web_all
276272
- *notify_dev_infra_on_fail
277273

278274
test_aio:

‎.circleci/env.sh‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ else
6161
setPublicVar SAUCE_USERNAME "angular-ci";
6262
setSecretVar SAUCE_ACCESS_KEY "9b988f434ff8-fbca-8aa4-4ae3-35442987";
6363
fi
64+
# TODO(josephperrott): Remove environment variables once all saucelabs tests are via bazel method.
6465
setPublicVar SAUCE_LOG_FILE /tmp/angular/sauce-connect.log
6566
setPublicVar SAUCE_READY_FILE /tmp/angular/sauce-connect-ready-file.lock
6667
setPublicVar SAUCE_PID_FILE /tmp/angular/sauce-connect-pid-file.lock
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
#!/usr/bin/env bash
2+
3+
set -u -e -o pipefail
4+
5+
# Prints out usage information for the script.
6+
function printUsage {
7+
echo -e "\e[1mrun-bazel-via-tunnel.sh\e[0m - Runs a bazel command using a saucelabs tunnel
8+
9+
\e[1mUsage:\e[0m $0 --tunnel-id=<tunnel_id> \\
10+
--username=<saucelabs_username> --key=<saucelabs_key> <bazel command>
11+
12+
\e[1mExample:\e[0m ./run-bazel-via-tunnel.sh --tunnel-id=<tunnel_id> \\
13+
--username=<saucelabs_username> --key=<saucelabs_key> \\
14+
yarn bazel test //src:everything
15+
16+
Flags:
17+
--username: The saucelabs username
18+
--key: The saucelabs access key
19+
--tunnel-id: An identifier for the saucelabs tunnel";
20+
}
21+
22+
# Ensures a file is created, creating directories for the full path as needed.
23+
function touch-safe {
24+
for f in "$@"; do
25+
[ -d $f:h ] || mkdir -p $f:h && command touch $f
26+
done
27+
}
28+
29+
# The root directory of the git project the script is running in.
30+
readonly GIT_ROOT_DIR=$(git rev-parse --show-toplevel 2> /dev/null)
31+
# Location for the saucelabs log file.
32+
readonly SAUCE_LOG_FILE=/tmp/angular/sauce-connect.log
33+
# Location for the saucelabs ready to connect lock file.
34+
readonly SAUCE_READY_FILE=/tmp/angular/sauce-connect-ready-file.lock
35+
# Location for the saucelabs ready to connection process id lock file.
36+
readonly SAUCE_PID_FILE=/tmp/angular/sauce-connect-pid-file.lock
37+
# Amount of seconds we wait for sauceconnect to establish a tunnel instance. In order to not
38+
# acquire CircleCI instances for too long if sauceconnect failed, we need a connect timeout.
39+
readonly SAUCE_READY_FILE_TIMEOUT=120
40+
41+
# Create saucelabs log file if it doesn't already exist.
42+
touch-safe $SAUCE_LOG_FILE;
43+
44+
# Handle configuration of script from command line flags and arguments
45+
OPTIONS=$(getopt -u -l tunnel-id:,username:,key:,help --options "" -- "$@")
46+
# Exit if flag parsing fails.
47+
if [ $? != 0 ] ; then echo "Failed to parse flags, exiting" && printUsage >&2 ; exit 1 ; fi
48+
set -- $OPTIONS
49+
while true; do
50+
case "$1" in
51+
--tunnel-id)
52+
shift
53+
SAUCE_TUNNEL_IDENTIFIER=$1
54+
;;
55+
--username)
56+
shift
57+
SAUCE_USERNAME=$1
58+
;;
59+
--key)
60+
shift
61+
SAUCE_ACCESS_KEY=$1
62+
;;
63+
--help)
64+
printUsage
65+
exit 2
66+
;;
67+
--)
68+
shift
69+
USER_COMMAND=$@
70+
break
71+
;;
72+
*)
73+
shift
74+
;;
75+
esac
76+
done
77+
78+
# Check each required flag and parameter
79+
if [[ -z ${SAUCE_TUNNEL_IDENTIFIER+x} ]]; then
80+
echo "Missing required flag: --tunnel-id"
81+
badCommandSyntax=1
82+
fi
83+
if [[ -z ${SAUCE_USERNAME+x} ]]; then
84+
echo "Missing required flag: --username"
85+
badCommandSyntax=1
86+
fi
87+
if [[ -z ${SAUCE_ACCESS_KEY+x} ]]; then
88+
echo "Missing required flag: --key"
89+
badCommandSyntax=1
90+
fi
91+
if [[ "${USER_COMMAND}" == "" ]]; then
92+
echo "Missing required bazel command: Bazel command for running in saucelabs tunnel"
93+
badCommandSyntax=1
94+
elif [[ ! $USER_COMMAND =~ ^(yarn bazel) ]]; then
95+
echo "The command provided must be a bazel command run via yarn, beginning with \"yarn bazel\""
96+
badCommandSyntax=1
97+
fi
98+
99+
# If any required flag or parameter were found to be missing or incorrect, exit the script.
100+
if [[ ${badCommandSyntax+x} ]]; then
101+
echo
102+
printUsage
103+
exit 1
104+
fi
105+
106+
107+
# Command arguments that will be passed to sauce-connect.
108+
# By default we disable SSL bumping for all requests. This is because SSL bumping is
109+
# not needed for our test setup and in order to perform the SSL bumping, Saucelabs
110+
# intercepts all HTTP requests in the tunnel VM and modifies them. This can cause
111+
# flakiness as it makes all requests dependent on the SSL bumping middleware.
112+
# See: https://wiki.saucelabs.com/display/DOCS/Troubleshooting+Sauce+Connect#TroubleshootingSauceConnect-DisablingSSLBumping
113+
sauceArgs="--no-ssl-bump-domains all"
114+
sauceArgs="${sauceArgs} --logfile ${SAUCE_LOG_FILE}"
115+
sauceArgs="${sauceArgs} --readyfile ${SAUCE_READY_FILE}"
116+
sauceArgs="${sauceArgs} --pidfile ${SAUCE_PID_FILE}"
117+
sauceArgs="${sauceArgs} --tunnel-identifier ${SAUCE_TUNNEL_IDENTIFIER}"
118+
sauceArgs="${sauceArgs} -u ${SAUCE_USERNAME}"
119+
120+
#########################
121+
# Open saucelabs tunnel #
122+
#########################
123+
124+
125+
${GIT_ROOT_DIR}/node_modules/sauce-connect/bin/sc -k $SAUCE_ACCESS_KEY ${sauceArgs} &
126+
127+
128+
########################################
129+
# Wait for saucelabs tunnel to connect #
130+
########################################
131+
counter=0
132+
133+
while [[ ! -f ${SAUCE_READY_FILE} ]]; do
134+
counter=$((counter + 1))
135+
136+
# Counter needs to be multiplied by two because the while loop only sleeps a half second.
137+
# This has been made in favor of better progress logging (printing dots every half second)
138+
if [ $counter -gt $[${SAUCE_READY_FILE_TIMEOUT} * 2] ]; then
139+
echo "Timed out after ${SAUCE_READY_FILE_TIMEOUT} seconds waiting for tunnel ready file."
140+
echo "Printing logfile output:"
141+
echo ""
142+
cat ${SAUCE_LOG_FILE}
143+
exit 5
144+
fi
145+
146+
printf "."
147+
sleep 0.5
148+
done
149+
150+
#########################
151+
# Execute Bazel command #
152+
#########################
153+
154+
# Prevent immediate exit for Bazel test failures
155+
set +e
156+
157+
(
158+
cd $GIT_ROOT_DIR && \
159+
# Run bazel command with saucelabs specific environment variables passed to the action
160+
# The KARMA_WEB_TEST_MODE and SAUCE_TUNNEL_IDENTIFIER environment variables provide
161+
# envirnment variables to be read in the karma configuration file to set correct
162+
# configurations for karma saucelabs and browser configs.
163+
# Usage of these envirnment variables can be seen in this repo in
164+
# /karma-js.conf.js and /browser-providers.conf.js
165+
eval "$USER_COMMAND --define=KARMA_WEB_TEST_MODE=SL_REQUIRED \
166+
--action_env=SAUCE_USERNAME=$SAUCE_USERNAME \
167+
--action_env=SAUCE_ACCESS_KEY=$SAUCE_ACCESS_KEY \
168+
--action_env=SAUCE_READY_FILE=$SAUCE_READY_FILE \
169+
--action_env=SAUCE_PID_FILE=$SAUCE_PID_FILE \
170+
--action_env=SAUCE_TUNNEL_IDENTIFIER=$SAUCE_TUNNEL_IDENTIFIER"
171+
)
172+
BAZEL_EXIT_CODE=$?
173+
echo "Exit code for bazel command was: $BAZEL_EXIT_CODE"
174+
175+
# Reenable immediate exit for failure exit code
176+
set -e
177+
178+
##############################
179+
# Close the saucelabs tunnel #
180+
##############################
181+
182+
if [[ ! -f ${SAUCE_PID_FILE} ]]; then
183+
echo "Could not find Saucelabs tunnel PID file. Cannot stop tunnel.."
184+
exit 1
185+
fi
186+
187+
echo "Shutting down Sauce Connect tunnel"
188+
189+
# The process id for the sauce-connect instance is stored inside of the pidfile.
190+
tunnelProcessId=$(cat ${SAUCE_PID_FILE})
191+
192+
# Kill the process by using the PID that has been read from the pidfile. Note that
193+
# we cannot use killall because CircleCI base container images don't have it installed.
194+
kill ${tunnelProcessId}
195+
196+
while (ps -p ${tunnelProcessId} &> /dev/null); do
197+
printf "."
198+
sleep .5
199+
done
200+
201+
echo ""
202+
echo "Sauce Connect tunnel has been shut down"
203+
204+
exit $BAZEL_EXIT_CODE

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL