2 # shellcheck shell=bash
4 # This file is intended to be sourced with `. shared.sh` or
5 # `source shared.sh`, hence the invalid shebang and not being
6 # marked as an executable file in git.
8 export MIRRORS_BASE="https://ci-mirrors.rust-lang.org/rustc"
10 # See http://unix.stackexchange.com/questions/82598
11 # Duplicated in docker/dist-various-2/shared.sh
13 echo "Attempting with retry:" "$@"
18 if [[ $n -lt $max ]]; then
19 sleep $n # don't retry immediately
21 echo "Command failed. Attempt $n/$max:"
23 echo "The command has failed after $n attempts."
31 [[ "${CI-false}" = "true" ]] || isAzurePipelines || isGitHubActions
34 function isAzurePipelines {
35 [[ "${TF_BUILD-False}" = "True" ]]
38 function isGitHubActions {
39 [[ "${GITHUB_ACTIONS-false}" = "true" ]]
43 function isSelfHostedGitHubActions {
44 [[ "${RUST_GHA_SELF_HOSTED-false}" = "true" ]]
48 [[ "${OSTYPE}" = "darwin"* ]]
52 [[ "${OSTYPE}" = "cygwin" ]] || [[ "${OSTYPE}" = "msys" ]]
56 [[ "${OSTYPE}" = "linux-gnu" ]]
60 if [[ $# -ne 1 ]]; then
61 echo "usage: $0 <branch-name>"
66 if isAzurePipelines; then
67 [[ "${BUILD_SOURCEBRANCHNAME}" = "${name}" ]]
68 elif isGitHubActions; then
69 [[ "${GITHUB_REF}" = "refs/heads/${name}" ]]
71 echo "isCiBranch only works inside CI!"
77 if isAzurePipelines; then
78 echo "${BUILD_SOURCEVERSION}"
79 elif isGitHubActions; then
82 echo "ciCommit only works inside CI!"
87 function ciCheckoutPath {
88 if isAzurePipelines; then
89 echo "${BUILD_SOURCESDIRECTORY}"
90 elif isGitHubActions; then
91 echo "${GITHUB_WORKSPACE}"
93 echo "ciCheckoutPath only works inside CI!"
98 function ciCommandAddPath {
99 if [[ $# -ne 1 ]]; then
100 echo "usage: $0 <path>"
105 if isAzurePipelines; then
106 echo "##vso[task.prependpath]${path}"
107 elif isGitHubActions; then
108 echo "${path}" >> "${GITHUB_PATH}"
110 echo "ciCommandAddPath only works inside CI!"
115 function ciCommandSetEnv {
116 if [[ $# -ne 2 ]]; then
117 echo "usage: $0 <name> <value>"
123 if isAzurePipelines; then
124 echo "##vso[task.setvariable variable=${name}]${value}"
125 elif isGitHubActions; then
126 echo "${name}=${value}" >> "${GITHUB_ENV}"
128 echo "ciCommandSetEnv only works inside CI!"