Skip to content

Commit 7f83593

Browse files
committed
Use sparse checkout on CI to halve incremental test time
On CI runners, skip docs/ and tests/ directories when cloning FastAPI (62% of 18K files). The fastapi/ package source remains intact for all test assertions. Locally, full clone is preserved.
1 parent e582df3 commit 7f83593

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

tests/test_incremental.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,21 @@ static int incremental_setup(void) {
202202

203203
snprintf(g_repodir, sizeof(g_repodir), "%s/fastapi", g_tmpdir);
204204

205-
char cmd[512];
206-
snprintf(cmd, sizeof(cmd),
207-
"git clone --depth=1 --branch 0.99.1 --quiet "
208-
"https://github.com/fastapi/fastapi.git '%s' 2>&1",
209-
g_repodir);
205+
/* On CI, use sparse checkout to skip docs/ and tests/ (~62% of files).
206+
* Cuts indexing time roughly in half on slow shared runners. */
207+
char cmd[1024];
208+
if (getenv("CI")) {
209+
snprintf(cmd, sizeof(cmd),
210+
"git clone --depth=1 --branch 0.99.1 --quiet --filter=blob:none "
211+
"--sparse https://github.com/fastapi/fastapi.git '%s' 2>&1 && "
212+
"cd '%s' && git sparse-checkout set --no-cone '/*' '!/docs' '!/tests' 2>&1",
213+
g_repodir, g_repodir);
214+
} else {
215+
snprintf(cmd, sizeof(cmd),
216+
"git clone --depth=1 --branch 0.99.1 --quiet "
217+
"https://github.com/fastapi/fastapi.git '%s' 2>&1",
218+
g_repodir);
219+
}
210220
int rc = system(cmd);
211221
if (rc != 0) {
212222
printf(" clone failed (rc=%d) — network offline?\n", rc);

0 commit comments

Comments
 (0)