-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathindex.js
More file actions
63 lines (60 loc) · 1.99 KB
/
Copy pathindex.js
File metadata and controls
63 lines (60 loc) · 1.99 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
import { exec } from "node:child_process";
import { debug, warning, startGroup, endGroup } from "@actions/core";
import console from "../modules/console.js";
console.info("Start to run postcss...");
startGroup("postcss output:");
/**
* @type { string }
*/
const output = await new Promise((res, rej) => {
const childProcess = exec("NO_COLOR=true npx postcss src/**/*.css --base src/ -d dist/ --verbose", (err, _, stderr) => {
if (err) {
rej(err);
} else {
res(stderr);
}
});
childProcess.stdout?.pipe(process.stdout);
childProcess.stderr?.pipe(process.stderr);
});
endGroup();
/**
* @type { [string, import("@actions/core").AnnotationProperties][] }
*/
const annotations = [];
/**
* @type { string }
*/
let lastFileName;
for (const line of output.split("\n")) {
if (line.trim().startsWith("Finished")) {
const match = line.match(/Finished (.*?) in/)?.[1];
if (match) {
lastFileName = match;
debug(line, { match });
}
}
if (line.includes("⚠")) {
/**
* @type { import("@actions/core").AnnotationProperties }
*/
const annotationProperties = {
title: "PostCSS Annotation",
file: lastFileName,
startLine: +line.match(/^(\d+):(\d+)/)?.[1],
startColumn: +line.match(/^(\d+):(\d+)/)?.[2],
};
const fileLink = `https://github.com/${process.env.GITHUB_REPOSITORY}/blob/${process.env.GITHUB_SHA.slice(0, 7)}/${encodeURI(`${lastFileName}#L${annotationProperties.startLine}`)}`;
const msg = `${line.replace(/^.*?⚠\s*/, "")} @ ${fileLink}`;
annotations.push([msg, annotationProperties]);
debug(line, { msg, annotationProperties, fileLink });
}
}
if (annotations.length > 0) {
console.warn("PostCSS has some warnings:");
for (const [msg, annotationProperties] of annotations) {
warning(msg, annotationProperties);
}
} else {
console.info("PostCSS has no warnings.");
}