Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

devops: speedup initial browser checkout (#4352)

Andrey Lushnikovb94a7c0e604b
diff --git a/browser_patches/prepare_checkout.sh b/browser_patches/prepare_checkout.sh
index 8771d3e002..a21a59fb87 100755
--- a/browser_patches/prepare_checkout.sh
+++ b/browser_patches/prepare_checkout.sh
@@ -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"