diff --git a/src/ci/docker/run.sh b/src/ci/docker/run.sh index fad4b5af0953f..bfd078f5fa5d2 100755 --- a/src/ci/docker/run.sh +++ b/src/ci/docker/run.sh @@ -50,6 +50,22 @@ if [ -d "$root_dir/.git" ]; then IS_GIT_SOURCE=1 fi +if [ $IS_GIT_SOURCE -eq 1 ]; then + git_repository=$(parse_stage0_file_by_key "git_repository") + nightly_branch=$(parse_stage0_file_by_key "nightly_branch") + + # Add remote only if it doesn't exist + if ! git remote | grep -q "^${git_repository}$"; then + echo "Configuring remote upstream." + git remote add upstream "https://github.com/${git_repository}" + REMOTE_NAME="upstream" + else + REMOTE_NAME="origin" + fi + + git fetch $REMOTE_NAME $nightly_branch +fi + CACHE_DOMAIN="${CACHE_DOMAIN:-ci-caches.rust-lang.org}" if [ -f "$docker_dir/$image/Dockerfile" ]; then diff --git a/src/ci/shared.sh b/src/ci/shared.sh index 2b0a10e4d08d9..bd87fa52f2baf 100644 --- a/src/ci/shared.sh +++ b/src/ci/shared.sh @@ -136,3 +136,15 @@ function releaseChannel { echo $RUST_CI_OVERRIDE_RELEASE_CHANNEL fi } + +# Parse values from ./src/stage0 file by key +function parse_stage0_file_by_key { + local key="$1" + local file="$ci_dir/../stage0" + local value=$(awk -F= '{a[$1]=$2} END {print(a["'$key'"])}' $file) + if [ -z "$value" ]; then + echo "ERROR: Key '$key' not found in '$file'." + exit 1 + fi + echo "$value" +}