ci(scripts): consistent variables & comments (#420)

This commit is contained in:
uncenter authored and GitHub committed 2024-01-26 22:37:57 +00:00
1 parent a974422f0a
commit 6cfb96b1e4
8 files changed
+49 -48

No files matched your search

+1 -1
View File
@@ -31,7 +31,7 @@ export const checkForMissingFiles = async () => {
}));
}
// only write summary if running in github actions
// Only write summary if running in GitHub Actions.
if (Deno.env.has("GITHUB_ACTIONS")) {
await core.summary
.addHeading("Missing files")
+2 -2
View File
@@ -4,7 +4,7 @@ import core from "@actions/core";
export type LoggerProps = core.AnnotationProperties & { content?: string };
const pretty_print = (
const prettyPrint = (
message: string,
props: LoggerProps,
severity: "error" | "warning" = "warning",
@@ -77,6 +77,6 @@ export const log = (
break;
}
} else {
pretty_print(message, props, severity);
prettyPrint(message, props, severity);
}
};
+11 -15
View File
@@ -23,19 +23,19 @@ const stylesheets = walk(join(REPO_ROOT, "styles", subDir), {
let failed = false;
for await (const entry of stylesheets) {
const repodir = dirname(entry.path);
const repo = basename(repodir);
const dir = basename(dirname(entry.path));
const file = relative(REPO_ROOT, entry.path);
const content = await Deno.readTextFile(entry.path);
// verify the usercss metadata
const { globalVars, isLess } = await verifyMetadata(entry, content, repo);
// don't attempt to compile or lint non-less files
// Verify the UserCSS metadata.
const { globalVars, isLess } = await verifyMetadata(entry, content, dir);
// Don't attempt to compile or lint non-LESS files.
if (!isLess) continue;
// try to compile the less file, report any errors
less.render(content, { lint: true, globalVars }).catch(
// Try to compile the LESS file, report any errors.
less.render(content, { lint: true, globalVars: globalVars }).catch(
(err: Less.RenderError) => {
failed = true;
log(
@@ -46,15 +46,11 @@ for await (const entry of stylesheets) {
},
);
// advanced linting with stylelint
// Lint with Stylelint.
await lint(entry, content, flags.fix).catch(() => failed = true);
}
// if any files are missing, cause the workflow to fail
if (await checkForMissingFiles() === false) {
failed = true;
}
if (await checkForMissingFiles() === false) failed = true;
if (failed) {
Deno.exit(1);
}
// Cause the workflow to fail if any issues were found.
if (failed) Deno.exit(1);
+20 -20
View File
@@ -12,16 +12,16 @@ import { getUserstylesData } from "@/utils.ts";
export const verifyMetadata = async (
entry: WalkEntry,
content: string,
repo: string,
userstyle: string,
) => {
const assert = await assertions(repo);
const assert = await assertions(userstyle);
const file = relative(REPO_ROOT, entry.path);
const { metadata, errors: parsingErrors } = usercssMeta.parse(content, {
allowErrors: true,
});
// pretty print / annotate the parsing errors
// Pretty print / annotate the parsing errors.
parsingErrors.map((e) => {
let startLine = 0;
for (const line of content.split("\n")) {
@@ -32,17 +32,17 @@ export const verifyMetadata = async (
log(e.message, { file, startLine, content });
});
Object.entries(assert).forEach(([k, v]) => {
const defacto = metadata[k];
if (defacto !== v) {
for (const [key, value] of Object.entries(assert)) {
const defacto = metadata[key];
if (defacto !== value) {
const line = content
.split("\n")
.findIndex((line) => line.includes(k)) + 1;
.findIndex((line) => line.includes(key)) + 1;
const message = sprintf(
"Metadata %s should be %s but is %s",
color.bold(k),
color.green(v),
color.bold(key),
color.green(value),
color.red(String(defacto)),
);
@@ -52,12 +52,12 @@ export const verifyMetadata = async (
content,
}, "warning");
}
});
}
// parse the usercss variables to less global variables, e.g.
// Parse the UserCSS variables to LESS global variables, e.g.
// `@var select lightFlavor "Light Flavor" ["latte:Latte*", "frappe:Frappé", "macchiato:Macchiato", "mocha:Mocha"]`
// gets parsed as
// `lightFlavor: "latte"`
// `lightFlavor: "latte"`.
const globalVars = Object.entries(metadata.vars)
.reduce((acc, [k, v]) => {
return { ...acc, [k]: v.default };
@@ -69,7 +69,7 @@ export const verifyMetadata = async (
};
};
const assertions = async (repo: string) => {
const assertions = async (userstyle: string) => {
const prefix = "https://github.com/catppuccin/userstyles";
const { userstyles } = await getUserstylesData().catch((err) => {
@@ -79,16 +79,16 @@ const assertions = async (repo: string) => {
return {
name: `${
Array.isArray(userstyles[repo].name)
? (userstyles[repo].name as string[]).join("/")
: userstyles[repo].name
Array.isArray(userstyles[userstyle].name)
? (userstyles[userstyle].name as string[]).join("/")
: userstyles[userstyle].name
} Catppuccin`,
namespace: `github.com/catppuccin/userstyles/styles/${repo}`,
namespace: `github.com/catppuccin/userstyles/styles/${userstyle}`,
author: "Catppuccin",
license: "MIT",
preprocessor: "less",
homepageURL: `${prefix}/tree/main/styles/${repo}`,
updateURL: `${prefix}/raw/main/styles/${repo}/catppuccin.user.css`,
supportURL: `${prefix}/issues?q=is%3Aopen+is%3Aissue+label%3A${repo}`,
homepageURL: `${prefix}/tree/main/styles/${userstyle}`,
updateURL: `${prefix}/raw/main/styles/${userstyle}/catppuccin.user.css`,
supportURL: `${prefix}/issues?q=is%3Aopen+is%3Aissue+label%3A${userstyle}`,
};
};
+3 -2
View File
@@ -1,5 +1,5 @@
import * as color from "std/fmt/colors.ts";
import { WalkEntry } from "std/fs/mod.ts";
import type { WalkEntry } from "std/fs/walk.ts";
import { relative } from "std/path/mod.ts";
import "npm:postcss-less";
@@ -15,7 +15,7 @@ export const lint = (entry: WalkEntry, content: string, fix: boolean) =>
.then(({ results }) => {
results.map((result) => {
result.warnings.map((warning) => {
// Some cleanup for fancier logging, dims the rule name
// Some cleanup for fancier logging - dims the rule name.
const message = warning.text?.replace(
new RegExp(`\\(?${warning.rule}\\)?`),
color.dim(`(${warning.rule})`),
@@ -30,6 +30,7 @@ export const lint = (entry: WalkEntry, content: string, fix: boolean) =>
content,
}, warning.severity);
});
if (result.warnings.length > 0) throw new Error("stylelint error");
});
});