Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/scripts/detect-changes.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);
23 changes: 21 additions & 2 deletions .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,26 @@
WASM_OPT_VERSION: 0.116.1

jobs:
detect-changes:
name: "Detect Changes"
runs-on: ubuntu-latest
outputs:
packages: ${{ steps.set-matrix.outputs.packages }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
fetch-depth: 0

- name: Determine changed packages
id: set-matrix
env:
GITHUB_EVENT_NAME: ${{ github.event_name }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: node .github/scripts/detect-changes.mjs

build:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
name: "Build"
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -112,12 +131,12 @@

test:
name: "Test ${{ matrix.package }}"
needs: build
needs: [detect-changes, build]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
package: [wasm-bip32, wasm-mps, wasm-utxo, wasm-solana, wasm-dot, wasm-ton]
package: ${{ fromJson(needs.detect-changes.outputs.packages) }}
include:
- package: wasm-utxo
needs-wasm-pack: true
Expand Down
Loading