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",
|
type: "json",
|
||||||
};
|
};
|
||||||
import userStylesSchema from "@/userstyles.schema.json" assert {
|
import userStylesSchema from "@/userstyles.schema.json" with {
|
||||||
type: "json",
|
type: "json",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { REPO_ROOT } from "@/deps.ts";
|
|||||||
import { updateFile } from "@/generate/utils.ts";
|
import { updateFile } from "@/generate/utils.ts";
|
||||||
import { UserStylesSchema } from "@/types/mod.ts";
|
import { UserStylesSchema } from "@/types/mod.ts";
|
||||||
import { stringify } from "std/yaml/stringify.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",
|
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")) {
|
if (Deno.env.has("GITHUB_ACTIONS")) {
|
||||||
await core.summary
|
await core.summary
|
||||||
.addHeading("Missing files")
|
.addHeading("Missing files")
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import core from "@actions/core";
|
|||||||
|
|
||||||
export type LoggerProps = core.AnnotationProperties & { content?: string };
|
export type LoggerProps = core.AnnotationProperties & { content?: string };
|
||||||
|
|
||||||
const pretty_print = (
|
const prettyPrint = (
|
||||||
message: string,
|
message: string,
|
||||||
props: LoggerProps,
|
props: LoggerProps,
|
||||||
severity: "error" | "warning" = "warning",
|
severity: "error" | "warning" = "warning",
|
||||||
@@ -77,6 +77,6 @@ export const log = (
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} 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;
|
let failed = false;
|
||||||
|
|
||||||
for await (const entry of stylesheets) {
|
for await (const entry of stylesheets) {
|
||||||
const repodir = dirname(entry.path);
|
const dir = basename(dirname(entry.path));
|
||||||
const repo = basename(repodir);
|
|
||||||
const file = relative(REPO_ROOT, entry.path);
|
const file = relative(REPO_ROOT, entry.path);
|
||||||
|
|
||||||
const content = await Deno.readTextFile(entry.path);
|
const content = await Deno.readTextFile(entry.path);
|
||||||
|
|
||||||
// verify the usercss metadata
|
// Verify the UserCSS metadata.
|
||||||
const { globalVars, isLess } = await verifyMetadata(entry, content, repo);
|
const { globalVars, isLess } = await verifyMetadata(entry, content, dir);
|
||||||
// don't attempt to compile or lint non-less files
|
|
||||||
|
// Don't attempt to compile or lint non-LESS files.
|
||||||
if (!isLess) continue;
|
if (!isLess) continue;
|
||||||
|
|
||||||
// try to compile the less file, report any errors
|
// Try to compile the LESS file, report any errors.
|
||||||
less.render(content, { lint: true, globalVars }).catch(
|
less.render(content, { lint: true, globalVars: globalVars }).catch(
|
||||||
(err: Less.RenderError) => {
|
(err: Less.RenderError) => {
|
||||||
failed = true;
|
failed = true;
|
||||||
log(
|
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);
|
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) {
|
// Cause the workflow to fail if any issues were found.
|
||||||
Deno.exit(1);
|
if (failed) Deno.exit(1);
|
||||||
}
|
|
||||||
+20
-20
@@ -12,16 +12,16 @@ import { getUserstylesData } from "@/utils.ts";
|
|||||||
export const verifyMetadata = async (
|
export const verifyMetadata = async (
|
||||||
entry: WalkEntry,
|
entry: WalkEntry,
|
||||||
content: string,
|
content: string,
|
||||||
repo: string,
|
userstyle: string,
|
||||||
) => {
|
) => {
|
||||||
const assert = await assertions(repo);
|
const assert = await assertions(userstyle);
|
||||||
const file = relative(REPO_ROOT, entry.path);
|
const file = relative(REPO_ROOT, entry.path);
|
||||||
|
|
||||||
const { metadata, errors: parsingErrors } = usercssMeta.parse(content, {
|
const { metadata, errors: parsingErrors } = usercssMeta.parse(content, {
|
||||||
allowErrors: true,
|
allowErrors: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
// pretty print / annotate the parsing errors
|
// Pretty print / annotate the parsing errors.
|
||||||
parsingErrors.map((e) => {
|
parsingErrors.map((e) => {
|
||||||
let startLine = 0;
|
let startLine = 0;
|
||||||
for (const line of content.split("\n")) {
|
for (const line of content.split("\n")) {
|
||||||
@@ -32,17 +32,17 @@ export const verifyMetadata = async (
|
|||||||
log(e.message, { file, startLine, content });
|
log(e.message, { file, startLine, content });
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.entries(assert).forEach(([k, v]) => {
|
for (const [key, value] of Object.entries(assert)) {
|
||||||
const defacto = metadata[k];
|
const defacto = metadata[key];
|
||||||
if (defacto !== v) {
|
if (defacto !== value) {
|
||||||
const line = content
|
const line = content
|
||||||
.split("\n")
|
.split("\n")
|
||||||
.findIndex((line) => line.includes(k)) + 1;
|
.findIndex((line) => line.includes(key)) + 1;
|
||||||
|
|
||||||
const message = sprintf(
|
const message = sprintf(
|
||||||
"Metadata %s should be %s but is %s",
|
"Metadata %s should be %s but is %s",
|
||||||
color.bold(k),
|
color.bold(key),
|
||||||
color.green(v),
|
color.green(value),
|
||||||
color.red(String(defacto)),
|
color.red(String(defacto)),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -52,12 +52,12 @@ export const verifyMetadata = async (
|
|||||||
content,
|
content,
|
||||||
}, "warning");
|
}, "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"]`
|
// `@var select lightFlavor "Light Flavor" ["latte:Latte*", "frappe:Frappé", "macchiato:Macchiato", "mocha:Mocha"]`
|
||||||
// gets parsed as
|
// gets parsed as
|
||||||
// `lightFlavor: "latte"`
|
// `lightFlavor: "latte"`.
|
||||||
const globalVars = Object.entries(metadata.vars)
|
const globalVars = Object.entries(metadata.vars)
|
||||||
.reduce((acc, [k, v]) => {
|
.reduce((acc, [k, v]) => {
|
||||||
return { ...acc, [k]: v.default };
|
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 prefix = "https://github.com/catppuccin/userstyles";
|
||||||
|
|
||||||
const { userstyles } = await getUserstylesData().catch((err) => {
|
const { userstyles } = await getUserstylesData().catch((err) => {
|
||||||
@@ -79,16 +79,16 @@ const assertions = async (repo: string) => {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
name: `${
|
name: `${
|
||||||
Array.isArray(userstyles[repo].name)
|
Array.isArray(userstyles[userstyle].name)
|
||||||
? (userstyles[repo].name as string[]).join("/")
|
? (userstyles[userstyle].name as string[]).join("/")
|
||||||
: userstyles[repo].name
|
: userstyles[userstyle].name
|
||||||
} Catppuccin`,
|
} Catppuccin`,
|
||||||
namespace: `github.com/catppuccin/userstyles/styles/${repo}`,
|
namespace: `github.com/catppuccin/userstyles/styles/${userstyle}`,
|
||||||
author: "Catppuccin",
|
author: "Catppuccin",
|
||||||
license: "MIT",
|
license: "MIT",
|
||||||
preprocessor: "less",
|
preprocessor: "less",
|
||||||
homepageURL: `${prefix}/tree/main/styles/${repo}`,
|
homepageURL: `${prefix}/tree/main/styles/${userstyle}`,
|
||||||
updateURL: `${prefix}/raw/main/styles/${repo}/catppuccin.user.css`,
|
updateURL: `${prefix}/raw/main/styles/${userstyle}/catppuccin.user.css`,
|
||||||
supportURL: `${prefix}/issues?q=is%3Aopen+is%3Aissue+label%3A${repo}`,
|
supportURL: `${prefix}/issues?q=is%3Aopen+is%3Aissue+label%3A${userstyle}`,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import * as color from "std/fmt/colors.ts";
|
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 { relative } from "std/path/mod.ts";
|
||||||
|
|
||||||
import "npm:postcss-less";
|
import "npm:postcss-less";
|
||||||
@@ -15,7 +15,7 @@ export const lint = (entry: WalkEntry, content: string, fix: boolean) =>
|
|||||||
.then(({ results }) => {
|
.then(({ results }) => {
|
||||||
results.map((result) => {
|
results.map((result) => {
|
||||||
result.warnings.map((warning) => {
|
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(
|
const message = warning.text?.replace(
|
||||||
new RegExp(`\\(?${warning.rule}\\)?`),
|
new RegExp(`\\(?${warning.rule}\\)?`),
|
||||||
color.dim(`(${warning.rule})`),
|
color.dim(`(${warning.rule})`),
|
||||||
@@ -30,6 +30,7 @@ export const lint = (entry: WalkEntry, content: string, fix: boolean) =>
|
|||||||
content,
|
content,
|
||||||
}, warning.severity);
|
}, warning.severity);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result.warnings.length > 0) throw new Error("stylelint error");
|
if (result.warnings.length > 0) throw new Error("stylelint error");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -13,7 +13,7 @@ const userstylesData = await getUserstylesData().catch((err) => {
|
|||||||
Deno.exit(1);
|
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 = [
|
const maintainers = [
|
||||||
...new Set(
|
...new Set(
|
||||||
Object.values(userstylesData.userstyles).flatMap((
|
Object.values(userstylesData.userstyles).flatMap((
|
||||||
@@ -21,7 +21,7 @@ const maintainers = [
|
|||||||
) =>
|
) =>
|
||||||
style.readme["current-maintainers"].map((m) => {
|
style.readme["current-maintainers"].map((m) => {
|
||||||
const username = m.url.split("github.com/")?.pop();
|
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);
|
assert.assertExists(username);
|
||||||
return username.toLowerCase();
|
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
|
const teamMembers = await octokit.teams
|
||||||
.listMembersInOrg({
|
.listMembersInOrg({
|
||||||
...team,
|
...team,
|
||||||
@@ -54,7 +54,9 @@ const syncMaintainers = async () => {
|
|||||||
});
|
});
|
||||||
console.log(`Added ${m} to the ${team.org}/${team.team_slug} team.`);
|
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) {
|
for (const m of toRemove) {
|
||||||
await octokit.teams.removeMembershipForUserInOrg({
|
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(`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();
|
await syncMaintainers();
|
||||||
Reference in new issue
Block a user