Skip to content

Commit

Permalink
ci: Add postcss test script
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnAngela committed Jan 18, 2024
1 parent 28dab20 commit b072f49
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/postCommit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ jobs:
run: npx stylelint --cache --cache-strategy content --cache-location ".cache/" --formatter github --max-warnings 0 "src/**/*.css"
- name: Run v8r
run: npx v8r
- name: Run postcss test
run: node scripts/postcss/index.js
- name: Check .mailmap
if: needs.postCommit.result == 'success'
run: node scripts/emailmapChecker/index.js
Expand Down
61 changes: 61 additions & 0 deletions scripts/postcss/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { exec } from "node:child_process";
import { 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("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.startsWith("Finished")) {
const match = line.match(/Finished (.*?) in/)?.[1];
if (match) {
lastFileName = 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]);
}
}

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.");
}

0 comments on commit b072f49

Please sign in to comment.