Skip to content

Commit dc41b95

Browse files
committed
ci: bound clone cache e2e clone step
1 parent 60b6b67 commit dc41b95

1 file changed

Lines changed: 32 additions & 2 deletions

File tree

scripts/e2e/clone-cache.sh

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ chmod 0777 "$ROOT"
1414
mkdir -p "$ROOT/e2e"
1515
chmod 0777 "$ROOT/e2e"
1616
KEEP="${KEEP:-0}"
17+
# Cold controller and project image builds can be slow on GitHub-hosted runners,
18+
# but the clone command should still fail before the workflow-level timeout.
19+
CLONE_COMMAND_TIMEOUT="${DOCKER_GIT_E2E_CLONE_CACHE_TIMEOUT:-1800s}"
20+
FAILURE_DUMPED=0
1721

1822
dg_ensure_docker "$ROOT/.e2e-bin"
1923
dg_prepare_docker_git_cli "$REPO_ROOT" "$ROOT/.e2e-bin"
@@ -28,9 +32,13 @@ MIRROR_PREFIX="/home/dev/.docker-git/.cache/git-mirrors"
2832

2933
ACTIVE_OUT_DIR=""
3034
ACTIVE_CONTAINER=""
35+
ACTIVE_CLONE_LOG=""
3136

3237
fail() {
3338
echo "e2e/clone-cache: $*" >&2
39+
if [[ "$FAILURE_DUMPED" == "0" ]]; then
40+
on_error "fail"
41+
fi
3442
exit 1
3543
}
3644

@@ -44,11 +52,19 @@ reset_shared_clone_cache_volume() {
4452

4553
on_error() {
4654
local line="$1"
55+
if [[ "$FAILURE_DUMPED" == "1" ]]; then
56+
return
57+
fi
58+
FAILURE_DUMPED=1
4759
echo "e2e/clone-cache: failed at line $line" >&2
4860
docker ps -a --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}' | head -n 80 || true
4961
if [[ -n "$ACTIVE_CONTAINER" ]]; then
5062
docker logs "$ACTIVE_CONTAINER" --tail 200 || true
5163
fi
64+
if [[ -n "$ACTIVE_CLONE_LOG" ]] && [[ -f "$ACTIVE_CLONE_LOG" ]]; then
65+
echo "--- host clone log ---" >&2
66+
cat "$ACTIVE_CLONE_LOG" >&2 || true
67+
fi
5268
if [[ -n "$ACTIVE_OUT_DIR" ]] && [[ -f "$ACTIVE_OUT_DIR/docker-compose.yml" ]]; then
5369
(cd "$ACTIVE_OUT_DIR" && docker compose ps) || true
5470
(cd "$ACTIVE_OUT_DIR" && docker compose logs --no-color --tail 200) || true
@@ -61,6 +77,7 @@ cleanup_active_case() {
6177
fi
6278
ACTIVE_OUT_DIR=""
6379
ACTIVE_CONTAINER=""
80+
ACTIVE_CLONE_LOG=""
6481
}
6582

6683
cleanup() {
@@ -75,6 +92,8 @@ cleanup() {
7592
trap 'on_error $LINENO' ERR
7693
trap cleanup EXIT
7794

95+
command -v timeout >/dev/null 2>&1 || fail "missing 'timeout' command"
96+
7897
wait_for_clone_completion() {
7998
local container="$1"
8099
local attempts=120
@@ -109,6 +128,7 @@ run_clone_case() {
109128
local volume_name="dg-e2e-cache-${case_name}-${RUN_ID}-home"
110129
local ssh_port="$(( (RANDOM % 1000) + 22000 ))"
111130
local log_path="$ROOT/clone-cache-${case_name}.log"
131+
local host_log_path="$ROOT/clone-cache-${case_name}-host.log"
112132

113133
mkdir -p "$out_dir/.orch/env"
114134
chmod 0777 "$out_dir" "$out_dir/.orch" "$out_dir/.orch/env"
@@ -120,10 +140,12 @@ EOF_ENV
120140

121141
ACTIVE_OUT_DIR="$out_dir"
122142
ACTIVE_CONTAINER="$container_name"
143+
ACTIVE_CLONE_LOG="$host_log_path"
123144

145+
set +e
124146
(
125147
cd "$REPO_ROOT"
126-
dg_run_docker_git "$REPO_ROOT" clone "$REPO_URL" \
148+
timeout "$CLONE_COMMAND_TIMEOUT" bun packages/app/dist/src/docker-git/main.js clone "$REPO_URL" \
127149
--force \
128150
--gh-skip \
129151
--no-ssh \
@@ -133,7 +155,15 @@ EOF_ENV
133155
--container-name "$container_name" \
134156
--service-name "$service_name" \
135157
--volume-name "$volume_name"
136-
)
158+
) >"$host_log_path" 2>&1
159+
local clone_exit=$?
160+
set -e
161+
if [[ "$clone_exit" -eq 124 ]]; then
162+
fail "clone command timed out after $CLONE_COMMAND_TIMEOUT for case: $case_name"
163+
fi
164+
if [[ "$clone_exit" -ne 0 ]]; then
165+
fail "clone command failed with exit code $clone_exit for case: $case_name"
166+
fi
137167

138168
wait_for_clone_completion "$container_name"
139169
docker logs "$container_name" > "$log_path" 2>&1 || true

0 commit comments

Comments
 (0)