-
-
Notifications
You must be signed in to change notification settings - Fork 6
ci: cross-size plugin safety workflow + clock-simple golden example #144
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
Merged
ChuckBuilds
merged 2 commits into
ChuckBuilds:main
from
rpierce99:safe/plugin-size-harness-upstream
Jun 7, 2026
Merged
Changes from all commits
Commits
Show all changes
2 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,152 @@ | ||
| name: Plugin Safety | ||
|
|
||
| # Renders every changed plugin across a representative spread of matrix sizes and | ||
| # screens using the LEDMatrix core harness, and validates manifests. Gates PRs | ||
| # that touch plugin code so a change can't silently break a size or screen. | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - 'plugins/**' | ||
| workflow_dispatch: | ||
| inputs: | ||
| all: | ||
| description: 'Check every plugin (not just changed ones)' | ||
| type: boolean | ||
| default: false | ||
|
|
||
| env: | ||
| # The core repo provides the harness (scripts/check_plugin.py). Point these at | ||
| # the fork/branch where the harness lives until it is merged upstream. | ||
| CORE_REPO: ChuckBuilds/LEDMatrix | ||
| CORE_REF: main | ||
|
|
||
| jobs: | ||
| safety: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout plugins | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| path: plugins-repo | ||
|
|
||
| - name: Checkout core (harness) | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| repository: ${{ env.CORE_REPO }} | ||
| ref: ${{ env.CORE_REF }} | ||
| path: core | ||
|
|
||
| - uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.12' | ||
| cache: pip | ||
|
|
||
| - name: Install core + harness deps | ||
| working-directory: core | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install -r requirements.txt -r requirements-test.txt | ||
| pip install RGBMatrixEmulator | ||
|
|
||
| - name: Determine changed plugins (non-test code only) | ||
| id: changed | ||
| working-directory: plugins-repo | ||
| env: | ||
| ALL_INPUT: ${{ github.event.inputs.all }} | ||
| BASE_SHA: ${{ github.event.pull_request.base.sha }} | ||
| run: | | ||
| if [ "$ALL_INPUT" = "true" ]; then | ||
| ids=$(ls plugins) | ||
| else | ||
| # Plugins with a changed file outside their test/ dir. | ||
| ids=$(git diff --name-only "$BASE_SHA"...HEAD -- 'plugins/*' \ | ||
| | grep -vE '^plugins/[^/]+/test/' \ | ||
| | sed -E 's#^plugins/([^/]+)/.*#\1#' | sort -u) | ||
| fi | ||
| echo "ids<<EOF" >> "$GITHUB_OUTPUT" | ||
| echo "$ids" >> "$GITHUB_OUTPUT" | ||
| echo "EOF" >> "$GITHUB_OUTPUT" | ||
| echo "Changed plugins:"; echo "$ids" | ||
|
|
||
| - name: Enforce version bump on changed plugins | ||
| if: steps.changed.outputs.ids != '' && github.event.inputs.all != 'true' | ||
| working-directory: plugins-repo | ||
| env: | ||
| # Read IDs from env (never interpolate ${{ }} into the script body) and | ||
| # validate each one — plugin ids flow into python -c strings below, so a | ||
| # crafted directory name on a PR branch could otherwise inject code. | ||
| IDS: ${{ steps.changed.outputs.ids }} | ||
| BASE_SHA: ${{ github.event.pull_request.base.sha }} | ||
| run: | | ||
| fail=0 | ||
| for pid in $IDS; do | ||
| case "$pid" in | ||
| '' | *[!a-z0-9._-]*) echo "::error::invalid plugin id '$pid'"; fail=1; continue ;; | ||
| esac | ||
| cur=$(python -c "import json;print(json.load(open('plugins/$pid/manifest.json'))['version'])") | ||
| old=$(git show "$BASE_SHA:plugins/$pid/manifest.json" 2>/dev/null \ | ||
| | python -c "import json,sys;print(json.load(sys.stdin)['version'])" 2>/dev/null || echo "") | ||
| if [ -n "$old" ] && [ "$cur" = "$old" ]; then | ||
| echo "::error::$pid code changed but version not bumped (still $cur). Users won't get the update." | ||
| fail=1 | ||
| else | ||
| echo "[ok] $pid version $old -> $cur" | ||
| fi | ||
| done | ||
| exit $fail | ||
|
|
||
| - name: Validate manifests against schema | ||
| if: steps.changed.outputs.ids != '' | ||
| env: | ||
| IDS: ${{ steps.changed.outputs.ids }} | ||
| run: | | ||
| python - <<'PY' | ||
| import json, os, re, sys | ||
| from pathlib import Path | ||
| import jsonschema | ||
| schema = json.load(open("core/schema/manifest_schema.json")) | ||
| valid = re.compile(r"^[a-z0-9][a-z0-9._-]*$") | ||
| ids = os.environ.get("IDS", "").split() | ||
| failed = False | ||
| for pid in ids: | ||
| if not valid.match(pid): | ||
| print(f"[FAIL] invalid plugin id: {pid!r}"); failed = True; continue | ||
| mpath = Path("plugins-repo/plugins") / pid / "manifest.json" | ||
| if not mpath.exists(): | ||
| print(f"[skip] {pid}: no manifest (deleted?)"); continue | ||
| try: | ||
| jsonschema.validate(json.load(open(mpath)), schema) | ||
| print(f"[ok] {pid}: manifest valid") | ||
| except jsonschema.ValidationError as e: | ||
| print(f"[FAIL] {pid}: {e.message}"); failed = True | ||
| sys.exit(1 if failed else 0) | ||
| PY | ||
|
|
||
| - name: Run safety harness on changed plugins | ||
| if: steps.changed.outputs.ids != '' | ||
| env: | ||
| IDS: ${{ steps.changed.outputs.ids }} | ||
| run: | | ||
| set -e | ||
| fail=0 | ||
| for pid in $IDS; do | ||
| case "$pid" in | ||
| '' | *[!a-z0-9._-]*) echo "::error::invalid plugin id '$pid'"; fail=1; continue ;; | ||
| esac | ||
| pdir="plugins-repo/plugins/$pid" | ||
| [ -d "$pdir" ] || { echo "::notice::$pid removed, skipping"; continue; } | ||
| echo "::group::$pid" | ||
| # Install the plugin's own runtime deps so it loads like a real install. | ||
| # A failure here is a real problem (the plugin can't load), so let it fail. | ||
| if [ -f "$pdir/requirements.txt" ]; then pip install -r "$pdir/requirements.txt"; fi | ||
| python core/scripts/check_plugin.py --plugin "$pid" \ | ||
| --plugin-dir "$PWD/plugins-repo/plugins" || fail=1 | ||
| echo "::endgroup::" | ||
| done | ||
| exit $fail | ||
|
|
||
| - name: Nothing to check | ||
| if: steps.changed.outputs.ids == '' | ||
| run: echo "No plugin code changed (test-only or docs change) — safety harness skipped." | ||
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,11 @@ | ||
| { | ||
| "_comment": "Settings the plugin safety harness uses to render clock-simple deterministically for golden-image comparison. timezone=UTC + a frozen UTC instant make the output identical on any host.", | ||
| "config": { | ||
| "timezone": "UTC", | ||
| "time_format": "12h", | ||
| "show_seconds": false, | ||
| "show_date": true | ||
| }, | ||
| "mock_data": {}, | ||
| "freeze_time": "2025-08-01 15:25:00" | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: ChuckBuilds/ledmatrix-plugins
Length of output: 160
🏁 Script executed:
Repository: ChuckBuilds/ledmatrix-plugins
Length of output: 5428
Pin GitHub Actions
usesto commit SHAs..github/workflows/test-plugins.ymluses tag-based actions:actions/checkout@v4(lines 29, 35)actions/setup-python@v5(line 41)Pin each
uses:to an immutable commit SHA to reduce supply-chain risk and satisfy hardened workflow policy.🧰 Tools
🪛 zizmor (1.25.2)
[error] 29-29: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy)
(unpinned-uses)
🤖 Prompt for AI Agents
Source: Linters/SAST tools