Skip to content

Commit 9ff7abc

Browse files
committed
test(ci): read sparse android guard files from git
1 parent dc9c11b commit 9ff7abc

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

test/scripts/ci-workflow-guards.test.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Ci Workflow Guards tests cover ci workflow guards script behavior.
2-
import { readdirSync, readFileSync } from "node:fs";
2+
import { execFileSync } from "node:child_process";
3+
import { existsSync, readdirSync, readFileSync } from "node:fs";
34
import { describe, expect, it } from "vitest";
45
import { parse } from "yaml";
56

@@ -37,10 +38,17 @@ function readCriticalQualityWorkflow() {
3738
return readFileSync(".github/workflows/codeql-critical-quality.yml", "utf8");
3839
}
3940

40-
function readAndroidCompileSdk(path: string): number {
41-
const match = readFileSync(path, "utf8").match(/^\s*compileSdk\s*=\s*(\d+)\s*$/mu);
41+
function readTrackedText(relativePath: string): string {
42+
if (existsSync(relativePath)) {
43+
return readFileSync(relativePath, "utf8");
44+
}
45+
return execFileSync("git", ["show", `:${relativePath}`], { encoding: "utf8" });
46+
}
47+
48+
function readAndroidCompileSdk(relativePath: string): number {
49+
const match = readTrackedText(relativePath).match(/^\s*compileSdk\s*=\s*(\d+)\s*$/mu);
4250
if (!match) {
43-
throw new Error(`Missing compileSdk in ${path}`);
51+
throw new Error(`Missing compileSdk in ${relativePath}`);
4452
}
4553
return Number(match[1]);
4654
}

0 commit comments

Comments
 (0)