3 # This file is intended to be sourced with `. shared.sh` or
4 # `source shared.sh`, hence the invalid shebang and not being
5 # marked as an executable file in git.
7 export MIRRORS_BASE="https://ci-mirrors.rust-lang.org/rustc"
9 # See http://unix.stackexchange.com/questions/82598
10 # Duplicated in docker/dist-various-2/shared.sh
12 echo "Attempting with retry:" "$@"
17 if [[ $n -lt $max ]]; then
18 sleep $n # don't retry immediately
20 echo "Command failed. Attempt $n/$max:"
22 echo "The command has failed after $n attempts."
30 [[ "${CI-false}" = "true" ]] || isAzurePipelines || isGitHubActions
33 function isAzurePipelines {
34 [[ "${TF_BUILD-False}" = "True" ]]
37 function isGitHubActions {
38 [[ "${GITHUB_ACTIONS-false}" = "true" ]]
42 function isSelfHostedGitHubActions {
43 [[ "${RUST_GHA_SELF_HOSTED-false}" = "true" ]]
47 [[ "${OSTYPE}" = "darwin"* ]]
51 [[ "${OSTYPE}" = "cygwin" ]] || [[ "${OSTYPE}" = "msys" ]]
55 [[ "${OSTYPE}" = "linux-gnu" ]]
59 if [[ $# -ne 1 ]]; then
60 echo "usage: $0 <branch-name>"
65 if isAzurePipelines; then
66 [[ "${BUILD_SOURCEBRANCHNAME}" = "${name}" ]]
67 elif isGitHubActions; then
68 [[ "${GITHUB_REF}" = "refs/heads/${name}" ]]
70 echo "isCiBranch only works inside CI!"
76 if isAzurePipelines; then
77 echo "${BUILD_SOURCEVERSION}"
78 elif isGitHubActions; then
81 echo "ciCommit only works inside CI!"
86 function ciCheckoutPath {
87 if isAzurePipelines; then
88 echo "${BUILD_SOURCESDIRECTORY}"
89 elif isGitHubActions; then
90 echo "${GITHUB_WORKSPACE}"
92 echo "ciCheckoutPath only works inside CI!"
97 function ciCommandAddPath {
98 if [[ $# -ne 1 ]]; then
99 echo "usage: $0 <path>"
104 if isAzurePipelines; then
105 echo "##vso[task.prependpath]${path}"
106 elif isGitHubActions; then
107 echo "${path}" >> "${GITHUB_PATH}"
109 echo "ciCommandAddPath only works inside CI!"
114 function ciCommandSetEnv {
115 if [[ $# -ne 2 ]]; then
116 echo "usage: $0 <name> <value>"
122 if isAzurePipelines; then
123 echo "##vso[task.setvariable variable=${name}]${value}"
124 elif isGitHubActions; then
125 echo "${name}=${value}" >> "${GITHUB_ENV}"
127 echo "ciCommandSetEnv only works inside CI!"