Philipp Wollermann | 94bd9e3 | 2018-04-30 15:32:28 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Philipp Wollermann | aa215e2 | 2020-02-05 16:52:54 +0100 | [diff] [blame] | 3 | set -euo pipefail |
Philipp Wollermann | 94bd9e3 | 2018-04-30 15:32:28 +0200 | [diff] [blame] | 4 | |
| 5 | BUILDKITE_API_TOKEN=$(gsutil cat "gs://bazel-encrypted-secrets/buildkite-api-token.enc" | \ |
Philipp Wollermann | e34da24 | 2019-05-08 13:21:28 +0200 | [diff] [blame] | 6 | gcloud kms decrypt --project "bazel-public" --location "global" --keyring "buildkite" --key "buildkite-api-token" --plaintext-file "-" --ciphertext-file "-") |
Philipp Wollermann | 94bd9e3 | 2018-04-30 15:32:28 +0200 | [diff] [blame] | 7 | |
| 8 | rm -rf bazelbuild |
Philipp Wollermann | ea12828 | 2019-05-08 11:56:14 +0200 | [diff] [blame] | 9 | gsutil cat "gs://bazel-git-mirror/bazelbuild-mirror.tar" | tar x |
Philipp Wollermann | aa215e2 | 2020-02-05 16:52:54 +0100 | [diff] [blame] | 10 | # mkdir bazelbuild |
Philipp Wollermann | 94bd9e3 | 2018-04-30 15:32:28 +0200 | [diff] [blame] | 11 | cd bazelbuild |
| 12 | |
Philipp Wollermann | aa215e2 | 2020-02-05 16:52:54 +0100 | [diff] [blame] | 13 | git config pack.compression 9 |
| 14 | |
Philipp Wollermann | ea12828 | 2019-05-08 11:56:14 +0200 | [diff] [blame] | 15 | function mirror() { |
| 16 | repo="$1" |
| 17 | remote_name="$(echo -n $repo | tr -C '[[:alnum:]]' '-')" |
| 18 | if [[ -d $remote_name ]]; then |
Philipp Wollermann | ef51001 | 2020-06-16 13:32:19 +0200 | [diff] [blame] | 19 | git -C "${remote_name}" fetch |
Philipp Wollermann | ea12828 | 2019-05-08 11:56:14 +0200 | [diff] [blame] | 20 | else |
Philipp Wollermann | aa215e2 | 2020-02-05 16:52:54 +0100 | [diff] [blame] | 21 | git clone --bare "${repo}" "${remote_name}" |
Philipp Wollermann | ea12828 | 2019-05-08 11:56:14 +0200 | [diff] [blame] | 22 | fi |
Philipp Wollermann | aa215e2 | 2020-02-05 16:52:54 +0100 | [diff] [blame] | 23 | git -C "${remote_name}" repack -a -d -F --threads=0 |
Philipp Wollermann | ea12828 | 2019-05-08 11:56:14 +0200 | [diff] [blame] | 24 | } |
Philipp Wollermann | 94bd9e3 | 2018-04-30 15:32:28 +0200 | [diff] [blame] | 25 | |
| 26 | for repo in $(curl -sS -H "Authorization: Bearer ${BUILDKITE_API_TOKEN}" "https://api.buildkite.com/v2/organizations/bazel/pipelines?per_page=100" \ |
| 27 | | jq '.[] | .repository' | sort -u | sed -e 's/^"//' -e 's/"$//'); do |
Philipp Wollermann | 83a9501 | 2019-05-16 11:41:55 +0200 | [diff] [blame] | 28 | mirror "$repo" & |
Philipp Wollermann | 94bd9e3 | 2018-04-30 15:32:28 +0200 | [diff] [blame] | 29 | done |
| 30 | |
Philipp Wollermann | ef51001 | 2020-06-16 13:32:19 +0200 | [diff] [blame] | 31 | wait |
| 32 | |
| 33 | for repo in $(fgrep '"git_repository": "' ../../buildkite/bazelci.py | cut -d'"' -f4 | sort -u); do |
Philipp Wollermann | 83a9501 | 2019-05-16 11:41:55 +0200 | [diff] [blame] | 34 | mirror "$repo" & |
Philipp Wollermann | ea12828 | 2019-05-08 11:56:14 +0200 | [diff] [blame] | 35 | done |
Philipp Wollermann | 94bd9e3 | 2018-04-30 15:32:28 +0200 | [diff] [blame] | 36 | |
Philipp Wollermann | 83a9501 | 2019-05-16 11:41:55 +0200 | [diff] [blame] | 37 | wait |
| 38 | |
Philipp Wollermann | dd80d5a | 2019-07-11 16:33:16 +0200 | [diff] [blame] | 39 | find . -name .DS_Store -delete |
| 40 | |
Philipp Wollermann | 94bd9e3 | 2018-04-30 15:32:28 +0200 | [diff] [blame] | 41 | cd .. |
Philipp Wollermann | 8b85809 | 2019-09-06 15:52:18 +0200 | [diff] [blame] | 42 | |
| 43 | # Verify that it works: |
Philipp Wollermann | aa215e2 | 2020-02-05 16:52:54 +0100 | [diff] [blame] | 44 | rm -rf bazel-test |
Philipp Wollermann | 8b85809 | 2019-09-06 15:52:18 +0200 | [diff] [blame] | 45 | git clone --reference bazelbuild/https---github-com-bazelbuild-bazel-git https://github.com/bazelbuild/bazel.git bazel-test |
| 46 | |
Philipp Wollermann | ea12828 | 2019-05-08 11:56:14 +0200 | [diff] [blame] | 47 | tar c bazelbuild | gsutil cp - "gs://bazel-git-mirror/bazelbuild-mirror.tar" |
| 48 | zip -q0r - bazelbuild | gsutil cp - "gs://bazel-git-mirror/bazelbuild-mirror.zip" |