|
1 | 1 | #!/usr/bin/env node |
2 | | -import { execSync } from 'child_process'; |
3 | | -import { appendFileSync } from 'fs'; |
| 2 | +import { execSync } from "child_process"; |
| 3 | +import { appendFileSync } from "fs"; |
4 | 4 |
|
5 | | -const ALL_PACKAGES = ['wasm-bip32', 'wasm-mps', 'wasm-utxo', 'wasm-solana', 'wasm-dot', 'wasm-ton', 'wasm-privacy-coin']; |
| 5 | +// Per-package matrix entries. Each object becomes one `matrix.include` |
| 6 | +// combination in the `test` job. The flags gate steps there: |
| 7 | +// - needs-wasm-pack: download the build artifact (wasm .js/.wasm) |
| 8 | +// - has-wasm-pack-tests: run `npm run test:wasm-pack-{node,chrome}` |
| 9 | +// Keeping the flags here (instead of a static `include:` block in the |
| 10 | +// workflow) is what actually lets `detect-changes` shrink the matrix — a |
| 11 | +// workflow `include:` entry whose `package` conflicts with the base matrix |
| 12 | +// spawns a NEW job rather than being filtered out, which previously |
| 13 | +// re-added every package on every PR. |
| 14 | +const PACKAGE_CONFIG = [ |
| 15 | + { package: "wasm-utxo", "needs-wasm-pack": true, "has-wasm-pack-tests": true }, |
| 16 | + { package: "wasm-bip32", "needs-wasm-pack": false, "has-wasm-pack-tests": false }, |
| 17 | + { package: "wasm-mps", "needs-wasm-pack": false, "has-wasm-pack-tests": false }, |
| 18 | + { package: "wasm-solana", "needs-wasm-pack": false, "has-wasm-pack-tests": false }, |
| 19 | + { package: "wasm-dot", "needs-wasm-pack": false, "has-wasm-pack-tests": false }, |
| 20 | + { package: "wasm-ton", "needs-wasm-pack": false, "has-wasm-pack-tests": false }, |
| 21 | + { package: "wasm-privacy-coin", "needs-wasm-pack": false, "has-wasm-pack-tests": false }, |
| 22 | +]; |
6 | 23 |
|
7 | | -function setOutput(packages) { |
8 | | - const value = JSON.stringify(packages); |
| 24 | +const ALL_PACKAGES = PACKAGE_CONFIG.map((p) => p.package); |
| 25 | + |
| 26 | +function setOutput(entries) { |
| 27 | + const value = JSON.stringify(entries); |
9 | 28 | appendFileSync(process.env.GITHUB_OUTPUT, `packages=${value}\n`); |
10 | 29 | console.log(`Packages to test: ${value}`); |
11 | 30 | } |
12 | 31 |
|
| 32 | +function entriesFor(pkgs) { |
| 33 | + const wanted = new Set(pkgs); |
| 34 | + return PACKAGE_CONFIG.filter((p) => wanted.has(p.package)); |
| 35 | +} |
| 36 | + |
13 | 37 | // Non-PR events (push to master, workflow_dispatch): run everything |
14 | | -if (process.env.GITHUB_EVENT_NAME !== 'pull_request') { |
15 | | - setOutput(ALL_PACKAGES); |
| 38 | +if (process.env.GITHUB_EVENT_NAME !== "pull_request") { |
| 39 | + setOutput(PACKAGE_CONFIG); |
16 | 40 | process.exit(0); |
17 | 41 | } |
18 | 42 |
|
19 | 43 | const base = process.env.BASE_SHA; |
20 | 44 | const head = process.env.HEAD_SHA; |
21 | 45 |
|
22 | 46 | const changedFiles = execSync(`git diff --name-only ${base} ${head}`) |
23 | | - .toString().trim().split('\n').filter(Boolean); |
| 47 | + .toString() |
| 48 | + .trim() |
| 49 | + .split("\n") |
| 50 | + .filter(Boolean); |
24 | 51 |
|
25 | 52 | // Shared infrastructure changes → run all packages |
26 | | -const sharedChanged = changedFiles.some(f => |
27 | | - /^(\.github\/|package\.json$|lerna\.json$|package-lock\.json$)/.test(f) |
| 53 | +const sharedChanged = changedFiles.some((f) => |
| 54 | + /^(\.github\/|package\.json$|lerna\.json$|package-lock\.json$)/.test(f), |
28 | 55 | ); |
29 | 56 | if (sharedChanged) { |
30 | | - setOutput(ALL_PACKAGES); |
| 57 | + setOutput(PACKAGE_CONFIG); |
31 | 58 | process.exit(0); |
32 | 59 | } |
33 | 60 |
|
34 | 61 | // Per-package detection; fall back to all if nothing package-specific changed |
35 | | -const changed = ALL_PACKAGES.filter(pkg => |
36 | | - changedFiles.some(f => f.startsWith(`packages/${pkg}/`)) |
| 62 | +const changed = ALL_PACKAGES.filter((pkg) => |
| 63 | + changedFiles.some((f) => f.startsWith(`packages/${pkg}/`)), |
37 | 64 | ); |
38 | | -setOutput(changed.length > 0 ? changed : ALL_PACKAGES); |
| 65 | +setOutput(changed.length > 0 ? entriesFor(changed) : PACKAGE_CONFIG); |
0 commit comments