Repository navigation
[trial] Exercise the Plugin tests workflow from #84 (do not merge) #2
Workflow file for this run
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
| name: Plugin tests | |
| on: | |
| pull_request: | |
| paths: | |
| - 'plugins/**' | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: plugin-tests-${{ github.event.pull_request.number }} | |
| cancel-in-progress: true | |
| jobs: | |
| detect: | |
| name: detect changed plugins | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| outputs: | |
| dirs: ${{ steps.detect.outputs.dirs }} | |
| steps: | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| # The pull_request checkout is the PR's merge commit; its first parent is the base. | |
| fetch-depth: 2 | |
| persist-credentials: false | |
| - id: detect | |
| name: List changed plugins with a test script | |
| run: | | |
| set -euo pipefail | |
| git diff --name-only -z HEAD^1 HEAD -- plugins/ \ | |
| | node -e ' | |
| const fs = require("fs"); | |
| const path = require("path"); | |
| const files = fs.readFileSync(0, "utf8").split("\0").filter(Boolean); | |
| const dirs = new Set(); | |
| for (const f of files) { | |
| const p = f.split("/"); | |
| if (p.length >= 4 && p[0] === "plugins" && p[1] && p[2]) dirs.add(`plugins/${p[1]}/${p[2]}`); | |
| } | |
| const out = []; | |
| for (const d of [...dirs].sort()) { | |
| const pkg = path.join(d, "package.json"); | |
| try { | |
| if (!fs.statSync(d).isDirectory()) continue; | |
| const j = JSON.parse(fs.readFileSync(pkg, "utf8")); | |
| if (j && j.scripts && typeof j.scripts.test === "string" && j.scripts.test.trim()) out.push(d); | |
| } catch { /* missing dir or package.json, or invalid JSON: skip */ } | |
| } | |
| process.stdout.write(JSON.stringify(out)); | |
| ' > dirs.json | |
| echo "Plugins to test: $(cat dirs.json)" | |
| echo "dirs=$(cat dirs.json)" >> "$GITHUB_OUTPUT" | |
| test: | |
| name: test (${{ matrix.dir }}) | |
| needs: detect | |
| if: needs.detect.outputs.dirs != '' && needs.detect.outputs.dirs != '[]' | |
| runs-on: macos-latest | |
| timeout-minutes: 10 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| dir: ${{ fromJSON(needs.detect.outputs.dirs) }} | |
| defaults: | |
| run: | |
| working-directory: ${{ matrix.dir }} | |
| steps: | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| persist-credentials: false | |
| - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 | |
| with: | |
| node-version: 22 | |
| - name: Install plugin dependencies | |
| run: | | |
| set -euo pipefail | |
| if [ -f package-lock.json ]; then | |
| npm ci --no-audit --no-fund | |
| elif node -e 'const p=require("./package.json"); process.exit(Object.keys({...p.dependencies, ...p.devDependencies}).length ? 0 : 1)'; then | |
| npm install --no-audit --no-fund | |
| else | |
| echo "No dependencies declared; skipping install." | |
| fi | |
| - name: npm test | |
| run: npm test |