ci(lint): validate name metadata (#402)
Co-authored-by: winston <[email protected]>
This commit is contained in:
1 parent
8da437f9f2
commit
5bb6f6db1e
14 files changed
+96
-67
No files matched your search
@@ -6,6 +6,7 @@
|
|||||||
"@actions/core": "npm:@actions/[email protected]",
|
"@actions/core": "npm:@actions/[email protected]",
|
||||||
"@octokit/rest": "npm:@octokit/[email protected]",
|
"@octokit/rest": "npm:@octokit/[email protected]",
|
||||||
"ajv": "npm:[email protected]",
|
"ajv": "npm:[email protected]",
|
||||||
|
"type-fest/": "https://esm.sh/v135/[email protected]/",
|
||||||
"handlebars": "npm:[email protected]",
|
"handlebars": "npm:[email protected]",
|
||||||
"less": "npm:[email protected]",
|
"less": "npm:[email protected]",
|
||||||
"usercss-meta": "npm:[email protected]"
|
"usercss-meta": "npm:[email protected]"
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ for await (const entry of stylesheets) {
|
|||||||
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 } = verifyMetadata(entry, content, repo);
|
const { globalVars, isLess } = await verifyMetadata(entry, content, repo);
|
||||||
// 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;
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,20 @@
|
|||||||
// @deno-types="@/types/usercss-meta.d.ts";
|
// @deno-types="@/types/usercss-meta.d.ts";
|
||||||
import usercssMeta from "usercss-meta";
|
import usercssMeta from "usercss-meta";
|
||||||
import { log } from "@/lint/logger.ts";
|
|
||||||
import * as color from "std/fmt/colors.ts";
|
import * as color from "std/fmt/colors.ts";
|
||||||
import { sprintf } from "std/fmt/printf.ts";
|
import { sprintf } from "std/fmt/printf.ts";
|
||||||
import type { WalkEntry } from "std/fs/walk.ts";
|
import type { WalkEntry } from "std/fs/walk.ts";
|
||||||
import { relative } from "std/path/mod.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,
|
entry: WalkEntry,
|
||||||
content: string,
|
content: string,
|
||||||
repo: string,
|
repo: string,
|
||||||
) => {
|
) => {
|
||||||
const assert = assertions(repo);
|
const assert = await assertions(repo);
|
||||||
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, {
|
||||||
@@ -67,9 +69,20 @@ export const verifyMetadata = (
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const assertions = (repo: string) => {
|
const assertions = async (repo: string) => {
|
||||||
const prefix = "https://github.com/catppuccin/userstyles";
|
const prefix = "https://github.com/catppuccin/userstyles";
|
||||||
|
|
||||||
|
const { userstyles } = await getUserstylesData().catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
Deno.exit(1);
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
name: `${
|
||||||
|
Array.isArray(userstyles[repo].name)
|
||||||
|
? (userstyles[repo].name as string[]).join("/")
|
||||||
|
: userstyles[repo].name
|
||||||
|
} Catppuccin`,
|
||||||
namespace: `github.com/catppuccin/userstyles/styles/${repo}`,
|
namespace: `github.com/catppuccin/userstyles/styles/${repo}`,
|
||||||
author: "Catppuccin",
|
author: "Catppuccin",
|
||||||
license: "MIT",
|
license: "MIT",
|
||||||
|
|||||||
@@ -1,23 +1,17 @@
|
|||||||
#!/usr/bin/env -S deno run -A
|
#!/usr/bin/env -S deno run -A
|
||||||
import * as assert from "std/assert/mod.ts";
|
import * as assert from "std/assert/mod.ts";
|
||||||
import * as path from "std/path/mod.ts";
|
|
||||||
import { Octokit } from "@octokit/rest";
|
import { Octokit } from "@octokit/rest";
|
||||||
|
|
||||||
import { REPO_ROOT, userStylesSchema } from "@/deps.ts";
|
|
||||||
import type { UserStylesSchema } from "@/types/mod.ts";
|
import type { UserStylesSchema } from "@/types/mod.ts";
|
||||||
import { validateYaml } from "@/utils.ts";
|
import { getUserstylesData } from "@/utils.ts";
|
||||||
import { UserstylesSchema } from "@/types/userstyles.d.ts";
|
|
||||||
|
|
||||||
const octokit = new Octokit({ auth: Deno.env.get("GITHUB_TOKEN") });
|
const octokit = new Octokit({ auth: Deno.env.get("GITHUB_TOKEN") });
|
||||||
const team = { org: "catppuccin", team_slug: "userstyles-maintainers" };
|
const team = { org: "catppuccin", team_slug: "userstyles-maintainers" };
|
||||||
|
|
||||||
const userstylesData = await validateYaml<UserstylesSchema>(
|
const userstylesData = await getUserstylesData().catch((err) => {
|
||||||
Deno.readTextFileSync(path.join(REPO_ROOT, "scripts/userstyles.yml")),
|
console.error(err);
|
||||||
userStylesSchema,
|
|
||||||
);
|
|
||||||
if (userstylesData.userstyles === undefined) {
|
|
||||||
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 = [
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
import Ajv, { Schema } from "ajv";
|
import Ajv, { Schema } from "ajv";
|
||||||
import { parse } from "std/yaml/parse.ts";
|
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
|
* @param content A string of YAML content
|
||||||
@@ -20,3 +25,23 @@ export const validateYaml = <T>(
|
|||||||
return resolve(data);
|
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,5 +1,5 @@
|
|||||||
/* ==UserStyle==
|
/* ==UserStyle==
|
||||||
@name AniList Catppuccin
|
@name AniList/AniChart Catppuccin
|
||||||
@namespace github.com/catppuccin/userstyles/styles/anilist
|
@namespace github.com/catppuccin/userstyles/styles/anilist
|
||||||
@homepageURL https://github.com/catppuccin/userstyles/tree/main/styles/anilist
|
@homepageURL https://github.com/catppuccin/userstyles/tree/main/styles/anilist
|
||||||
@version 2.1.1
|
@version 2.1.1
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
@name Chess.com Catppuccin
|
@name Chess.com Catppuccin
|
||||||
@namespace github.com/catppuccin/userstyles/styles/chess.com
|
@namespace github.com/catppuccin/userstyles/styles/chess.com
|
||||||
@homepageURL https://github.com/catppuccin/userstyles/tree/main/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
|
@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
|
@supportURL https://github.com/catppuccin/userstyles/issues?q=is%3Aopen+is%3Aissue+label%3Achess.com
|
||||||
@description Soothing pastel theme for Chess.com
|
@description Soothing pastel theme for Chess.com
|
||||||
@@ -62,8 +62,8 @@
|
|||||||
@crust: @catppuccin[@@lookup][@crust];
|
@crust: @catppuccin[@@lookup][@crust];
|
||||||
@accent-color: @catppuccin[@@lookup][@@accent];
|
@accent-color: @catppuccin[@@lookup][@@accent];
|
||||||
|
|
||||||
#piece(@name) {
|
#piece(@piece) {
|
||||||
@url: url("https://media.githubusercontent.com/media/catppuccin/userstyles/main/styles/chess.com/assets/@{lookup}/@{name}.png");
|
@url: url("https://media.githubusercontent.com/media/catppuccin/userstyles/main/styles/chess.com/assets/@{lookup}/@{piece}.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
@bb: #piece("b/bb") [];
|
@bb: #piece("b/bb") [];
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
/* ==UserStyle==
|
/* ==UserStyle==
|
||||||
@name Github Catppuccin
|
@name GitHub Catppuccin
|
||||||
@namespace github.com/catppuccin/userstyles/styles/github
|
@namespace github.com/catppuccin/userstyles/styles/github
|
||||||
@homepageURL https://github.com/catppuccin/userstyles/tree/main/styles/github
|
@homepageURL https://github.com/catppuccin/userstyles/tree/main/styles/github
|
||||||
@version 1.3.2
|
@version 1.3.3
|
||||||
@description Soothing pastel theme for GitHub
|
@description Soothing pastel theme for GitHub
|
||||||
@author Catppuccin
|
@author Catppuccin
|
||||||
@updateURL https://github.com/catppuccin/userstyles/raw/main/styles/github/catppuccin.user.css
|
@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
|
@supportURL https://github.com/catppuccin/userstyles/issues?q=is%3Aopen+is%3Aissue+label%3Agithub
|
||||||
@license MIT
|
@license MIT
|
||||||
|
|
||||||
@preprocessor less
|
@preprocessor less
|
||||||
@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"]
|
||||||
@@ -58,49 +58,49 @@
|
|||||||
z-index: 9999;
|
z-index: 9999;
|
||||||
}
|
}
|
||||||
|
|
||||||
#coloredButton(@name, @color, @flat) {
|
#coloredButton(@item, @color, @flat) {
|
||||||
& when (@flat) {
|
& when (@flat) {
|
||||||
--color-btn-@{name}-text: @color;
|
--color-btn-@{item}-text: @color;
|
||||||
--color-btn-@{name}-bg: @base;
|
--color-btn-@{item}-bg: @base;
|
||||||
--color-btn-@{name}-icon: @color;
|
--color-btn-@{item}-icon: @color;
|
||||||
|
|
||||||
--color-btn-@{name}-hover-text: @base;
|
--color-btn-@{item}-hover-text: @base;
|
||||||
--color-btn-@{name}-hover-bg: @color;
|
--color-btn-@{item}-hover-bg: @color;
|
||||||
--color-btn-@{name}-hover-border: @color;
|
--color-btn-@{item}-hover-border: @color;
|
||||||
|
|
||||||
--color-btn-@{name}-selected-text: @base;
|
--color-btn-@{item}-selected-text: @base;
|
||||||
--color-btn-@{name}-selected-bg: @color;
|
--color-btn-@{item}-selected-bg: @color;
|
||||||
--color-btn-@{name}-selected-border: @color;
|
--color-btn-@{item}-selected-border: @color;
|
||||||
|
|
||||||
--color-btn-@{name}-disabled-text: fadeout(@color, 60%);
|
--color-btn-@{item}-disabled-text: fadeout(@color, 60%);
|
||||||
--color-btn-@{name}-disabled-bg: @mantle;
|
--color-btn-@{item}-disabled-bg: @mantle;
|
||||||
}
|
}
|
||||||
|
|
||||||
& when not (@flat) {
|
& when not (@flat) {
|
||||||
--color-btn-@{name}-text: @base;
|
--color-btn-@{item}-text: @base;
|
||||||
--color-btn-@{name}-bg: @color;
|
--color-btn-@{item}-bg: @color;
|
||||||
--color-btn-@{name}-icon: @base;
|
--color-btn-@{item}-icon: @base;
|
||||||
|
|
||||||
--color-btn-@{name}-hover-text: @base;
|
--color-btn-@{item}-hover-text: @base;
|
||||||
--color-btn-@{name}-hover-bg: lighten(@color, 10%);
|
--color-btn-@{item}-hover-bg: lighten(@color, 10%);
|
||||||
--color-btn-@{name}-hover-border: lighten(@color, 10%);
|
--color-btn-@{item}-hover-border: lighten(@color, 10%);
|
||||||
|
|
||||||
--color-btn-@{name}-selected-text: @base;
|
--color-btn-@{item}-selected-text: @base;
|
||||||
--color-btn-@{name}-selected-bg: lighten(@color, 10%);
|
--color-btn-@{item}-selected-bg: lighten(@color, 10%);
|
||||||
--color-btn-@{name}-selected-border: lighten(@color, 10%);
|
--color-btn-@{item}-selected-border: lighten(@color, 10%);
|
||||||
|
|
||||||
--color-btn-@{name}-disabled-text: @crust;
|
--color-btn-@{item}-disabled-text: @crust;
|
||||||
--color-btn-@{name}-disabled-bg: fadeout(@color, 60%);
|
--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 */
|
/* set these to transparent for the looks */
|
||||||
--color-btn-@{name}-border: transparent;
|
--color-btn-@{item}-border: transparent;
|
||||||
--color-btn-@{name}-shadow: 0 0 transparent;
|
--color-btn-@{item}-shadow: 0 0 transparent;
|
||||||
--color-btn-@{name}-inset-shadow: 0 0 transparent;
|
--color-btn-@{item}-inset-shadow: 0 0 transparent;
|
||||||
--color-btn-@{name}-selected-shadow: 0 0 transparent;
|
--color-btn-@{item}-selected-shadow: 0 0 transparent;
|
||||||
--color-btn-@{name}-disabled-border: transparent;
|
--color-btn-@{item}-disabled-border: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
#catppuccin(@lookup, @accent) {
|
#catppuccin(@lookup, @accent) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* ==UserStyle==
|
/* ==UserStyle==
|
||||||
@name HackerNews Catppuccin
|
@name Hacker News Catppuccin
|
||||||
@namespace github.com/catppuccin/userstyles/styles/hacker-news
|
@namespace github.com/catppuccin/userstyles/styles/hacker-news
|
||||||
@homepageURL https://github.com/catppuccin/userstyles/tree/main/styles/hacker-news
|
@homepageURL https://github.com/catppuccin/userstyles/tree/main/styles/hacker-news
|
||||||
@version 0.1.1
|
@version 0.1.1
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* ==UserStyle==
|
/* ==UserStyle==
|
||||||
@name Hoppscotch.io Catppuccin
|
@name Hoppscotch Catppuccin
|
||||||
@namespace github.com/catppuccin/userstyles/styles/hoppscotch
|
@namespace github.com/catppuccin/userstyles/styles/hoppscotch
|
||||||
@homepageURL https://github.com/catppuccin/userstyles/tree/main/styles/hoppscotch
|
@homepageURL https://github.com/catppuccin/userstyles/tree/main/styles/hoppscotch
|
||||||
@version 1.0.0
|
@version 1.0.0
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* ==UserStyle==
|
/* ==UserStyle==
|
||||||
@name Lichess Catppuccin
|
@name lichess Catppuccin
|
||||||
@namespace github.com/catppuccin/userstyles/styles/lichess
|
@namespace github.com/catppuccin/userstyles/styles/lichess
|
||||||
@homepageURL https://github.com/catppuccin/userstyles/tree/main/styles/lichess
|
@homepageURL https://github.com/catppuccin/userstyles/tree/main/styles/lichess
|
||||||
@version 0.0.1
|
@version 0.0.1
|
||||||
|
|||||||
@@ -1133,10 +1133,6 @@
|
|||||||
.snoo-cls-11 {
|
.snoo-cls-11 {
|
||||||
fill: @sky;
|
fill: @sky;
|
||||||
}
|
}
|
||||||
|
|
||||||
.snoo-cls-11 {
|
|
||||||
fill: @sky;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* ==UserStyle==
|
/* ==UserStyle==
|
||||||
@name WhatsApp Web Catppuccin
|
@name WhatsApp Web Catppuccin
|
||||||
@namespace github.com/catppuccin/userstyles/styles/whatsapp-web
|
@namespace github.com/catppuccin/userstyles/styles/whatsapp-web
|
||||||
@homepageURL https://github.com/catppuccin/userstyles/tree/main/styles/whatsapp-web
|
@homepageURL https://github.com/catppuccin/userstyles/tree/main/styles/whatsapp-web
|
||||||
@version 0.0.4
|
@version 0.0.4
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* ==UserStyle==
|
/* ==UserStyle==
|
||||||
@name Wikiwand Catppuccin
|
@name WikiWand Catppuccin
|
||||||
@namespace github.com/catppuccin/userstyles/styles/wikiwand
|
@namespace github.com/catppuccin/userstyles/styles/wikiwand
|
||||||
@homepageURL https://github.com/catppuccin/userstyles/tree/main/styles/wikiwand
|
@homepageURL https://github.com/catppuccin/userstyles/tree/main/styles/wikiwand
|
||||||
@version 1.2.0
|
@version 1.2.0
|
||||||
|
|||||||
Reference in new issue
Block a user