Skip to content

Commit f2b64cb

Browse files
committed
Run prettier versions against same source
1 parent 5fc7bd5 commit f2b64cb

17 files changed

+268
-219
lines changed

.github/actions/main/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ name: "Prettier regression test"
33
description: "Prettier regression test"
44
runs:
55
using: "node24"
6-
main: "../../../build/index.js"
6+
main: "../../../src/index.ts"

.github/workflows/main.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@ jobs:
2020
git config --global user.email "[email protected]"
2121
git config --global user.name "GitHub Actions"
2222
- run: yarn
23-
- run: yarn build
24-
- name: main action
25-
uses: ./.github/actions/main
23+
- uses: ./.github/actions/main
2624
env:
2725
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2826
- name: Upload Reports
2927
uses: actions/upload-artifact@v5
3028
with:
3129
name: Full reports
32-
path: running/reports
30+
path: reports

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
!.yarn/sdks
1111
!.yarn/versions
1212
.pnp.*
13-
/build
1413
log.txt
1514
/repositories
1615
/running

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/prettier
22
/repos/**
3-
/build
43
/cspell.json
54
.yarn/**

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
"lint:prettier": "prettier . --check",
1515
"lint:tsc": "tsc --noEmit",
1616
"test": "vitest",
17-
"build": "tsc",
18-
"execute": "yarn build && node ./build/index.js",
17+
"execute": "node ./src/index.ts",
1918
"add-repository": "node scripts/add-repository.mjs",
2019
"update-repositories": "node scripts/update-repositories.mjs"
2120
},

src/constants.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import path from "path";
22

3+
const cwd = process.cwd();
4+
35
export const IS_CI = Boolean(process.env.CI);
4-
export const cwd = process.cwd();
56
export const temporaryDirectory = path.join(cwd, "./running");
67
export const repositoriesDirectory = path.join(cwd, "./repositories");
8+
export const reportsDirectory = path.join(cwd, "./reports");
79
export const MAXIMUM_GITHUB_COMMENT_LENGTH = 65536;

src/excute-command.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { runPrettier } from "./run-prettier.ts";
2+
import * as logger from "./logger.ts";
3+
import { installPrettier } from "./install-prettier.ts";
4+
import { parseCommand } from "./parse-command.ts";
5+
import { createTemporaryDirectory, writeFile } from "./utilities.ts";
6+
import { reportsDirectory } from "./constants.ts";
7+
import path from "node:path";
8+
9+
export async function executeCommand(commandString: string) {
10+
const { alternative, original, repositories } = parseCommand(commandString);
11+
const directory = await createTemporaryDirectory();
12+
13+
// Install Prettier
14+
await logger.log("Installing Prettier...");
15+
const [alternativePrettier, originalPrettier] = await Promise.all(
16+
[original, alternative].map((version) =>
17+
installPrettier(version, { cwd: directory }),
18+
),
19+
);
20+
21+
const result = await Promise.all(
22+
repositories.map(async (repository, index) => {
23+
await logger.log(
24+
`[${index + 1}/${repositories.length}] Running Prettier on '${repository.repository}' ...`,
25+
);
26+
27+
const diff = await runPrettier(repository, {
28+
cwd: directory,
29+
alternative: alternativePrettier,
30+
original: originalPrettier,
31+
});
32+
33+
await writeFile(
34+
path.join(reportsDirectory, `${repository.directoryName}.diff`),
35+
diff,
36+
);
37+
38+
return {
39+
repository,
40+
diff,
41+
};
42+
}),
43+
);
44+
45+
return {
46+
alternative,
47+
original,
48+
result,
49+
};
50+
}

src/execute/index.ts

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/execute/prepare-prettier-ignore-file.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { inspect } from "node:util";
33
import * as core from "@actions/core";
44
import { IS_CI } from "./constants.ts";
55
import * as logger from "./logger.ts";
6-
import { execute } from "./execute/index.ts";
6+
import { executeCommand } from "./excute-command.ts";
77
import { getReport } from "./report.ts";
88
import { getIssueComment } from "./get-issue-comment.ts";
99
import { uploadToArtifact } from "./artifact.ts";
@@ -40,15 +40,16 @@ async function run() {
4040
const comment = getIssueComment();
4141
commandString = comment.body as string;
4242
} else {
43-
await fs.writeFile("log.txt", "");
4443
commandString = process.argv.splice(2)[0];
4544
}
4645

4746
if (!commandString) {
4847
throw new Error("Please enter some commands.");
4948
}
5049

51-
const result = await execute(commandString);
50+
await logger.log(`Received with command '${commandString}'.`)
51+
52+
const result = await executeCommand(commandString);
5253

5354
const { title, reports } = getReport(result);
5455

0 commit comments

Comments
 (0)