Thanks to visit codestin.com
Credit goes to chromium.googlesource.com

blob: 9fce68947f42962d9971163d31a120107688a17a [file] [log] [blame]
Aidan Hobson Sayers96e174f2017-03-29 09:47:431#!/bin/false
Daiki Iharace4c1242020-11-02 12:58:432# shellcheck shell=bash
Alex Crichtonc08f3822017-02-25 08:00:473
Aidan Hobson Sayers96e174f2017-03-29 09:47:434# 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.
7
Pietro Albini14da85c2019-11-04 16:40:188export MIRRORS_BASE="https://ci-mirrors.rust-lang.org/rustc"
Pietro Albinia3607722019-10-04 16:42:539
Smittybdfcb882021-06-23 20:26:4610# See https://unix.stackexchange.com/questions/82598
Tyler Mandrya1b9a592023-11-08 02:11:0711# Duplicated in docker/scripts/shared.sh
Alex Crichtonc08f3822017-02-25 08:00:4712function retry {
Aidan Hobson Sayers96e174f2017-03-29 09:47:4313 echo "Attempting with retry:" "$@"
Alex Crichtonc08f3822017-02-25 08:00:4714 local n=1
15 local max=5
Alex Crichtonc08f3822017-02-25 08:00:4716 while true; do
Alex Crichtonc08f3822017-02-25 08:00:4717 "$@" && break || {
18 if [[ $n -lt $max ]]; then
kennytm7def3f02018-05-10 12:00:2919 sleep $n # don't retry immediately
Alex Crichtonc08f3822017-02-25 08:00:4720 ((n++))
21 echo "Command failed. Attempt $n/$max:"
22 else
23 echo "The command has failed after $n attempts."
kennytm7def3f02018-05-10 12:00:2924 return 1
Alex Crichtonc08f3822017-02-25 08:00:4725 fi
26 }
27 done
28}
kennytme6e5dc02017-05-17 16:33:2029
John Erickson699376ad2019-05-06 18:15:5230function isCI {
Pietro Albini94f2f002022-06-05 10:29:2031 [[ "${CI-false}" = "true" ]] || isGitHubActions
Pietro Albini262ce312019-11-11 13:31:3232}
33
34function isGitHubActions {
35 [[ "${GITHUB_ACTIONS-false}" = "true" ]]
John Erickson699376ad2019-05-06 18:15:5236}
37
Pietro Albinicb76f822020-07-06 13:12:2738
39function isSelfHostedGitHubActions {
40 [[ "${RUST_GHA_SELF_HOSTED-false}" = "true" ]]
41}
42
Pietro Albini4bc4fae2019-10-08 10:05:4543function isMacOS {
Pietro Albini262ce312019-11-11 13:31:3244 [[ "${OSTYPE}" = "darwin"* ]]
John Erickson699376ad2019-05-06 18:15:5245}
46
Pietro Albini4bc4fae2019-10-08 10:05:4547function isWindows {
Pietro Albini262ce312019-11-11 13:31:3248 [[ "${OSTYPE}" = "cygwin" ]] || [[ "${OSTYPE}" = "msys" ]]
Pietro Albinia3607722019-10-04 16:42:5349}
50
Pietro Albini4bc4fae2019-10-08 10:05:4551function isLinux {
Pietro Albini262ce312019-11-11 13:31:3252 [[ "${OSTYPE}" = "linux-gnu" ]]
Pietro Albinia3607722019-10-04 16:42:5353}
54
Matt Harding80459c12024-02-13 04:37:3155function isKnownToBeMingwBuild {
MarcoIeni5b9a77a2024-11-29 15:04:1256 # CI_JOB_NAME must end with "mingw" and optionally `-N` to be considered a MinGW build.
57 isGitHubActions && [[ "${CI_JOB_NAME}" =~ mingw(-[0-9]+)?$ ]]
Matt Harding80459c12024-02-13 04:37:3158}
59
Pietro Albini262ce312019-11-11 13:31:3260function isCiBranch {
61 if [[ $# -ne 1 ]]; then
62 echo "usage: $0 <branch-name>"
63 exit 1
64 fi
65 name="$1"
66
Pietro Albini94f2f002022-06-05 10:29:2067 if isGitHubActions; then
Pietro Albini262ce312019-11-11 13:31:3268 [[ "${GITHUB_REF}" = "refs/heads/${name}" ]]
69 else
70 echo "isCiBranch only works inside CI!"
71 exit 1
72 fi
John Erickson699376ad2019-05-06 18:15:5273}
Pietro Albinia3607722019-10-04 16:42:5374
Pietro Albini392723e2021-05-06 16:47:3775function ciBaseBranch {
Pietro Albini94f2f002022-06-05 10:29:2076 if isGitHubActions; then
Pietro Albini392723e2021-05-06 16:47:3777 echo "${GITHUB_BASE_REF#refs/heads/}"
78 else
79 echo "ciBaseBranch only works inside CI!"
80 exit 1
81 fi
82}
83
Pietro Albini4479de42019-10-10 15:04:4484function ciCommit {
Pietro Albini94f2f002022-06-05 10:29:2085 if isGitHubActions; then
Pietro Albini262ce312019-11-11 13:31:3286 echo "${GITHUB_SHA}"
87 else
88 echo "ciCommit only works inside CI!"
89 exit 1
90 fi
91}
92
93function ciCheckoutPath {
Pietro Albini94f2f002022-06-05 10:29:2094 if isGitHubActions; then
Pietro Albini262ce312019-11-11 13:31:3295 echo "${GITHUB_WORKSPACE}"
96 else
97 echo "ciCheckoutPath only works inside CI!"
98 exit 1
99 fi
Pietro Albini4479de42019-10-10 15:04:44100}
101
Pietro Albinia3607722019-10-04 16:42:53102function ciCommandAddPath {
103 if [[ $# -ne 1 ]]; then
104 echo "usage: $0 <path>"
105 exit 1
106 fi
107 path="$1"
108
Pietro Albini94f2f002022-06-05 10:29:20109 if isGitHubActions; then
Pietro Albinib710f9c2020-10-01 17:26:07110 echo "${path}" >> "${GITHUB_PATH}"
Pietro Albini262ce312019-11-11 13:31:32111 else
112 echo "ciCommandAddPath only works inside CI!"
113 exit 1
114 fi
Pietro Albinia3607722019-10-04 16:42:53115}
Pietro Albinic5bbde32019-10-04 16:53:52116
117function ciCommandSetEnv {
118 if [[ $# -ne 2 ]]; then
119 echo "usage: $0 <name> <value>"
120 exit 1
121 fi
122 name="$1"
123 value="$2"
124
Pietro Albini94f2f002022-06-05 10:29:20125 if isGitHubActions; then
Pietro Albinib710f9c2020-10-01 17:26:07126 echo "${name}=${value}" >> "${GITHUB_ENV}"
Pietro Albini262ce312019-11-11 13:31:32127 else
128 echo "ciCommandSetEnv only works inside CI!"
129 exit 1
130 fi
Pietro Albinic5bbde32019-10-04 16:53:52131}
Mark Rousskov61b453c2021-06-19 14:08:13132
133function releaseChannel {
134 if [[ -z "${RUST_CI_OVERRIDE_RELEASE_CHANNEL+x}" ]]; then
135 cat "${ci_dir}/channel"
136 else
137 echo $RUST_CI_OVERRIDE_RELEASE_CHANNEL
138 fi
139}
onur-ozkan4454fa92024-10-12 04:41:39140
141# Parse values from src/stage0 file by key
142function parse_stage0_file_by_key {
143 local key="$1"
144 local file="$ci_dir/../stage0"
145 local value=$(awk -F= '{a[$1]=$2} END {print(a["'$key'"])}' $file)
146 if [ -z "$value" ]; then
147 echo "ERROR: Key '$key' not found in '$file'."
148 exit 1
149 fi
150 echo "$value"
151}