-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathlinguist-generated.js
More file actions
104 lines (99 loc) · 3.47 KB
/
Copy pathlinguist-generated.js
File metadata and controls
104 lines (99 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { endGroup, startGroup, warning } from "@actions/core";
import fs from "node:fs";
import path from "node:path";
import console from "../modules/console.js";
import createCommit from "../modules/createCommit.js";
import yamlModule from "../modules/yamlModule.js";
console.info("Initialization done.");
const foldersForCodeQL = new Set();
const scriptsExcludedFromCodeQL = [
"generateCommitsHistory",
];
const gitattributesPath = ".gitattributes";
const oldGitattributes = await fs.promises.readFile(gitattributesPath, {
encoding: "utf-8",
});
startGroup("old .gitattributes:");
console.info(oldGitattributes);
endGroup();
const originalGitattributes = oldGitattributes.replace(/\n# From [^\n]+\n(?:[^\n]+\n)+(?=\n|$)/g, "").trim();
startGroup("original .gitattributes:");
console.info(originalGitattributes);
endGroup();
const newGitattributes = [""];
const cssFiles = ["dist/**/*.css"];
for (const [index, stringValue] of Object.entries(process.env)) {
if (!index.startsWith("linguist-generated-")) {
continue;
}
const key = index.replace("linguist-generated-", "");
const value = JSON.parse(stringValue);
if (!Array.isArray(value) || value.length === 0) {
warning(`${index} is not array or empty: ${stringValue}`);
continue;
}
console.info(`${key}:`, value);
newGitattributes.push(`# From ${key}`);
for (const srcPath of value) {
if (!scriptsExcludedFromCodeQL.includes(key)) {
foldersForCodeQL.add(path.dirname(srcPath));
}
newGitattributes.push(`${srcPath} linguist-generated=true`);
if (path.extname(srcPath) === ".css") {
cssFiles.push(srcPath);
}
}
newGitattributes.push("");
}
startGroup("new .gitattributes:");
console.info(newGitattributes);
endGroup();
const finalGitattributes = [originalGitattributes, ...newGitattributes];
startGroup("final .gitattributes:");
console.info(finalGitattributes);
endGroup();
await fs.promises.writeFile(gitattributesPath, `${finalGitattributes.join("\n").trim()}\n`, {
encoding: "utf-8",
});
await createCommit("auto: new .gitattributes generated");
const stylelintrcPath = ".stylelintrc.yaml";
startGroup("cssFiles:");
console.info(cssFiles);
endGroup();
const stylelintrc = await yamlModule.readFile(stylelintrcPath);
startGroup("old .stylelintrc:");
console.info(stylelintrc);
endGroup();
stylelintrc.ignoreFiles = cssFiles;
startGroup("new .stylelintrc:");
console.info(stylelintrc);
endGroup();
await yamlModule.writeFile(stylelintrcPath, stylelintrc);
await createCommit("auto: new .stylelintrc.yaml generated");
const codeqlConfigPath = ".github/codeql-config.yaml";
const oldCodeQLConfig = await yamlModule.readFile(codeqlConfigPath);
startGroup("old codeql-config.yaml");
console.info(oldCodeQLConfig);
endGroup();
const codeQLConfigPathsIgnore = oldCodeQLConfig["paths-ignore"];
startGroup("old `paths-ignore`:");
console.info(codeQLConfigPathsIgnore);
endGroup();
for (const folder of foldersForCodeQL) {
if (!codeQLConfigPathsIgnore.includes(folder)) {
codeQLConfigPathsIgnore.push(folder);
}
}
startGroup("new `paths-ignore`:");
console.info(codeQLConfigPathsIgnore);
endGroup();
const finalCodeQLConfig = {
...oldCodeQLConfig,
"paths-ignore": codeQLConfigPathsIgnore,
};
startGroup("final codeql-config.yaml:");
console.info(finalCodeQLConfig);
endGroup();
await yamlModule.writeFile(codeqlConfigPath, finalCodeQLConfig);
await createCommit("auto: new .github/codeql-config.yaml generated");
console.info("Done.");