Repository navigation
perf(ci): parallelize plugin validation and add sha256 workspace caching #247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Louis1125
wants to merge
3
commits into
cursor:main
Choose a base branch
from
Louis1125:perf/parallel-validation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+146
−0
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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")) | ||
| 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) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
|
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() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }}- | ||
|
cursor[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| - name: Run Plugin Validator | ||
| run: python3 .github/scripts/validate.py | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,3 +33,6 @@ build/ | |
|
|
||
| # Logs | ||
| *.log | ||
|
|
||
| # Local validation cache | ||
| .cache/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.