ci(lint): init (#318)

* ci(lint): init

This finishes what #132 started, supersedes #317 (thanks for the stylelint setup!)

* ci(lint): add stylelint

Co-authored-by: uncenter <[email protected]>
This commit is contained in:
winstonanduncenter authored and GitHub committed 2023-11-16 22:45:25 +01:00
1 parent 6496c51291
commit ff8da1e094
13 files changed
+1484 -73

No files matched your search

-50
View File
@@ -1,50 +0,0 @@
name: File Checker
on:
workflow_dispatch:
pull_request:
jobs:
file-checker:
name: Required files included
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check files
run: |
MISSING_FILES=0
echo "# Missing Files Found 😢" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
required_files=(
"catppuccin.user.css"
"assets/mocha.webp"
"assets/macchiato.webp"
"assets/frappe.webp"
"assets/latte.webp"
"assets/catwalk.webp"
)
find_files() {
local path=$1
for file in "${required_files[@]}"; do
if [ ! -f "$path/$file" ]; then
MISSING_FILES=1
echo "- $path/$file" >> $GITHUB_STEP_SUMMARY
fi
done
}
for dir in styles/*; do
if [ -d "$dir" ]; then
find_files "$dir"
fi
done
if [ $MISSING_FILES -eq 0 ]; then
echo "# No Missing Files 🙌" > $GITHUB_STEP_SUMMARY
fi
exit $MISSING_FILES
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
+2 -2
View File
@@ -42,8 +42,8 @@ jobs:
path: ${{ env.DENO_DIR }}
- name: Generate health files
working-directory: src/generate
run: ./generate.ts
working-directory: ./src
run: deno task generate
- name: Push changes
uses: stefanzweifel/git-auto-commit-action@v5
+34
View File
@@ -0,0 +1,34 @@
name: Lint
on:
workflow_dispatch:
pull_request:
push:
branches: [main]
env:
DENO_DIR: deno_cache
jobs:
lint:
name: Lint Userstyles
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- name: Cache Deno dependencies
uses: actions/cache@v3
with:
key: ${{ hashFiles('src/deno.lock') }}
path: ${{ env.DENO_DIR }}
- name: Run Lint
working-directory: src
run: deno task lint
+2 -2
View File
@@ -32,8 +32,8 @@ jobs:
- name: Sync maintainers
if: ${{ github.repository == 'catppuccin/userstyles' && github.ref == 'refs/heads/main' }}
working-directory: src/generate
run: ./syncMaintainers.ts
working-directory: ./src
run: deno task sync-maintainers
env:
GITHUB_TOKEN: ${{ secrets.USERSTYLES_TOKEN }}
+9 -1
View File
@@ -1,11 +1,19 @@
{
"imports": {
"@/": "./",
"std/": "https://deno.land/[email protected]/",
"catppuccin-repo/": "https://raw.githubusercontent.com/catppuccin/catppuccin/91d6b5433730103c504dcf43583b594e418ee7c1/",
"globber": "https://deno.land/x/[email protected]/mod.ts",
"@actions/core": "npm:@actions/[email protected]",
"@octokit/rest": "npm:@octokit/[email protected]",
"usercss-meta": "npm:[email protected]",
"ajv": "npm:[email protected]",
"octokit": "npm:@octokit/[email protected]"
"less": "npm:[email protected]"
},
"tasks": {
"generate": "./generate/main.ts",
"lint": "./lint/main.ts",
"sync-maintainers": "./sync-maintainers/main.ts",
"update-types": "deno run -A 'npm:json-schema-to-typescript' ./userstyles.schema.json types/userstyles.d.ts"
}
}
Generated
+1163 -1
View File
File diff suppressed because it is too large. Load diff
+11
View File
@@ -0,0 +1,11 @@
import schema from "./userstyles.schema.json" assert { type: "json" };
import portsSchema from "catppuccin-repo/resources/ports.schema.json" assert {
type: "json",
};
import { join } from "std/path/mod.ts";
const ROOT = new URL(".", import.meta.url).pathname;
/** absolute path to the repository */
export const REPO_ROOT = join(ROOT, "..");
export { portsSchema, schema };
-6
View File
@@ -1,6 +0,0 @@
import schema from "../userstyles.schema.json" assert { type: "json" };
import portsSchema from "catppuccin-repo/resources/ports.schema.json" assert {
type: "json",
};
export { portsSchema, schema };
@@ -1,9 +1,10 @@
#!/usr/bin/env -S deno run --allow-env --allow-read --allow-write --allow-net
import * as path from "std/path/mod.ts";
import { parse as parseYaml } from "std/yaml/mod.ts";
import Ajv from "ajv";
import { portsSchema, schema } from "./deps.ts";
import { portsSchema, REPO_ROOT, schema } from "@/deps.ts";
import {
ApplicationLink,
@@ -15,10 +16,9 @@ import {
Usage,
Userstyle,
Userstyles,
} from "./types.d.ts";
} from "@/types.d.ts";
const ROOT = new URL(".", import.meta.url).pathname;
const REPO_ROOT = path.join(ROOT, "../..");
const ISSUE_PREFIX = "lbl:";
type Metadata = {
@@ -41,7 +41,7 @@ const validate = ajv.compile<Metadata>(schema);
const validatePorts = ajv.compile<PortMetadata>(portsSchema);
const userstylesYaml = Deno.readTextFileSync(
path.join(ROOT, "../userstyles.yml"),
path.join(REPO_ROOT, "src/userstyles.yml"),
);
const userstylesData = parseYaml(userstylesYaml);
if (!validate(userstylesData)) {
+114
View File
@@ -0,0 +1,114 @@
#!/usr/bin/env -S deno run --allow-read --allow-write --allow-env --allow-sys=uid,gid
// TODO: remove this once types for usercss-meta are available
// deno-lint-ignore-file no-explicit-any
import { basename, dirname, join, relative } from "std/path/mod.ts";
import { globber } from "globber";
import core from "@actions/core";
// @deno-types="npm:@types/less";
import less from "less";
import usercssMeta from "usercss-meta";
import { lint } from "./stylelint.ts";
import { REPO_ROOT } from "@/deps.ts";
const iterator = globber({
include: ["styles/**/catppuccin.user.css"],
cwd: REPO_ROOT,
});
const missingFiles: string[] = [];
const assertions = (repo: string) => {
const pfx = "https://github.com/catppuccin/userstyles";
return {
namespace: `github.com/catppuccin/userstyles/styles/${repo}`,
author: "Catppuccin",
license: "MIT",
preprocessor: "less",
homepageURL: `${pfx}/tree/main/styles/${repo}`,
updateURL: `${pfx}/raw/main/styles/${repo}/catppuccin.user.css`,
};
};
for await (const entry of iterator) {
const repodir = dirname(entry.absolute);
const repo = basename(repodir);
const content = await Deno.readTextFile(entry.absolute);
let metadata: Record<string, any> = {};
try {
metadata = usercssMeta.parse(content).metadata;
} catch (err) {
core.error(err, { file: entry.relative });
}
const assert = assertions(repo);
Object.entries(assert).forEach(([k, v]) => {
const defacto = metadata[k];
if (defacto !== v) {
const line = content.split("\n").findIndex((line) => line.includes(k)) +
1;
core.warning(`Metadata \`${k}\` should be ${v} but is \`${defacto}\``, {
file: entry.relative,
startLine: line !== 0 ? line : undefined,
});
}
});
// don't attempt to compile or lint non-less files
if (metadata.preprocessor !== assert.preprocessor) continue;
const globalVars = Object.entries(metadata.vars)
.reduce((acc, [k, v]) => {
// @ts-expect-error untyped
return { ...acc, [k]: v.default };
}, {});
less.render(content, { lint: true, globalVars }).then().catch(
(err: any) => {
core.error(err.message, {
file: entry.relative,
startLine: err.line,
endLine: err.line,
});
},
);
lint(content).then(({ results }) => {
results.sort(
(a, b) => (a.source ?? "").localeCompare(b.source ?? ""),
).map((result) => {
result.warnings.map((warning) => {
core.warning(warning.text ?? "unspecified", {
file: entry.relative,
startLine: warning.line,
endLine: warning.endLine,
startColumn: warning.column,
endColumn: warning.endColumn,
});
});
});
});
[
"catppuccin.user.css",
...["latte", "frappe", "macchiato", "mocha", "catwalk"].map((f) =>
`assets/${f}.webp`
),
].map(async (fp) => {
const filepath = join(repodir, fp);
await Deno.stat(join(repodir, fp)).catch(() => {
missingFiles.push(relative(REPO_ROOT, filepath));
});
});
}
// only write summary if running in github actions
if (Deno.env.has("GITHUB_ACTIONS") && missingFiles.length !== 0) {
await core.summary.addHeading("Missing files").addList(missingFiles).write();
Deno.exit(1);
}
+139
View File
@@ -0,0 +1,139 @@
import { deepMerge } from "std/collections/mod.ts";
import stylelint from "npm:stylelint";
import stylelintConfigStandard from "npm:stylelint-config-standard";
import stylelintConfigRecommended from "npm:stylelint-config-recommended";
import postcssLess from "npm:postcss-less";
const config: stylelint.Config = {
customSyntax: postcssLess,
rules: {
"selector-class-pattern": null,
"custom-property-pattern": null,
"selector-id-pattern": null,
"rule-empty-line-before": null,
"comment-empty-line-before": null,
"custom-property-empty-line-before": null,
"at-rule-empty-line-before": null,
"declaration-empty-line-before": null,
"property-no-vendor-prefix": null,
"alpha-value-notation": null,
"color-function-notation": null,
"hue-degree-notation": null,
"length-zero-no-unit": null,
"function-no-unknown": [
true,
{
// generated from https://lesscss.org/functions/
// via `Array.from(document.querySelectorAll('.section-content h3.docs-heading'), heading => heading.textContent.replace('\n', ''))`
ignoreFunctions: [
"%",
"abs",
"acos",
"alpha",
"argb",
"asin",
"atan",
"average",
"blue",
"boolean",
"ceil",
"color",
"contrast",
"convert",
"cos",
"darken",
"data-uri",
"default",
"desaturate",
"difference",
"e",
"each",
"escape",
"exclusion",
"extract",
"fade",
"fadein",
"fadeout",
"floor",
"get-unit",
"green",
"greyscale",
"hardlight",
"hsl",
"hsla",
"hsv",
"hsva",
"hsvhue",
"hsvsaturation",
"hsvvalue",
"hue",
"if",
"image-height",
"image-size",
"image-width",
"iscolor",
"isdefined",
"isem",
"iskeyword",
"isnumber",
"ispercentage",
"ispixel",
"isruleset",
"isstring",
"isunit",
"isurl",
"length",
"lighten",
"lightness",
"luma",
"luminance",
"max",
"min",
"mix",
"mod",
"multiply",
"negation",
"overlay",
"percentage",
"pi",
"pow",
"range",
"red",
"replace",
"rgb",
"rgba",
"round",
"saturate",
"saturation",
"screen",
"shade",
"sin",
"softlight",
"spin",
"sqrt",
"svg-gradient",
"tan",
"tint",
"unit",
],
},
],
"function-name-case": null,
"no-descending-specificity": null,
},
};
const base = deepMerge(
stylelintConfigRecommended,
{ ...stylelintConfigStandard, extends: {} },
);
export const lint = (code: string) =>
stylelint.lint({
config: deepMerge(base, config),
code,
});
@@ -1,23 +1,22 @@
#!/usr/bin/env -S deno run --allow-read --allow-net --allow-env
import * as assert from "std/assert/mod.ts";
import * as path from "std/path/mod.ts";
import { parse as parseYaml } from "std/yaml/mod.ts";
import Ajv from "ajv";
import { Octokit } from "octokit";
import { Octokit } from "@octokit/rest";
import { schema } from "./deps.ts";
import { Userstyle, UserstylesSchema } from "./types.d.ts";
import { REPO_ROOT, schema } from "@/deps.ts";
import { Userstyle, UserstylesSchema } from "@/types.d.ts";
const octokit = new Octokit({ auth: Deno.env.get("GITHUB_TOKEN") });
const team = { org: "catppuccin", team_slug: "userstyles-maintainers" };
const ROOT = new URL(".", import.meta.url).pathname;
const ajv = new Ajv.default();
const validate = ajv.compile<UserstylesSchema>(schema);
const userstylesYaml = Deno.readTextFileSync(
path.join(ROOT, "../userstyles.yml"),
path.join(REPO_ROOT, "src/userstyles.yml"),
);
const userstylesData = parseYaml(userstylesYaml);
if (!validate(userstylesData)) {
+1 -1
View File
@@ -1,2 +1,2 @@
export * from "../types/userstyles.d.ts";
export * from "./types/userstyles.d.ts";
export type { Categories as PortCategories } from "catppuccin-repo/resources/generate/types.d.ts";