Archived
test: tolerate Windows line endings in Docker docs check
This commit is contained in:
@@ -48,7 +48,8 @@ describe("pi-web-docker documentation", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function readDockerCommandMatrix(dockerReadme: string): string[] {
|
function readDockerCommandMatrix(dockerReadme: string): string[] {
|
||||||
const commandMatrixSection = dockerReadme.split("### Command matrix\n")[1]?.split("\n### Installer options")[0] ?? "";
|
const normalizedReadme = normalizeLineEndings(dockerReadme);
|
||||||
|
const commandMatrixSection = normalizedReadme.split("### Command matrix\n")[1]?.split("\n### Installer options")[0] ?? "";
|
||||||
return Array.from(commandMatrixSection.matchAll(/^\| `([^`]+)` \|/gm), (match) => {
|
return Array.from(commandMatrixSection.matchAll(/^\| `([^`]+)` \|/gm), (match) => {
|
||||||
const command = match[1];
|
const command = match[1];
|
||||||
if (command === undefined) throw new Error("Docker command matrix row did not include a command");
|
if (command === undefined) throw new Error("Docker command matrix row did not include a command");
|
||||||
@@ -57,7 +58,8 @@ function readDockerCommandMatrix(dockerReadme: string): string[] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function readEntrypointCommandCases(dockerEntrypoint: string): Set<string> {
|
function readEntrypointCommandCases(dockerEntrypoint: string): Set<string> {
|
||||||
const commandCaseBlock = dockerEntrypoint.slice(dockerEntrypoint.indexOf('case "$command_name" in'));
|
const normalizedEntrypoint = normalizeLineEndings(dockerEntrypoint);
|
||||||
|
const commandCaseBlock = normalizedEntrypoint.slice(normalizedEntrypoint.indexOf('case "$command_name" in'));
|
||||||
const commandCases = new Set<string>();
|
const commandCases = new Set<string>();
|
||||||
for (const line of commandCaseBlock.split("\n")) {
|
for (const line of commandCaseBlock.split("\n")) {
|
||||||
const match = /^ {2}([a-z][a-z-]*(?:\|[a-z][a-z-]*)*)(?:\|__run-detached)?\)$/.exec(line);
|
const match = /^ {2}([a-z][a-z-]*(?:\|[a-z][a-z-]*)*)(?:\|__run-detached)?\)$/.exec(line);
|
||||||
@@ -67,6 +69,10 @@ function readEntrypointCommandCases(dockerEntrypoint: string): Set<string> {
|
|||||||
return commandCases;
|
return commandCases;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function normalizeLineEndings(content: string): string {
|
||||||
|
return content.replace(/\r\n?/g, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
async function readRepoFile(relativePath: string): Promise<string> {
|
async function readRepoFile(relativePath: string): Promise<string> {
|
||||||
return await readFile(join(repoRoot, relativePath), "utf8");
|
return await readFile(join(repoRoot, relativePath), "utf8");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user