diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..53e16a6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,52 @@ +name: Validate themes + +on: + pull_request: + push: + branches: + - main + +permissions: + contents: read + +concurrency: + group: validate-${{ github.ref }} + cancel-in-progress: true + +jobs: + validate: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Install validation tools + run: | + python -m pip install --upgrade pip + python -m pip install PyYAML==6.0.2 + sudo apt-get update + sudo apt-get install -y shellcheck + + - name: Regenerate every editor theme + run: | + for generator in editors/*/generate.py; do + echo "::group::$generator" + (cd "$(dirname "$generator")" && python3 generate.py) + echo "::endgroup::" + done + + - name: Check generated files are committed + run: | + git diff --exit-code + test -z "$(git status --porcelain)" + + - name: Validate assets and documentation + run: python3 scripts/validate.py + + - name: Lint shell scripts + run: git ls-files -z '*.sh' | xargs -0 shellcheck -S error diff --git a/README.md b/README.md index 70b5442..747140c 100644 --- a/README.md +++ b/README.md @@ -204,6 +204,6 @@ Dev & -github +Github & X diff --git a/editors/eclipse/README.md b/editors/eclipse/README.md index 87c8a19..fa3a9f8 100644 --- a/editors/eclipse/README.md +++ b/editors/eclipse/README.md @@ -4,7 +4,7 @@
- License: MIT + License: MIT Eclipse Python Themes @@ -68,7 +68,7 @@
Dev & - github + Github & X
diff --git a/editors/netbeans/README.md b/editors/netbeans/README.md index 30a567f..04f4823 100644 --- a/editors/netbeans/README.md +++ b/editors/netbeans/README.md @@ -4,7 +4,7 @@
- License: MIT + License: MIT NetBeans Python Themes @@ -68,7 +68,7 @@
Dev & - github + Github & X
diff --git a/editors/sublime/README.md b/editors/sublime/README.md index cb1c91f..c33a829 100644 --- a/editors/sublime/README.md +++ b/editors/sublime/README.md @@ -4,7 +4,7 @@
- License: MIT + License: MIT Sublime Text Python Themes @@ -63,7 +63,7 @@
Dev & - github + Github & X
diff --git a/editors/sublime/generate.py b/editors/sublime/generate.py index 7bd9148..c852102 100644 --- a/editors/sublime/generate.py +++ b/editors/sublime/generate.py @@ -2,8 +2,8 @@ import os PARENT = os.path.dirname(__file__) -DIST_DIR = os.path.join(PARENT, "dist") -os.makedirs(DIST_DIR, exist_ok=True) +THEMES_DIR = os.path.join(PARENT, "themes") +os.makedirs(THEMES_DIR, exist_ok=True) with open(os.path.join(PARENT, "..", "..", "colors.json")) as f: palettes = json.load(f) @@ -184,7 +184,7 @@ def resolve(idx): } filename = f"{name}.sublime-color-scheme" - filepath = os.path.join(DIST_DIR, filename) + filepath = os.path.join(THEMES_DIR, filename) with open(filepath, "w") as f: json.dump(scheme, f, indent=2) print(f" ✓ {filename}") diff --git a/editors/textmate/README.md b/editors/textmate/README.md index 95a32e1..ff77156 100644 --- a/editors/textmate/README.md +++ b/editors/textmate/README.md @@ -52,4 +52,4 @@ rm ~/Library/Application\ Support/TextMate/Themes/Xscriptor\ *.tmTheme ## Links - [Repository](https://github.com/xscriptor-colors/ide) -- [Colors](../colors.md) +- [Colors](../../colors.md) diff --git a/editors/vim/README.md b/editors/vim/README.md index 234bc13..126fdf7 100644 --- a/editors/vim/README.md +++ b/editors/vim/README.md @@ -8,7 +8,7 @@ Copy the `.vim` files to your `~/.vim/colors/` directory: ```bash # Option 1: Copy all themes -cp dist/*.vim ~/.vim/colors/ +cp themes/*.vim ~/.vim/colors/ # Option 2: Use the install script chmod +x install.sh diff --git a/editors/visualstudio/README.md b/editors/visualstudio/README.md index 4884bde..1f2053f 100644 --- a/editors/visualstudio/README.md +++ b/editors/visualstudio/README.md @@ -4,7 +4,7 @@
- License: MIT + License: MIT Visual Studio Python Themes @@ -68,7 +68,7 @@
Dev & - github + Github & X
diff --git a/editors/xcode/README.md b/editors/xcode/README.md index 61d70e2..2e47ef9 100644 --- a/editors/xcode/README.md +++ b/editors/xcode/README.md @@ -4,7 +4,7 @@
- License: MIT + License: MIT Xcode Python Themes @@ -30,7 +30,7 @@

This generator reads ANSI terminal palettes (16 colors each, 12 palettes) defined in - colors.md and produces Xcode + colors.md and produces Xcode .xccolortheme files. Each palette maps to 24 Xcode syntax tokens (keywords, strings, comments, types, etc.) so that the editor's syntax highlighting matches the terminal color scheme. @@ -39,7 +39,7 @@

Canonical themes live in themes/. When the source palette changes, run the generator to rebuild them into - labs/dist/. + labs/dist/.


@@ -121,13 +121,13 @@ REPO="xscriptor/xcode" bash <(curl -fsSL ...) -s -- -u # remote uninstallRelated Documents
@@ -139,7 +139,7 @@ REPO="xscriptor/xcode" bash <(curl -fsSL ...) -s -- -u # remote uninstallDev & -github +Github & X diff --git a/editors/xcode/docs/color-mapping.md b/editors/xcode/docs/color-mapping.md index 04588bc..9fa9ecb 100644 --- a/editors/xcode/docs/color-mapping.md +++ b/editors/xcode/docs/color-mapping.md @@ -6,7 +6,7 @@

- Each palette defined in colors.md + Each palette defined in colors.md contains 16 ANSI colors (color0 through color15) plus background and foreground. The generator maps them to Xcode syntax tokens as follows: @@ -54,4 +54,4 @@ insertion point) are computed automatically based on background luminance.

-

Back to root README

+

Back to root README

diff --git a/editors/xcode/labs/README.md b/editors/xcode/labs/README.md index 43fcca0..b2e2898 100644 --- a/editors/xcode/labs/README.md +++ b/editors/xcode/labs/README.md @@ -9,12 +9,12 @@

generate_themes.py reads the palettes defined in - colors.md and produces + colors.md and produces Xcode theme files in dist/. Each theme maps the 16 ANSI colors to 24 Xcode syntax tokens.

-

See the root README for installation instructions and theme listing.

+

See the root README for installation instructions and theme listing.


@@ -105,4 +105,4 @@ colors = make_theme("Praha", theme)
-

Back to root README

+

Back to root README

diff --git a/editors/zed/README.md b/editors/zed/README.md index 6171d64..76d9704 100644 --- a/editors/zed/README.md +++ b/editors/zed/README.md @@ -8,7 +8,7 @@ ./install.sh ``` -Or manually copy the `.json` files from `dist/` to `~/.config/zed/themes/`. +Or manually copy the `.json` files from `themes/` to `~/.config/zed/themes/`. ## Uninstall diff --git a/scripts/validate.py b/scripts/validate.py new file mode 100644 index 0000000..26a3bac --- /dev/null +++ b/scripts/validate.py @@ -0,0 +1,173 @@ +#!/usr/bin/env python3 +"""Validate generated editor themes and repository documentation. + +Checks: + * JSON, TOML and XML/plist theme files parse. + * Shell install/uninstall scripts pass ``bash -n``. + * Relative links in Markdown files resolve. + * YAML is checked when PyYAML is available. +""" + +from __future__ import annotations + +import json +import re +import subprocess +import sys +import tomllib +from pathlib import Path +from urllib.parse import unquote, urlparse +from xml.etree import ElementTree + +ROOT = Path(__file__).resolve().parents[1] +SKIP_DIRS = {".git", "__pycache__"} +JSON_SUFFIXES = {".json", ".sublime-color-scheme"} +TOML_SUFFIXES = {".toml"} +XML_SUFFIXES = {".xml", ".tmTheme", ".vssettings", ".bbcolorproject", ".icls"} +YAML_SUFFIXES = {".yaml", ".yml"} +SHELL_SUFFIXES = {".sh"} + + +def iter_files(suffixes: set[str]) -> list[Path]: + files: list[Path] = [] + for path in ROOT.rglob("*"): + if not path.is_file() or path.suffix not in suffixes: + continue + rel = path.relative_to(ROOT) + if any(part in SKIP_DIRS for part in rel.parts): + continue + files.append(path) + return sorted(files) + + +def check_json(path: Path) -> str | None: + try: + with path.open(encoding="utf-8") as f: + json.load(f) + except (OSError, json.JSONDecodeError) as exc: + return f"{path.relative_to(ROOT)}: {exc}" + return None + + +def check_toml(path: Path) -> str | None: + try: + with path.open("rb") as f: + tomllib.load(f) + except (OSError, tomllib.TOMLDecodeError) as exc: + return f"{path.relative_to(ROOT)}: {exc}" + return None + + +def check_xml(path: Path) -> str | None: + try: + ElementTree.parse(path) + except (OSError, ElementTree.ParseError) as exc: + return f"{path.relative_to(ROOT)}: {exc}" + return None + + +def check_shell(path: Path) -> str | None: + result = subprocess.run( + ["bash", "-n", str(path)], + capture_output=True, + text=True, + ) + if result.returncode != 0: + detail = (result.stderr or result.stdout).strip() + return f"{path.relative_to(ROOT)}: {detail}" + return None + + +def check_yaml(path: Path) -> str | None: + try: + import yaml # type: ignore[import-not-found] + except ImportError: + return None + try: + with path.open(encoding="utf-8") as f: + yaml.safe_load(f) + except (OSError, yaml.YAMLError) as exc: + return f"{path.relative_to(ROOT)}: {exc}" + return None + + +LINK_RE = re.compile(r"(? list[str]: + issues: list[str] = [] + text = path.read_text(encoding="utf-8", errors="replace") + targets = LINK_RE.findall(text) + HREF_RE.findall(text) + for raw in targets: + target = raw.strip() + if target.startswith("<") and ">" in target: + target = target[1 : target.index(">")] + target = target.split(" ", 1)[0] + target = unquote(target) + parsed = urlparse(target) + if parsed.scheme or target.startswith("#") or target.startswith("//"): + continue + if target.startswith("/"): + continue + clean = target.split("#", 1)[0].split("?", 1)[0] + if not clean: + continue + destination = (path.parent / clean).resolve() + try: + destination.relative_to(ROOT.resolve()) + except ValueError: + continue + if not destination.exists(): + issues.append(f"{path.relative_to(ROOT)}: broken link {target!r}") + return issues + + +def main() -> int: + errors: list[str] = [] + checked = 0 + + for path in iter_files(JSON_SUFFIXES): + checked += 1 + error = check_json(path) + if error: + errors.append(error) + for path in iter_files(TOML_SUFFIXES): + checked += 1 + error = check_toml(path) + if error: + errors.append(error) + for path in iter_files(XML_SUFFIXES): + checked += 1 + error = check_xml(path) + if error: + errors.append(error) + for path in iter_files(SHELL_SUFFIXES): + checked += 1 + error = check_shell(path) + if error: + errors.append(error) + for path in iter_files(YAML_SUFFIXES): + checked += 1 + error = check_yaml(path) + if error: + errors.append(error) + + markdown_files = iter_files({".md"}) + for path in markdown_files: + checked += 1 + errors.extend(check_markdown_links(path)) + + print(f"Validated {checked} files ({len(markdown_files)} Markdown).") + if errors: + print("\nValidation failed:", file=sys.stderr) + for error in errors: + print(f" {error}", file=sys.stderr) + return 1 + + print("All checked files are valid.") + return 0 + + +if __name__ == "__main__": + sys.exit(main())