Use the new "git-mirrors" feature in buildkite-agent.
diff --git a/gitbundle/gitbundle.sh b/gitbundle/gitbundle.sh
index 8d66d1e..36b5d5a 100755
--- a/gitbundle/gitbundle.sh
+++ b/gitbundle/gitbundle.sh
@@ -6,27 +6,32 @@
gcloud kms decrypt --location "global" --keyring "buildkite" --key "buildkite-api-token" --plaintext-file "-" --ciphertext-file "-")
rm -rf bazelbuild
-gsutil cat "gs://bazel-git-mirror/bazelbuild.tar" | tar x
+gsutil cat "gs://bazel-git-mirror/bazelbuild-mirror.tar" | tar x
cd bazelbuild
-git config --local gc.auto 0
-
-for remote in $(git remote); do
- git remote remove "${remote}"
-done
+function mirror() {
+ repo="$1"
+ remote_name="$(echo -n $repo | tr -C '[[:alnum:]]' '-')"
+ if [[ -d $remote_name ]]; then
+ git --git-dir "${remote_name}" remote set-url origin "${repo}"
+ git --git-dir "${remote_name}" remote update --prune
+ else
+ git clone --mirror "${repo}" "${remote_name}"
+ fi
+}
for repo in $(curl -sS -H "Authorization: Bearer ${BUILDKITE_API_TOKEN}" "https://api.buildkite.com/v2/organizations/bazel/pipelines?per_page=100" \
| jq '.[] | .repository' | sort -u | sed -e 's/^"//' -e 's/"$//'); do
- remote_name="$(echo $repo | md5sum | cut -d' ' -f1)"
- git remote add --no-tags "${remote_name}" "${repo}"
+ mirror "$repo"
done
-git fetch --all
-git gc --aggressive
+for repo in $(fgrep '"git_repository": "' ../buildkite/bazelci.py | cut -d'"' -f4 | sort -u); do
+ mirror "$repo"
+done
cd ..
-tar c bazelbuild | gsutil cp - "gs://bazel-git-mirror/bazelbuild.tar"
-zip -q0r - bazelbuild | gsutil cp - "gs://bazel-git-mirror/bazelbuild.zip"
+tar c bazelbuild | gsutil cp - "gs://bazel-git-mirror/bazelbuild-mirror.tar"
+zip -q0r - bazelbuild | gsutil cp - "gs://bazel-git-mirror/bazelbuild-mirror.zip"
# Verify that it works:
# git clone --reference bazelbuild https://github.com/bazelbuild/bazel.git