xref: /aosp_15_r20/external/grpc-grpc/bazel/update_mirror.sh (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1#!/bin/bash
2# Copyright 2020 The gRPC Authors
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# Script to upload github archives for bazel dependencies to GCS, creating a reliable mirror link.
17# Archives are copied to "grpc-bazel-mirror" GCS bucket (https://console.cloud.google.com/storage/browser/grpc-bazel-mirror?project=grpc-testing)
18# and will by downloadable with the https://storage.googleapis.com/grpc-bazel-mirror/ prefix.
19#
20# This script should be run each time bazel dependencies are updated.
21
22set -e
23
24cd $(dirname $0)/..
25
26# Create a temp directory to hold the versioned tarball,
27# and clean it up when the script exits.
28tmpdir="$(mktemp -d)"
29function cleanup {
30  rm -rf "$tmpdir"
31}
32trap cleanup EXIT
33
34function upload {
35  local file="$1"
36
37  if gsutil stat "gs://grpc-bazel-mirror/${file}" > /dev/null
38  then
39    echo "Skipping ${file}"
40  else
41    echo "Downloading https://${file}"
42    curl -L --fail --output "${tmpdir}/archive" "https://${file}"
43
44    echo "Uploading https://${file} to https://storage.googleapis.com/grpc-bazel-mirror/${file}"
45    gsutil cp "${tmpdir}/archive" "gs://grpc-bazel-mirror/${file}"
46
47    rm -rf "${tmpdir}/archive"
48  fi
49}
50
51# How to check that all mirror URLs work:
52# 1. clean $HOME/.cache/bazel
53# 2. bazel clean --expunge
54# 3. bazel sync (failed downloads will print warnings)
55
56# A specific link can be upload manually by running e.g.
57# upload "github.com/google/boringssl/archive/1c2769383f027befac5b75b6cedd25daf3bf4dcf.tar.gz"
58
59# bazel binaries used by the tools/bazel wrapper script
60upload github.com/bazelbuild/bazel/releases/download/6.5.0/bazel-6.5.0-linux-x86_64
61upload github.com/bazelbuild/bazel/releases/download/6.5.0/bazel-6.5.0-darwin-x86_64
62upload github.com/bazelbuild/bazel/releases/download/6.5.0/bazel-6.5.0-windows-x86_64.exe
63upload github.com/bazelbuild/bazel/releases/download/7.1.0/bazel-7.1.0-linux-x86_64
64upload github.com/bazelbuild/bazel/releases/download/7.1.0/bazel-7.1.0-darwin-x86_64
65upload github.com/bazelbuild/bazel/releases/download/7.1.0/bazel-7.1.0-windows-x86_64.exe
66
67# Collect the github archives to mirror from grpc_deps.bzl
68grep -o '"https://github.com/[^"]*"' bazel/grpc_deps.bzl | sed 's/^"https:\/\///' | sed 's/"$//' | while read -r line ; do
69    echo "Updating mirror for ${line}"
70    upload "${line}"
71done
72