summary refs log tree commit diff
path: root/src/ci/scripts
diff options
context:
space:
mode:
authorPietro Albini <pietro@pietroalbini.org>2019-11-18 15:34:07 +0100
committerPietro Albini <pietro@pietroalbini.org>2019-11-22 15:36:37 +0100
commitee12992da955d3ec8132b5c5c4579b3535da05e6 (patch)
tree5ddfb43a59bb75d59e20f9c752f0a334a0a442e0 /src/ci/scripts
parent262ce313d065a40561e0da9a65ec6b5d35641560 (diff)
downloadrust-ee12992da955d3ec8132b5c5c4579b3535da05e6.tar.gz
rust-ee12992da955d3ec8132b5c5c4579b3535da05e6.zip
ci: guess some environment variables based on builder name and os
Some environment variables (like DEPLOY or DEPLOY_ALT for dist builders,
or IMAGE on Linux builders) are set on a lot of builders, and whether
they should be present or not can be detected automatically based on the
builder name and the platform.

This commit simplifies the CI configuration by automatically setting
those environment variables.
Diffstat (limited to 'src/ci/scripts')
-rwxr-xr-xsrc/ci/scripts/setup-environment.sh31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/ci/scripts/setup-environment.sh b/src/ci/scripts/setup-environment.sh
new file mode 100755
index 00000000000..e126a06edab
--- /dev/null
+++ b/src/ci/scripts/setup-environment.sh
@@ -0,0 +1,31 @@
+#!/bin/bash
+# This script guesses some environment variables based on the builder name and
+# the current platform, to reduce the amount of variables defined in the CI
+# configuration.
+
+set -euo pipefail
+IFS=$'\n\t'
+
+source "$(cd "$(dirname "$0")" && pwd)/../shared.sh"
+
+# Builders starting with `dist-` are dist builders, but if they also end with
+# `-alt` they are alternate dist builders.
+if [[ "${CI_JOB_NAME}" = dist-* ]]; then
+    if [[ "${CI_JOB_NAME}" = *-alt ]]; then
+        echo "alternate dist builder detected, setting DEPLOY_ALT=1"
+        ciCommandSetEnv DEPLOY_ALT 1
+    else
+        echo "normal dist builder detected, setting DEPLOY=1"
+        ciCommandSetEnv DEPLOY 1
+    fi
+fi
+
+# All the Linux builds happen inside Docker.
+if isLinux; then
+    if [[ -z "${IMAGE+x}" ]]; then
+        echo "linux builder detected, using docker to run the build"
+        ciCommandSetEnv IMAGE "${CI_JOB_NAME}"
+    else
+        echo "a custom docker image is already set"
+    fi
+fi