ci(scripts): consistent variables & comments (#420)
This commit is contained in:
1 parent
a974422f0a
commit
6cfb96b1e4
8 files changed
+49
-48
No files matched your search
+2
-2
@@ -1,7 +1,7 @@
|
||||
import portsSchema from "catppuccin-repo/resources/ports.schema.json" assert {
|
||||
import portsSchema from "catppuccin-repo/resources/ports.schema.json" with {
|
||||
type: "json",
|
||||
};
|
||||
import userStylesSchema from "@/userstyles.schema.json" assert {
|
||||
import userStylesSchema from "@/userstyles.schema.json" with {
|
||||
type: "json",
|
||||
};
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { REPO_ROOT } from "@/deps.ts";
|
||||
import { updateFile } from "@/generate/utils.ts";
|
||||
import { UserStylesSchema } from "@/types/mod.ts";
|
||||
import { stringify } from "std/yaml/stringify.ts";
|
||||
import palette from "https://raw.githubusercontent.com/catppuccin/palette/v0.2.0/palette-porcelain.json" assert {
|
||||
import palette from "https://raw.githubusercontent.com/catppuccin/palette/v0.2.0/palette-porcelain.json" with {
|
||||
type: "json",
|
||||
};
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
@@ -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
@@ -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}`,
|
||||
};
|
||||
};
|
||||
@@ -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");
|
||||
});
|
||||
});
|
||||
@@ -13,7 +13,7 @@ const userstylesData = await getUserstylesData().catch((err) => {
|
||||
Deno.exit(1);
|
||||
});
|
||||
|
||||
// lowercase usernames of all the "current-maintainers" in the file
|
||||
// Lowercase usernames of all the "current-maintainers" in the file.
|
||||
const maintainers = [
|
||||
...new Set(
|
||||
Object.values(userstylesData.userstyles).flatMap((
|
||||
@@ -21,7 +21,7 @@ const maintainers = [
|
||||
) =>
|
||||
style.readme["current-maintainers"].map((m) => {
|
||||
const username = m.url.split("github.com/")?.pop();
|
||||
// check that they follow github.com/username pattern
|
||||
// Check that they follow github.com/username pattern.
|
||||
assert.assertExists(username);
|
||||
return username.toLowerCase();
|
||||
})
|
||||
@@ -29,7 +29,7 @@ const maintainers = [
|
||||
),
|
||||
];
|
||||
|
||||
// lowercase usernames of all maintainers in the current GH team
|
||||
// Lowercase usernames of all maintainers in the current GitHub team.
|
||||
const teamMembers = await octokit.teams
|
||||
.listMembersInOrg({
|
||||
...team,
|
||||
@@ -54,7 +54,9 @@ const syncMaintainers = async () => {
|
||||
});
|
||||
console.log(`Added ${m} to the ${team.org}/${team.team_slug} team.`);
|
||||
}
|
||||
console.log(`${toAdd.length} users added to the ${team.org}/${team.team_slug} team.`)
|
||||
console.log(
|
||||
`${toAdd.length} users added to the ${team.org}/${team.team_slug} team.`,
|
||||
);
|
||||
|
||||
for (const m of toRemove) {
|
||||
await octokit.teams.removeMembershipForUserInOrg({
|
||||
@@ -63,7 +65,9 @@ const syncMaintainers = async () => {
|
||||
});
|
||||
console.log(`Removed ${m} from the ${team.org}/${team.team_slug} team.`);
|
||||
}
|
||||
console.log(`${toRemove.length} users removed from the ${team.org}/${team.team_slug} team.`)
|
||||
console.log(
|
||||
`${toRemove.length} users removed from the ${team.org}/${team.team_slug} team.`,
|
||||
);
|
||||
};
|
||||
|
||||
await syncMaintainers();
|
||||
Reference in new issue
Block a user