diff --git a/.circleci/config.yml b/.circleci/config.yml index 89cd859aad..6a3fb3bea1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -269,7 +269,7 @@ jobs: - *attach_workspace - *init_environment # Deploy angular.io to production (if necessary) - - run: setPublicVar CI_STABLE_BRANCH "$(npm info @angular/core dist-tags.latest | sed -r 's/^\s*([0-9]+\.[0-9]+)\.[0-9]+.*$/\1.x/')" + - run: setPublicVar_CI_STABLE_BRANCH - run: yarn --cwd aio deploy-production test_aio_local: @@ -495,6 +495,12 @@ jobs: steps: - *attach_workspace - *init_environment + - run: setPublicVar_CI_STABLE_BRANCH + - run: + name: Check out `aio/` from the stable branch + command: | + git fetch origin $CI_STABLE_BRANCH + git checkout --force origin/$CI_STABLE_BRANCH -- aio/ - run: name: Run tests against https://angular.io/ command: ./aio/scripts/test-production.sh https://angular.io/ $CI_AIO_MIN_PWA_SCORE diff --git a/.circleci/env-helpers.inc.sh b/.circleci/env-helpers.inc.sh index ff21eb9ea0..5fa1263e11 100644 --- a/.circleci/env-helpers.inc.sh +++ b/.circleci/env-helpers.inc.sh @@ -36,3 +36,38 @@ function setSecretVar() { # Restore original shell options. eval "$originalShellOptions"; } + + +# Create a function to set an environment variable, when called. +# +# Use this function for creating setter for public environment variables that require expensive or +# time-consuming computaions and may not be needed. When needed, you can call this function to set +# the environment variable (which will be available through `$BASH_ENV` from that point onwards). +# +# Arguments: +# - ``: The name of the environment variable. The generated setter function will be +# `setPublicVar_`. +# - ``: The code to run to compute the value for the variable. Since this code should be +# executed lazily, it must be properly escaped. For example: +# ```sh +# # DO NOT do this: +# createPublicVarSetter MY_VAR "$(whoami)"; # `whoami` will be evaluated eagerly +# +# # DO this isntead: +# createPublicVarSetter MY_VAR "\$(whoami)"; # `whoami` will NOT be evaluated eagerly +# ``` +# +# Usage: `createPublicVarSetter ` +# +# Example: +# ```sh +# createPublicVarSetter MY_VAR 'echo "FOO"'; +# echo $MY_VAR; # Not defined +# +# setPublicVar_MY_VAR; +# source $BASH_ENV; +# echo $MY_VAR; # FOO +# ``` +function createPublicVarSetter() { + echo "setPublicVar_$1() { setPublicVar $1 \"$2\"; }" >> $BASH_ENV; +} diff --git a/.circleci/env.sh b/.circleci/env.sh index 2e990a05c9..4ebc6cdc8e 100755 --- a/.circleci/env.sh +++ b/.circleci/env.sh @@ -34,6 +34,13 @@ setPublicVar CI_REPO_NAME "$CIRCLE_PROJECT_REPONAME"; setPublicVar CI_REPO_OWNER "$CIRCLE_PROJECT_USERNAME"; +#################################################################################################### +# Define "lazy" PUBLIC environment variables for CircleCI. +# (I.e. functions to set an environment variable when called.) +#################################################################################################### +createPublicVarSetter CI_STABLE_BRANCH "\$(npm info @angular/core dist-tags.latest | sed -r 's/^\\s*([0-9]+\\.[0-9]+)\\.[0-9]+.*$/\\1.x/')"; + + #################################################################################################### # Define SECRET environment variables for CircleCI. ####################################################################################################