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
View File
@@ -6,6 +6,7 @@
"@actions/core": "npm:@actions/[email protected]",
"@octokit/rest": "npm:@octokit/[email protected]",
"ajv": "npm:[email protected]",
"type-fest/": "https://esm.sh/v135/[email protected]/",
"handlebars": "npm:[email protected]",
"less": "npm:[email protected]",
"usercss-meta": "npm:[email protected]"
+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">;
+1 -1
View File
@@ -1,5 +1,5 @@
/* ==UserStyle==
@name AniList Catppuccin
@name AniList/AniChart Catppuccin
@namespace github.com/catppuccin/userstyles/styles/anilist
@homepageURL https://github.com/catppuccin/userstyles/tree/main/styles/anilist
@version 2.1.1
+3 -3
View File
@@ -2,7 +2,7 @@
@name Chess.com Catppuccin
@namespace github.com/catppuccin/userstyles/styles/chess.com
@homepageURL https://github.com/catppuccin/userstyles/tree/main/styles/chess.com
@version 0.1.2
@version 0.1.3
@updateURL https://github.com/catppuccin/userstyles/raw/main/styles/chess.com/catppuccin.user.css
@supportURL https://github.com/catppuccin/userstyles/issues?q=is%3Aopen+is%3Aissue+label%3Achess.com
@description Soothing pastel theme for Chess.com
@@ -62,8 +62,8 @@
@crust: @catppuccin[@@lookup][@crust];
@accent-color: @catppuccin[@@lookup][@@accent];
#piece(@name) {
@url: url("https://media.githubusercontent.com/media/catppuccin/userstyles/main/styles/chess.com/assets/@{lookup}/@{name}.png");
#piece(@piece) {
@url: url("https://media.githubusercontent.com/media/catppuccin/userstyles/main/styles/chess.com/assets/@{lookup}/@{piece}.png");
}
@bb: #piece("b/bb") [];
+38 -38
View File
@@ -1,13 +1,13 @@
/* ==UserStyle==
@name Github Catppuccin
@namespace github.com/catppuccin/userstyles/styles/github
@homepageURL https://github.com/catppuccin/userstyles/tree/main/styles/github
@version 1.3.2
@description Soothing pastel theme for GitHub
@author Catppuccin
@updateURL https://github.com/catppuccin/userstyles/raw/main/styles/github/catppuccin.user.css
@supportURL https://github.com/catppuccin/userstyles/issues?q=is%3Aopen+is%3Aissue+label%3Agithub
@license MIT
@name GitHub Catppuccin
@namespace github.com/catppuccin/userstyles/styles/github
@homepageURL https://github.com/catppuccin/userstyles/tree/main/styles/github
@version 1.3.3
@description Soothing pastel theme for GitHub
@author Catppuccin
@updateURL https://github.com/catppuccin/userstyles/raw/main/styles/github/catppuccin.user.css
@supportURL https://github.com/catppuccin/userstyles/issues?q=is%3Aopen+is%3Aissue+label%3Agithub
@license MIT
@preprocessor less
@var select lightFlavor "Light Flavor" ["latte:Latte*", "frappe:Frappé", "macchiato:Macchiato", "mocha:Mocha"]
@@ -58,49 +58,49 @@
z-index: 9999;
}
#coloredButton(@name, @color, @flat) {
#coloredButton(@item, @color, @flat) {
& when (@flat) {
--color-btn-@{name}-text: @color;
--color-btn-@{name}-bg: @base;
--color-btn-@{name}-icon: @color;
--color-btn-@{item}-text: @color;
--color-btn-@{item}-bg: @base;
--color-btn-@{item}-icon: @color;
--color-btn-@{name}-hover-text: @base;
--color-btn-@{name}-hover-bg: @color;
--color-btn-@{name}-hover-border: @color;
--color-btn-@{item}-hover-text: @base;
--color-btn-@{item}-hover-bg: @color;
--color-btn-@{item}-hover-border: @color;
--color-btn-@{name}-selected-text: @base;
--color-btn-@{name}-selected-bg: @color;
--color-btn-@{name}-selected-border: @color;
--color-btn-@{item}-selected-text: @base;
--color-btn-@{item}-selected-bg: @color;
--color-btn-@{item}-selected-border: @color;
--color-btn-@{name}-disabled-text: fadeout(@color, 60%);
--color-btn-@{name}-disabled-bg: @mantle;
--color-btn-@{item}-disabled-text: fadeout(@color, 60%);
--color-btn-@{item}-disabled-bg: @mantle;
}
& when not (@flat) {
--color-btn-@{name}-text: @base;
--color-btn-@{name}-bg: @color;
--color-btn-@{name}-icon: @base;
--color-btn-@{item}-text: @base;
--color-btn-@{item}-bg: @color;
--color-btn-@{item}-icon: @base;
--color-btn-@{name}-hover-text: @base;
--color-btn-@{name}-hover-bg: lighten(@color, 10%);
--color-btn-@{name}-hover-border: lighten(@color, 10%);
--color-btn-@{item}-hover-text: @base;
--color-btn-@{item}-hover-bg: lighten(@color, 10%);
--color-btn-@{item}-hover-border: lighten(@color, 10%);
--color-btn-@{name}-selected-text: @base;
--color-btn-@{name}-selected-bg: lighten(@color, 10%);
--color-btn-@{name}-selected-border: lighten(@color, 10%);
--color-btn-@{item}-selected-text: @base;
--color-btn-@{item}-selected-bg: lighten(@color, 10%);
--color-btn-@{item}-selected-border: lighten(@color, 10%);
--color-btn-@{name}-disabled-text: @crust;
--color-btn-@{name}-disabled-bg: fadeout(@color, 60%);
--color-btn-@{item}-disabled-text: @crust;
--color-btn-@{item}-disabled-bg: fadeout(@color, 60%);
}
--color-btn-@{name}-hover-icon: @base;
--color-btn-@{item}-hover-icon: @base;
/* set these to transparent for the looks */
--color-btn-@{name}-border: transparent;
--color-btn-@{name}-shadow: 0 0 transparent;
--color-btn-@{name}-inset-shadow: 0 0 transparent;
--color-btn-@{name}-selected-shadow: 0 0 transparent;
--color-btn-@{name}-disabled-border: transparent;
--color-btn-@{item}-border: transparent;
--color-btn-@{item}-shadow: 0 0 transparent;
--color-btn-@{item}-inset-shadow: 0 0 transparent;
--color-btn-@{item}-selected-shadow: 0 0 transparent;
--color-btn-@{item}-disabled-border: transparent;
}
#catppuccin(@lookup, @accent) {
+1 -1
View File
@@ -1,5 +1,5 @@
/* ==UserStyle==
@name HackerNews Catppuccin
@name Hacker News Catppuccin
@namespace github.com/catppuccin/userstyles/styles/hacker-news
@homepageURL https://github.com/catppuccin/userstyles/tree/main/styles/hacker-news
@version 0.1.1
+1 -1
View File
@@ -1,5 +1,5 @@
/* ==UserStyle==
@name Hoppscotch.io Catppuccin
@name Hoppscotch Catppuccin
@namespace github.com/catppuccin/userstyles/styles/hoppscotch
@homepageURL https://github.com/catppuccin/userstyles/tree/main/styles/hoppscotch
@version 1.0.0
+1 -1
View File
@@ -1,5 +1,5 @@
/* ==UserStyle==
@name Lichess Catppuccin
@name lichess Catppuccin
@namespace github.com/catppuccin/userstyles/styles/lichess
@homepageURL https://github.com/catppuccin/userstyles/tree/main/styles/lichess
@version 0.0.1
-4
View File
@@ -1133,10 +1133,6 @@
.snoo-cls-11 {
fill: @sky;
}
.snoo-cls-11 {
fill: @sky;
}
}
}
+1 -1
View File
@@ -1,5 +1,5 @@
/* ==UserStyle==
@name WhatsApp Web Catppuccin
@name WhatsApp Web Catppuccin
@namespace github.com/catppuccin/userstyles/styles/whatsapp-web
@homepageURL https://github.com/catppuccin/userstyles/tree/main/styles/whatsapp-web
@version 0.0.4
+1 -1
View File
@@ -1,5 +1,5 @@
/* ==UserStyle==
@name Wikiwand Catppuccin
@name WikiWand Catppuccin
@namespace github.com/catppuccin/userstyles/styles/wikiwand
@homepageURL https://github.com/catppuccin/userstyles/tree/main/styles/wikiwand
@version 1.2.0