Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/scripts/utils/cache_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import os
import json
import hashlib

CACHE_FILE = os.path.join(os.getcwd(), ".cache", "plugin_validation.json")

class ValidationCache:
def __init__(self):
self.cache = self._load_cache()

def _load_cache(self):
if os.path.exists(CACHE_FILE):
try:
with open(CACHE_FILE, "r", encoding="utf-8") as f:
return json.load(f)
except Exception:
pass
return {}

def get_hash(self, target_path):
hasher = hashlib.sha256()

if os.path.isfile(target_path):
with open(target_path, "rb") as f:
while chunk := f.read(8192):
hasher.update(chunk)
elif os.path.isdir(target_path):
for root, dirs, files in os.walk(target_path):
# Ignore .git and .cache folders
dirs[:] = [d for d in dirs if not d.startswith(".")]
for file in sorted(files):
file_path = os.path.join(root, file)
hasher.update(file.encode("utf-8"))
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated
try:
with open(file_path, "rb") as f:
while chunk := f.read(8192):
hasher.update(chunk)
except Exception:
pass

return hasher.hexdigest()

def is_cached(self, path):
if not os.path.exists(path):
return False
return self.cache.get(path) == self.get_hash(path)

def update(self, path):
if os.path.exists(path):
self.cache[path] = self.get_hash(path)

def save(self):
os.makedirs(os.path.dirname(CACHE_FILE), exist_ok=True)
with open(CACHE_FILE, "w", encoding="utf-8") as f:
json.dump(self.cache, f, indent=2)
58 changes: 58 additions & 0 deletions .github/scripts/validate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import os
import sys
import json
import glob
from concurrent.futures import ThreadPoolExecutor
from utils.cache_manager import ValidationCache

cache = ValidationCache()

IGNORE_PATHS = {".git", ".github", ".cache", "node_modules", "scripts", "package-lock.json", "package.json"}

def validate_plugin(plugin_path):
base_name = os.path.basename(plugin_path)
if base_name in IGNORE_PATHS or not os.path.exists(plugin_path):
return True, f"Skipped (system path): {base_name}"

if cache.is_cached(plugin_path):
return True, f"Skipped (cached): {base_name}"

errors = []
if os.path.isdir(plugin_path):
json_files = glob.glob(os.path.join(plugin_path, "**/*.json"), recursive=True)
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated
for jf in json_files:
try:
with open(jf, "r", encoding="utf-8") as f:
json.load(f)
except Exception as e:
errors.append(f"Invalid JSON format in {jf}: {str(e)}")

if errors:
return False, "\n".join(errors)

cache.update(plugin_path)
return True, f"Validated: {base_name}"

def main():
target_dir = os.getcwd()
entries = [os.path.join(target_dir, d) for d in os.listdir(target_dir) if d not in IGNORE_PATHS]

print(f"🔍 Validating plugins across {len(entries)} target paths using parallel workers...")

failed = False
with ThreadPoolExecutor(max_workers=8) as executor:
results = executor.map(validate_plugin, entries)
for success, msg in results:
print(f" -> {msg}")
if not success:
failed = True

cache.save()
if failed:
print("❌ Plugin validation failed!")
sys.exit(1)
else:
print("✅ All plugin configurations validated successfully.")

if __name__ == "__main__":
main()
30 changes: 30 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Validate Plugins

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Restore Validation Cache
uses: actions/cache@v4
with:
path: .cache/plugin_validation.json
key: plugin-cache-${{ runner.os }}-${{ github.sha }}
restore-keys: |
plugin-cache-${{ runner.os }}-
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated

- name: Run Plugin Validator
run: python3 .github/scripts/validate.py
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ build/

# Logs
*.log

# Local validation cache
.cache/
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,10 @@ plugins/
## License

MIT

## Local Validation

Run parallel validator locally:
```bash
python3 .github/scripts/validate.py
```
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.