• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/false
2# shellcheck shell=bash
3
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.
7
8export MIRRORS_BASE="https://ci-mirrors.rust-lang.org/rustc"
9
10# See https://unix.stackexchange.com/questions/82598
11# Duplicated in docker/dist-various-2/shared.sh
12function retry {
13  echo "Attempting with retry:" "$@"
14  local n=1
15  local max=5
16  while true; do
17    "$@" && break || {
18      if [[ $n -lt $max ]]; then
19        sleep $n  # don't retry immediately
20        ((n++))
21        echo "Command failed. Attempt $n/$max:"
22      else
23        echo "The command has failed after $n attempts."
24        return 1
25      fi
26    }
27  done
28}
29
30function isCI {
31    [[ "${CI-false}" = "true" ]] || isGitHubActions
32}
33
34function isGitHubActions {
35    [[ "${GITHUB_ACTIONS-false}" = "true" ]]
36}
37
38
39function isSelfHostedGitHubActions {
40    [[ "${RUST_GHA_SELF_HOSTED-false}" = "true" ]]
41}
42
43function isMacOS {
44    [[ "${OSTYPE}" = "darwin"* ]]
45}
46
47function isWindows {
48    [[ "${OSTYPE}" = "cygwin" ]] || [[ "${OSTYPE}" = "msys" ]]
49}
50
51function isLinux {
52    [[ "${OSTYPE}" = "linux-gnu" ]]
53}
54
55function isCiBranch {
56    if [[ $# -ne 1 ]]; then
57        echo "usage: $0 <branch-name>"
58        exit 1
59    fi
60    name="$1"
61
62    if isGitHubActions; then
63        [[ "${GITHUB_REF}" = "refs/heads/${name}" ]]
64    else
65        echo "isCiBranch only works inside CI!"
66        exit 1
67    fi
68}
69
70function ciBaseBranch {
71    if isGitHubActions; then
72        echo "${GITHUB_BASE_REF#refs/heads/}"
73    else
74        echo "ciBaseBranch only works inside CI!"
75        exit 1
76    fi
77}
78
79function ciCommit {
80    if isGitHubActions; then
81        echo "${GITHUB_SHA}"
82    else
83        echo "ciCommit only works inside CI!"
84        exit 1
85    fi
86}
87
88function ciCheckoutPath {
89    if isGitHubActions; then
90        echo "${GITHUB_WORKSPACE}"
91    else
92        echo "ciCheckoutPath only works inside CI!"
93        exit 1
94    fi
95}
96
97function ciCommandAddPath {
98    if [[ $# -ne 1 ]]; then
99        echo "usage: $0 <path>"
100        exit 1
101    fi
102    path="$1"
103
104    if isGitHubActions; then
105        echo "${path}" >> "${GITHUB_PATH}"
106    else
107        echo "ciCommandAddPath only works inside CI!"
108        exit 1
109    fi
110}
111
112function ciCommandSetEnv {
113    if [[ $# -ne 2 ]]; then
114        echo "usage: $0 <name> <value>"
115        exit 1
116    fi
117    name="$1"
118    value="$2"
119
120    if isGitHubActions; then
121        echo "${name}=${value}" >> "${GITHUB_ENV}"
122    else
123        echo "ciCommandSetEnv only works inside CI!"
124        exit 1
125    fi
126}
127
128function releaseChannel {
129    if [[ -z "${RUST_CI_OVERRIDE_RELEASE_CHANNEL+x}" ]]; then
130        cat "${ci_dir}/channel"
131    else
132        echo $RUST_CI_OVERRIDE_RELEASE_CHANNEL
133    fi
134}
135