ci(lint): validate name metadata (#402)

Co-authored-by: winston <[email protected]>
This commit is contained in:
uncenterandwinston authored and GitHub committed 2023-12-14 17:44:50 +01:00
1 parent 8da437f9f2
commit 5bb6f6db1e
14 files changed
+96 -67

No files matched your search

+1 -1
View File
@@ -28,7 +28,7 @@ for await (const entry of stylesheets) {
const content = await Deno.readTextFile(entry.path);
// verify the usercss metadata
const { globalVars, isLess } = verifyMetadata(entry, content, repo);
const { globalVars, isLess } = await verifyMetadata(entry, content, repo);
// don't attempt to compile or lint non-less files
if (!isLess) continue;
+18 -5
View File
@@ -1,18 +1,20 @@
// @deno-types="@/types/usercss-meta.d.ts";
import usercssMeta from "usercss-meta";
import { log } from "@/lint/logger.ts";
import * as color from "std/fmt/colors.ts";
import { sprintf } from "std/fmt/printf.ts";
import type { WalkEntry } from "std/fs/walk.ts";
import { relative } from "std/path/mod.ts";
import { REPO_ROOT } from "@/deps.ts";
export const verifyMetadata = (
import { REPO_ROOT } from "@/deps.ts";
import { log } from "@/lint/logger.ts";
import { getUserstylesData } from "@/utils.ts";
export const verifyMetadata = async (
entry: WalkEntry,
content: string,
repo: string,
) => {
const assert = assertions(repo);
const assert = await assertions(repo);
const file = relative(REPO_ROOT, entry.path);
const { metadata, errors: parsingErrors } = usercssMeta.parse(content, {
@@ -67,9 +69,20 @@ export const verifyMetadata = (
};
};
const assertions = (repo: string) => {
const assertions = async (repo: string) => {
const prefix = "https://github.com/catppuccin/userstyles";
const { userstyles } = await getUserstylesData().catch((err) => {
console.error(err);
Deno.exit(1);
});
return {
name: `${
Array.isArray(userstyles[repo].name)
? (userstyles[repo].name as string[]).join("/")
: userstyles[repo].name
} Catppuccin`,
namespace: `github.com/catppuccin/userstyles/styles/${repo}`,
author: "Catppuccin",
license: "MIT",
+4 -10
View File
@@ -1,23 +1,17 @@
#!/usr/bin/env -S deno run -A
import * as assert from "std/assert/mod.ts";
import * as path from "std/path/mod.ts";
import { Octokit } from "@octokit/rest";
import { REPO_ROOT, userStylesSchema } from "@/deps.ts";
import type { UserStylesSchema } from "@/types/mod.ts";
import { validateYaml } from "@/utils.ts";
import { UserstylesSchema } from "@/types/userstyles.d.ts";
import { getUserstylesData } from "@/utils.ts";
const octokit = new Octokit({ auth: Deno.env.get("GITHUB_TOKEN") });
const team = { org: "catppuccin", team_slug: "userstyles-maintainers" };
const userstylesData = await validateYaml<UserstylesSchema>(
Deno.readTextFileSync(path.join(REPO_ROOT, "scripts/userstyles.yml")),
userStylesSchema,
);
if (userstylesData.userstyles === undefined) {
const userstylesData = await getUserstylesData().catch((err) => {
console.error(err);
Deno.exit(1);
}
});
// lowercase usernames of all the "current-maintainers" in the file
const maintainers = [
+25
View File
@@ -1,5 +1,10 @@
import Ajv, { Schema } from "ajv";
import { parse } from "std/yaml/parse.ts";
import { join } from "std/path/join.ts";
import { SetRequired } from "type-fest/source/set-required.d.ts";
import { REPO_ROOT, userStylesSchema } from "@/deps.ts";
import { UserstylesSchema } from "@/types/userstyles.d.ts";
/**
* @param content A string of YAML content
@@ -20,3 +25,23 @@ export const validateYaml = <T>(
return resolve(data);
});
};
/**
* Utility function that calls {@link validateYaml} on the userstyles.yml file.
* Fails when data.userstyles is undefined.
*/
export const getUserstylesData = (): Promise<Userstyles> => {
return new Promise((resolve, reject) => {
validateYaml<UserstylesSchema>(
Deno.readTextFileSync(join(REPO_ROOT, "scripts/userstyles.yml")),
userStylesSchema,
).then((data) => {
if (data.userstyles === undefined || data.collaborators === undefined) {
return reject("userstyles.yml is missing required fields");
}
return resolve(data as Userstyles);
});
});
};
type Userstyles = SetRequired<UserstylesSchema, "userstyles" | "collaborators">;