Skip to content

Commit 515e67e

Browse files
clydinmgechev
authored andcommitted
ci: introduce SauceLabs environment variables
1 parent 38f5eee commit 515e67e

File tree

3 files changed

+115
-3
lines changed

3 files changed

+115
-3
lines changed

.circleci/config.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ executors:
4646
- image: circleci/node:<< parameters.nodeversion >>-browsers
4747
working_directory: ~/ng
4848
environment:
49-
BASH_ENV: ~/.profile
5049
NPM_CONFIG_PREFIX: ~/.npm-global
5150
resource_class: xlarge
5251

@@ -191,6 +190,9 @@ jobs:
191190
parallelism: 4
192191
steps:
193192
- attach_workspace: *attach_options
193+
- run:
194+
name: Initialize Environment
195+
command: ./.circleci/env.sh
194196
- run:
195197
name: Execute CLI E2E Tests
196198
command: PATH=~/.npm-global/bin:$PATH node ./tests/legacy-cli/run_e2e --nb-shards=${CIRCLE_NODE_TOTAL} --shard=${CIRCLE_NODE_INDEX} <<# parameters.ivy >>--ivy<</ parameters.ivy >> <<# parameters.snapshots >>--ng-snapshots<</ parameters.snapshots >>
@@ -202,8 +204,12 @@ jobs:
202204
parallelism: 4
203205
steps:
204206
- attach_workspace: *attach_options
205-
# Ensure latest npm version to support local package repository
206-
- run: PATH=~/.npm-global/bin:$PATH npm install --global npm
207+
- run:
208+
name: Initialize Environment
209+
command: |
210+
./.circleci/env.sh
211+
# Ensure latest npm version to support local package repository
212+
PATH=~/.npm-global/bin:$PATH npm install --global npm
207213
- run: PATH=~/.npm-global/bin:$PATH node ./tests/legacy-cli/run_e2e --nb-shards=${CIRCLE_NODE_TOTAL} --shard=${CIRCLE_NODE_INDEX}
208214

209215
build:

.circleci/env-helpers.inc.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
####################################################################################################
2+
# Helpers for defining environment variables for CircleCI.
3+
#
4+
# In CircleCI, each step runs in a new shell. The way to share ENV variables across steps is to
5+
# export them from `$BASH_ENV`, which is automatically sourced at the beginning of every step (for
6+
# the default `bash` shell).
7+
#
8+
# See also https://circleci.com/docs/2.0/env-vars/#using-bash_env-to-set-environment-variables.
9+
####################################################################################################
10+
11+
# Set and print an environment variable.
12+
#
13+
# Use this function for setting environment variables that are public, i.e. it is OK for them to be
14+
# visible to anyone through the CI logs.
15+
#
16+
# Usage: `setPublicVar <name> <value>`
17+
function setPublicVar() {
18+
setSecretVar $1 "$2";
19+
echo "$1=$2";
20+
}
21+
22+
# Set (without printing) an environment variable.
23+
#
24+
# Use this function for setting environment variables that are secret, i.e. should not be visible to
25+
# everyone through the CI logs.
26+
#
27+
# Usage: `setSecretVar <name> <value>`
28+
function setSecretVar() {
29+
# WARNING: Secrets (e.g. passwords, access tokens) should NOT be printed.
30+
# (Keep original shell options to restore at the end.)
31+
local -r originalShellOptions=$(set +o);
32+
set +x -eu -o pipefail;
33+
34+
echo "export $1=\"${2:-}\";" >> $BASH_ENV;
35+
36+
# Restore original shell options.
37+
eval "$originalShellOptions";
38+
}
39+
40+
41+
# Create a function to set an environment variable, when called.
42+
#
43+
# Use this function for creating setter for public environment variables that require expensive or
44+
# time-consuming computaions and may not be needed. When needed, you can call this function to set
45+
# the environment variable (which will be available through `$BASH_ENV` from that point onwards).
46+
#
47+
# Arguments:
48+
# - `<name>`: The name of the environment variable. The generated setter function will be
49+
# `setPublicVar_<name>`.
50+
# - `<code>`: The code to run to compute the value for the variable. Since this code should be
51+
# executed lazily, it must be properly escaped. For example:
52+
# ```sh
53+
# # DO NOT do this:
54+
# createPublicVarSetter MY_VAR "$(whoami)"; # `whoami` will be evaluated eagerly
55+
#
56+
# # DO this isntead:
57+
# createPublicVarSetter MY_VAR "\$(whoami)"; # `whoami` will NOT be evaluated eagerly
58+
# ```
59+
#
60+
# Usage: `createPublicVarSetter <name> <code>`
61+
#
62+
# Example:
63+
# ```sh
64+
# createPublicVarSetter MY_VAR 'echo "FOO"';
65+
# echo $MY_VAR; # Not defined
66+
#
67+
# setPublicVar_MY_VAR;
68+
# source $BASH_ENV;
69+
# echo $MY_VAR; # FOO
70+
# ```
71+
function createPublicVarSetter() {
72+
echo "setPublicVar_$1() { setPublicVar $1 \"$2\"; }" >> $BASH_ENV;
73+
}

.circleci/env.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
3+
# Variables
4+
readonly projectDir=$(realpath "$(dirname ${BASH_SOURCE[0]})/..")
5+
readonly envHelpersPath="$projectDir/.circleci/env-helpers.inc.sh";
6+
7+
# Load helpers and make them available everywhere (through `$BASH_ENV`).
8+
source $envHelpersPath;
9+
echo "source $envHelpersPath;" >> $BASH_ENV;
10+
11+
12+
####################################################################################################
13+
# Define PUBLIC environment variables for CircleCI.
14+
####################################################################################################
15+
# See https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables for more info.
16+
####################################################################################################
17+
setPublicVar PROJECT_ROOT "$projectDir";
18+
19+
####################################################################################################
20+
# Define SauceLabs environment variables for CircleCI.
21+
####################################################################################################
22+
setPublicVar SAUCE_USERNAME "angular-ci";
23+
setSecretVar SAUCE_ACCESS_KEY "9b988f434ff8-fbca-8aa4-4ae3-35442987";
24+
setPublicVar SAUCE_LOG_FILE /tmp/angular/sauce-connect.log
25+
setPublicVar SAUCE_READY_FILE /tmp/angular/sauce-connect-ready-file.lock
26+
setPublicVar SAUCE_PID_FILE /tmp/angular/sauce-connect-pid-file.lock
27+
setPublicVar SAUCE_TUNNEL_IDENTIFIER "angular-${CIRCLE_BUILD_NUM}-${CIRCLE_NODE_INDEX}"
28+
# Amount of seconds we wait for sauceconnect to establish a tunnel instance. In order to not
29+
# acquire CircleCI instances for too long if sauceconnect failed, we need a connect timeout.
30+
setPublicVar SAUCE_READY_FILE_TIMEOUT 120
31+
32+
# Source `$BASH_ENV` to make the variables available immediately.
33+
source $BASH_ENV;

0 commit comments

Comments
 (0)