devops: speedup initial browser checkout (#4352)

Instead of checking out the whole repository, we now do a shallow
clone.

We then gradually "unshallow" the clone, looking for the `BASE_REVISION`.

This should fix experimental mac-11 builder.
This commit is contained in:
Andrey Lushnikov 2020-11-05 02:04:06 -08:00 committed by GitHub
parent bba8c98c69
commit b94a7c0e60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -71,7 +71,7 @@ fi
# if there's no checkout folder - checkout one.
if ! [[ -d $CHECKOUT_PATH ]]; then
echo "-- $FRIENDLY_CHECKOUT_PATH is missing - checking out.."
git clone --single-branch --branch $BASE_BRANCH $REMOTE_URL $CHECKOUT_PATH
git clone --single-branch --depth 1 --branch $BASE_BRANCH $REMOTE_URL $CHECKOUT_PATH
else
echo "-- checking $FRIENDLY_CHECKOUT_PATH folder - OK"
fi
@ -102,11 +102,30 @@ else
git remote add $REMOTE_BROWSER_UPSTREAM $REMOTE_URL
fi
# If not, fetch from REMOTE_BROWSER_UPSTREAM and check one more time.
git fetch $REMOTE_BROWSER_UPSTREAM $BASE_BRANCH
if ! git cat-file -e $BASE_REVISION^{commit}; then
echo "ERROR: $FRIENDLY_CHECKOUT_PATH/ does not include the BASE_REVISION (@$BASE_REVISION). Wrong revision number?"
exit 1
# Check if our checkout contains BASE_REVISION.
# If not, fetch from REMOTE_BROWSER_UPSTREAM and slowly fetch more and more commits
# until we find $BASE_REVISION.
# This technique allows us start with a shallow clone.
if ! git cat-file -e $BASE_REVISION^{commit} 2>/dev/null; then
# Detach git head so that we can fetch into branch.
git checkout --detach >/dev/null 2>/dev/null
# Fetch 128 commits first, and then double the amount every iteration.
FETCH_DEPTH=128
SUCCESS="no"
while (( FETCH_DEPTH <= 8192 )); do
echo "Fetching ${FETCH_DEPTH} commits to find base revision..."
git fetch --depth "${FETCH_DEPTH}" $REMOTE_BROWSER_UPSTREAM $BASE_BRANCH
FETCH_DEPTH=$(( FETCH_DEPTH * 2 ));
if git cat-file -e $BASE_REVISION^{commit} >/dev/null; then
SUCCESS="yes"
break;
fi
done
if [[ "${SUCCESS}" == "no" ]]; then
echo "ERROR: $FRIENDLY_CHECKOUT_PATH/ does not include the BASE_REVISION (@$BASE_REVISION). Wrong revision number?"
exit 1
fi
fi
echo "-- checking $FRIENDLY_CHECKOUT_PATH repo has BASE_REVISION (@$BASE_REVISION) commit - OK"