Skip to content

Commit 581f42b

Browse files
committed
cleanup
1 parent e2c9a47 commit 581f42b

2 files changed

Lines changed: 28 additions & 13 deletions

File tree

‎tests/build.mjs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import fs from "fs";
33
import path from "path";
44
import { DefaultSuites } from "../suites/default-suites.mjs";
55
import { ExperimentalSuites } from "../suites-experimental/suites.mjs";
6-
import { getChangedFiles, logError, logWarn, runActionGroup, sh } from "./helper.mjs";
6+
import { getChangedFiles, parseGitFiles, logError, logWarn, runActionGroup, sh } from "./helper.mjs";
77
import { EXCLUDES } from "./excludes.mjs";
88

99
function findWorkloadForUrl(suiteUrl) {
@@ -110,8 +110,8 @@ async function checkGitStatus() {
110110
try {
111111
await runActionGroup("Checking for uncommitted build changes...", async () => {
112112
const status = await sh("git", "status", "--porcelain", "suites", "suites-experimental");
113-
const allDirtyFiles = status.stdoutString.split("\n").map(line => line.trim()).filter(line => line.length > 0);
114-
const dirtyFiles = allDirtyFiles.filter(line => !line.includes("package-lock.json"));
113+
const allDirtyFiles = parseGitFiles(status.stdoutString, { isPorcelain: true });
114+
const dirtyFiles = allDirtyFiles.filter((path) => !path.includes("package-lock.json"));
115115
if (dirtyFiles.length > 0) {
116116
logError(dirtyFiles.join("\n"));
117117
throw new Error("Git tree is dirty");

‎tests/helper.mjs‎

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,6 @@ import fs from "fs";
44

55
export const GITHUB_ACTIONS_OUTPUT = "GITHUB_ACTIONS_OUTPUT" in process.env || "GITHUB_EVENT_PATH" in process.env;
66

7-
export function getChangedFiles() {
8-
// "--diff-filter=ACMR" => ignore deleted files.
9-
const diffOut = execFileSync("git", ["diff", "--name-only", "--diff-filter=ACMR", "@{upstream}"], { encoding: "utf8" });
10-
const files = diffOut
11-
.split("\n")
12-
.map((f) => f.trim())
13-
.filter((f) => f.length > 0 && fs.existsSync(f));
14-
return [...new Set(files)];
15-
}
16-
177
export function logInfo(...args) {
188
const text = args.join(" ");
199
console.log(styleText("yellow", text));
@@ -119,3 +109,28 @@ export async function sh(binary, ...args) {
119109
console.log("::endgroup::");
120110
}
121111
}
112+
113+
export function getChangedFiles() {
114+
// "--diff-filter=ACMR" => ignore deleted files.
115+
const diffOut = execFileSync("git", ["diff", "--name-only", "--diff-filter=ACMR", "@{upstream}"], { encoding: "utf8" });
116+
return parseGitFiles(diffOut, { isPorcelain: false });
117+
}
118+
119+
export function parseGitFiles(output, { isPorcelain = false } = {}) {
120+
const files = new Set();
121+
for (let line of output.split("\n")) {
122+
line = line.trimEnd();
123+
if (isPorcelain) {
124+
if (line.length <= 3)
125+
continue;
126+
line = line.substring(3);
127+
} else {
128+
if (line.length === 0)
129+
continue;
130+
}
131+
if (fs.existsSync(line))
132+
files.add(line);
133+
134+
}
135+
return [...files];
136+
}

0 commit comments

Comments
 (0)