-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdetect-changes.mjs
More file actions
38 lines (31 loc) · 1.21 KB
/
detect-changes.mjs
File metadata and controls
38 lines (31 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env node
import { execSync } from 'child_process';
import { appendFileSync } from 'fs';
const ALL_PACKAGES = ['wasm-bip32', 'wasm-mps', 'wasm-utxo', 'wasm-solana', 'wasm-dot', 'wasm-ton'];
function setOutput(packages) {
const value = JSON.stringify(packages);
appendFileSync(process.env.GITHUB_OUTPUT, `packages=${value}\n`);
console.log(`Packages to test: ${value}`);
}
// Non-PR events (push to master, workflow_dispatch): run everything
if (process.env.GITHUB_EVENT_NAME !== 'pull_request') {
setOutput(ALL_PACKAGES);
process.exit(0);
}
const base = process.env.BASE_SHA;
const head = process.env.HEAD_SHA;
const changedFiles = execSync(`git diff --name-only ${base} ${head}`)
.toString().trim().split('\n').filter(Boolean);
// Shared infrastructure changes → run all packages
const sharedChanged = changedFiles.some(f =>
/^(\.github\/|package\.json$|lerna\.json$|package-lock\.json$)/.test(f)
);
if (sharedChanged) {
setOutput(ALL_PACKAGES);
process.exit(0);
}
// Per-package detection; fall back to all if nothing package-specific changed
const changed = ALL_PACKAGES.filter(pkg =>
changedFiles.some(f => f.startsWith(`packages/${pkg}/`))
);
setOutput(changed.length > 0 ? changed : ALL_PACKAGES);