Skip to content

Commit 772c96d

Browse files
committed
fix(sea): resolve audit tools and authorize native builds
1 parent 7d75eb5 commit 772c96d

2 files changed

Lines changed: 31 additions & 28 deletions

File tree

‎.github/workflows/ci-sea.yml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,17 @@ jobs:
4141
payload-token-client-id: ${{ vars.SOCKET_PR_CLIENT_ID }}
4242
payload-token-private-key: ${{ secrets.SOCKET_PR_APP_PRIVATE_KEY }}
4343
socket-api-token: ${{ secrets.SOCKET_API_TOKEN_FOR_CLI_AND_SFW }}
44+
- name: Mint sdxgen read token
45+
id: sdxgen-token
46+
uses: ./.github/actions/fleet/github-payload-app-token
47+
with:
48+
client-id: ${{ vars.SOCKET_PR_CLIENT_ID }}
49+
private-key: ${{ secrets.SOCKET_PR_APP_PRIVATE_KEY }}
50+
repositories: sdxgen
4451
- name: Build CLI payload
52+
env:
53+
GH_TOKEN: ${{ github.token }}
54+
SDXGEN_GITHUB_TOKEN: ${{ steps.sdxgen-token.outputs.token }}
4555
run: pnpm run build:cli
4656
- name: Build native sea
4757
run: pnpm run build:sea --target=host

‎src/core/optimize/pastoralist-audit.mts‎

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,46 @@
1-
/**
2-
* Pastoralist override audit for the optimize command. Runs pastoralist's
3-
* update pipeline against the project so stale package-manager overrides get
4-
* the review record (and pruning) pastoralist maintains, before socket's own.
5-
*
6-
* @socketregistry overrides are applied.
7-
*
8-
* Key Functions: - runPastoralistAudit: spawn the pinned pastoralist bin
9-
* against the project root, never failing the optimize run on its errors.
10-
*
11-
* Spawned (not imported) for the same reason the package-manager agents are:
12-
* the dependency stays out of the CLI's CJS bundle (pastoralist's dist uses
13-
* top-level await, which rolldown cannot emit as CJS) while the lockfile
14-
* still pins the exact audited version.
15-
*/
16-
17-
import { fileURLToPath } from 'node:url'
1+
import { readFileSync } from 'node:fs'
2+
import { findPackageJSON } from 'node:module'
3+
import path from 'node:path'
4+
import { pathToFileURL } from 'node:url'
185

196
import { debug, debugDir } from '@socketsecurity/lib-stable/debug/output'
207
import { getDefaultLogger } from '@socketsecurity/lib-stable/logger/default'
218
import { spawn } from '@socketsecurity/lib-stable/process/spawn/child'
9+
import { rootPath } from '../../constants/paths.mts'
10+
import { resolveNodeRuntime } from '../../util/spawn/node-runtime.mts'
11+
2212
const logger = getDefaultLogger()
2313

2414
export type PastoralistAuditResult = {
2515
ok: boolean
2616
reason?: string | undefined
2717
}
2818

29-
/**
30-
* Run pastoralist's override audit against `root`: its update flow writes
31-
* the override review appendix and prunes overrides whose reason is gone.
32-
* Errors are logged and swallowed — an audit miss must never block the
33-
* optimization it precedes.
34-
*/
3519
export async function runPastoralistAudit(
3620
root: string,
3721
): Promise<PastoralistAuditResult> {
3822
let binPath: string
3923
try {
40-
// pastoralist's exports map carries only an `import` condition for `.`
41-
// (dist/index.js, the bin), so the import-condition resolver finds it
42-
// where a require-resolve cannot.
43-
binPath = fileURLToPath(import.meta.resolve('pastoralist'))
24+
const manifest = findPackageJSON(
25+
'pastoralist',
26+
pathToFileURL(path.join(rootPath, 'package.json')),
27+
)
28+
if (!manifest) {
29+
return { ok: false, reason: 'pastoralist is not installed' }
30+
}
31+
const packageJson = JSON.parse(readFileSync(manifest, 'utf8')) as {
32+
bin: { pastoralist: string }
33+
}
34+
binPath = path.resolve(path.dirname(manifest), packageJson.bin.pastoralist)
4435
} catch (e) {
4536
debug('pastoralist is not resolvable from this checkout')
4637
debugDir(e)
4738
return { ok: false, reason: 'pastoralist is not installed' }
4839
}
4940

50-
const result = await spawn(process.execPath, [binPath, '--root', root], {
41+
const runtime = await resolveNodeRuntime({ cwd: root })
42+
const result = await spawn(runtime.executable, [binPath, '--root', root], {
43+
env: runtime.environment,
5144
cwd: root,
5245
stdio: 'inherit',
5346
})

0 commit comments

Comments
 (0)