Skip to content

Commit 4d994bb

Browse files
committed
CI portability: resolve anvil/forge from PATH in sdk test helper; build SDK before service tests
1 parent 66147b5 commit 4d994bb

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ jobs:
207207
node-version: 22
208208
- name: Install workspace dependencies
209209
run: npm install
210+
- name: Build SDK
211+
working-directory: sdk
212+
run: npm run build
210213
- name: Install standalone service dependencies
211214
run: |
212215
npm install --prefix services/contract-audit

sdk/test/helpers/chain.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import {
1818
} from 'viem';
1919
import { privateKeyToAccount } from 'viem/accounts';
2020
import { join, dirname } from 'node:path';
21+
import { homedir } from 'node:os';
22+
import { existsSync } from 'node:fs';
2123
import { fileURLToPath } from 'node:url';
2224
import { PAYMENT_CHANNEL_ABI } from '../../src/contracts.js';
2325

@@ -26,8 +28,29 @@ const __dirname = dirname(__filename);
2628

2729
export const ANVIL_PORT = 8547;
2830
export const ANVIL_RPC = `http://127.0.0.1:${ANVIL_PORT}`;
29-
export const ANVIL_BIN = '/opt/homebrew/bin/anvil';
30-
export const FORGE_BIN = '/opt/homebrew/bin/forge';
31+
32+
function resolveBin(name: string): string {
33+
const envOverride = process.env[`${name.toUpperCase()}_BIN`];
34+
if (envOverride && existsSync(envOverride)) return envOverride;
35+
try {
36+
const found = execSync(`command -v ${name}`, { encoding: 'utf-8' }).trim();
37+
if (found) return found;
38+
} catch {
39+
// not on PATH; try well-known locations
40+
}
41+
const candidates = [
42+
`/opt/homebrew/bin/${name}`,
43+
`/usr/local/bin/${name}`,
44+
join(homedir(), '.foundry', 'bin', name),
45+
];
46+
for (const candidate of candidates) {
47+
if (existsSync(candidate)) return candidate;
48+
}
49+
return name;
50+
}
51+
52+
export const ANVIL_BIN = resolveBin('anvil');
53+
export const FORGE_BIN = resolveBin('forge');
3154
export const CONTRACTS_DIR = join(__dirname, '..', '..', '..', 'contracts');
3255

3356
export const ACCOUNTS = {

0 commit comments

Comments
 (0)