]> git.lizzy.rs Git - rust.git/blob - src/ci/scripts/setup-environment.sh
Rollup merge of #100040 - ChrisDenton:broken-pipe, r=davidtwco
[rust.git] / src / ci / scripts / setup-environment.sh
1 #!/bin/bash
2 # This script guesses some environment variables based on the builder name and
3 # the current platform, to reduce the amount of variables defined in the CI
4 # configuration.
5
6 set -euo pipefail
7 IFS=$'\n\t'
8
9 source "$(cd "$(dirname "$0")" && pwd)/../shared.sh"
10
11 # Load extra environment variables
12 vars="${EXTRA_VARIABLES-}"
13 echo "${vars}" | jq '' >/dev/null  # Validate JSON and exit on errors
14 for key in $(echo "${vars}" | jq "keys[]" -r); do
15     # On Windows, for whatever reason, $key contains the BOM character in it,
16     # and that messes up `jq ".${key}"`. This line strips the BOM from the key.
17     #
18     # https://unix.stackexchange.com/a/381263
19     key="$(echo "${key}" | sed '1s/^\xEF\xBB\xBF//')"
20
21     echo "adding extra environment variable ${key}"
22     value="$(echo "${vars}" | jq ".${key}" -r)"
23     export "${key}"="${value}"
24     ciCommandSetEnv "${key}" "${value}"
25 done
26
27 # Builders starting with `dist-` are dist builders, but if they also end with
28 # `-alt` they are alternate dist builders.
29 if [[ "${CI_JOB_NAME}" = dist-* ]]; then
30     if [[ "${CI_JOB_NAME}" = *-alt ]]; then
31         echo "alternate dist builder detected, setting DEPLOY_ALT=1"
32         ciCommandSetEnv DEPLOY_ALT 1
33     else
34         echo "normal dist builder detected, setting DEPLOY=1"
35         ciCommandSetEnv DEPLOY 1
36     fi
37 fi
38
39 # All the Linux builds happen inside Docker.
40 if isLinux; then
41     if [[ -z "${IMAGE+x}" ]]; then
42         echo "linux builder detected, using docker to run the build"
43         ciCommandSetEnv IMAGE "${CI_JOB_NAME}"
44     else
45         echo "a custom docker image is already set"
46     fi
47 fi