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!"
76 function ciBaseBranch {
77 if isAzurePipelines; then
78 echo "unsupported on Azure Pipelines"
80 elif isGitHubActions; then
81 echo "${GITHUB_BASE_REF#refs/heads/}"
83 echo "ciBaseBranch only works inside CI!"
89 if isAzurePipelines; then
90 echo "${BUILD_SOURCEVERSION}"
91 elif isGitHubActions; then
94 echo "ciCommit only works inside CI!"
99 function ciCheckoutPath {
100 if isAzurePipelines; then
101 echo "${BUILD_SOURCESDIRECTORY}"
102 elif isGitHubActions; then
103 echo "${GITHUB_WORKSPACE}"
105 echo "ciCheckoutPath only works inside CI!"
110 function ciCommandAddPath {
111 if [[ $# -ne 1 ]]; then
112 echo "usage: $0 <path>"
117 if isAzurePipelines; then
118 echo "##vso[task.prependpath]${path}"
119 elif isGitHubActions; then
120 echo "${path}" >> "${GITHUB_PATH}"
122 echo "ciCommandAddPath only works inside CI!"
127 function ciCommandSetEnv {
128 if [[ $# -ne 2 ]]; then
129 echo "usage: $0 <name> <value>"
135 if isAzurePipelines; then
136 echo "##vso[task.setvariable variable=${name}]${value}"
137 elif isGitHubActions; then
138 echo "${name}=${value}" >> "${GITHUB_ENV}"
140 echo "ciCommandSetEnv only works inside CI!"