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 https://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" ]] || isGitHubActions
34 function isGitHubActions {
35 [[ "${GITHUB_ACTIONS-false}" = "true" ]]
39 function isSelfHostedGitHubActions {
40 [[ "${RUST_GHA_SELF_HOSTED-false}" = "true" ]]
44 [[ "${OSTYPE}" = "darwin"* ]]
48 [[ "${OSTYPE}" = "cygwin" ]] || [[ "${OSTYPE}" = "msys" ]]
52 [[ "${OSTYPE}" = "linux-gnu" ]]
56 if [[ $# -ne 1 ]]; then
57 echo "usage: $0 <branch-name>"
62 if isGitHubActions; then
63 [[ "${GITHUB_REF}" = "refs/heads/${name}" ]]
65 echo "isCiBranch only works inside CI!"
70 function ciBaseBranch {
71 if isGitHubActions; then
72 echo "${GITHUB_BASE_REF#refs/heads/}"
74 echo "ciBaseBranch only works inside CI!"
80 if isGitHubActions; then
83 echo "ciCommit only works inside CI!"
88 function ciCheckoutPath {
89 if 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 isGitHubActions; then
105 echo "${path}" >> "${GITHUB_PATH}"
107 echo "ciCommandAddPath only works inside CI!"
112 function ciCommandSetEnv {
113 if [[ $# -ne 2 ]]; then
114 echo "usage: $0 <name> <value>"
120 if isGitHubActions; then
121 echo "${name}=${value}" >> "${GITHUB_ENV}"
123 echo "ciCommandSetEnv only works inside CI!"
128 function releaseChannel {
129 if [[ -z "${RUST_CI_OVERRIDE_RELEASE_CHANNEL+x}" ]]; then
130 cat "${ci_dir}/channel"
132 echo $RUST_CI_OVERRIDE_RELEASE_CHANNEL