Skip to content

Commit c142890

Browse files
authored
chore: Put provenance into publishConfig and call npm publish directly (#1871)
Just throwing stuff at the wall now tbh. Currently fighting ENEEDAUTH: https://github.com/braintrustdata/braintrust-sdk-javascript/actions/runs/24687031527/job/72198977988
1 parent 6b1e73e commit c142890

11 files changed

Lines changed: 128 additions & 10 deletions

File tree

.github/workflows/publish-js-sdk.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ jobs:
5858
if: steps.detect.outputs.needs_publish == 'true'
5959
env:
6060
NODE_AUTH_TOKEN: ""
61-
run: pnpm exec changeset publish
61+
NPM_TOKEN: ""
62+
run: node scripts/release/publish-release-manifest.mjs --manifest .release-manifest.json
6263
- name: Push Changesets release tags
6364
if: steps.detect.outputs.has_work == 'true'
6465
run: |
@@ -168,7 +169,8 @@ jobs:
168169
if: steps.manifest.outputs.has_packages == 'true'
169170
env:
170171
NODE_AUTH_TOKEN: ""
171-
run: pnpm exec changeset publish --tag rc --no-git-tag
172+
NPM_TOKEN: ""
173+
run: node scripts/release/publish-release-manifest.mjs --manifest .release-manifest.json --tag rc
172174
- name: Post prerelease to Slack
173175
if: steps.manifest.outputs.has_packages == 'true'
174176
uses: slackapi/slack-github-action@af78098f536edbc4de71162a307590698245be95 # v3.0.1

integrations/browser-js/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"license": "Apache-2.0",
5151
"publishConfig": {
5252
"access": "public",
53-
"registry": "https://registry.npmjs.org/"
53+
"registry": "https://registry.npmjs.org/",
54+
"provenance": true
5455
}
5556
}

integrations/langchain-js/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"homepage": "https://www.braintrust.dev/docs",
5959
"publishConfig": {
6060
"access": "public",
61-
"registry": "https://registry.npmjs.org/"
61+
"registry": "https://registry.npmjs.org/",
62+
"provenance": true
6263
}
6364
}

integrations/openai-agents-js/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"homepage": "https://www.braintrust.dev/docs",
4646
"publishConfig": {
4747
"access": "public",
48-
"registry": "https://registry.npmjs.org/"
48+
"registry": "https://registry.npmjs.org/",
49+
"provenance": true
4950
}
5051
}

integrations/otel-js/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"homepage": "https://www.braintrust.dev/docs",
6565
"publishConfig": {
6666
"access": "public",
67-
"registry": "https://registry.npmjs.org/"
67+
"registry": "https://registry.npmjs.org/",
68+
"provenance": true
6869
}
6970
}

integrations/templates-nunjucks/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"homepage": "https://www.braintrust.dev/docs",
4949
"publishConfig": {
5050
"access": "public",
51-
"registry": "https://registry.npmjs.org/"
51+
"registry": "https://registry.npmjs.org/",
52+
"provenance": true
5253
}
5354
}

integrations/temporal-js/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"homepage": "https://www.braintrust.dev/docs",
7878
"publishConfig": {
7979
"access": "public",
80-
"registry": "https://registry.npmjs.org/"
80+
"registry": "https://registry.npmjs.org/",
81+
"provenance": true
8182
}
8283
}

integrations/vercel-ai-sdk/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"homepage": "https://www.braintrust.dev/docs",
4646
"publishConfig": {
4747
"access": "public",
48-
"registry": "https://registry.npmjs.org/"
48+
"registry": "https://registry.npmjs.org/",
49+
"provenance": true
4950
}
5051
}

js/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@
232232
},
233233
"publishConfig": {
234234
"access": "public",
235-
"registry": "https://registry.npmjs.org/"
235+
"registry": "https://registry.npmjs.org/",
236+
"provenance": true
236237
}
237238
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import { execFileSync } from "node:child_process";
2+
import { readFileSync } from "node:fs";
3+
4+
import { parseArgs, readPackage, repoPath } from "./_shared.mjs";
5+
6+
const args = parseArgs();
7+
const manifestPath = args.manifest ?? ".release-manifest.json";
8+
const npmTag = args.tag;
9+
10+
const manifest = JSON.parse(readFileSync(repoPath(manifestPath), "utf8"));
11+
const packages = orderPackagesForPublish(manifest.packages ?? []);
12+
13+
if (packages.length === 0) {
14+
console.log(`No packages to publish from ${manifestPath}.`);
15+
process.exit(0);
16+
}
17+
18+
for (const pkg of packages) {
19+
const packageDir = repoPath(pkg.dir);
20+
const packageJson = readPackage(pkg.dir);
21+
const publishArgs = ["publish"];
22+
23+
if (packageJson.publishConfig?.access) {
24+
publishArgs.push("--access", packageJson.publishConfig.access);
25+
}
26+
27+
if (npmTag) {
28+
publishArgs.push("--tag", npmTag);
29+
}
30+
31+
console.log(
32+
`Publishing ${packageJson.name}@${packageJson.version} from ${pkg.dir} with npm`,
33+
);
34+
35+
execFileSync("npm", publishArgs, {
36+
cwd: packageDir,
37+
stdio: "inherit",
38+
});
39+
}
40+
41+
function orderPackagesForPublish(packages) {
42+
const packageMap = new Map(
43+
packages.map((pkg) => [
44+
pkg.name,
45+
{ ...pkg, manifest: readPackage(pkg.dir) },
46+
]),
47+
);
48+
const visiting = new Set();
49+
const visited = new Set();
50+
const ordered = [];
51+
52+
for (const pkg of packageMap.values()) {
53+
visit(pkg);
54+
}
55+
56+
return ordered.map(({ manifest: _manifest, ...pkg }) => pkg);
57+
58+
function visit(pkg) {
59+
if (visited.has(pkg.name)) {
60+
return;
61+
}
62+
63+
if (visiting.has(pkg.name)) {
64+
throw new Error(
65+
`Detected a publish dependency cycle involving ${pkg.name}`,
66+
);
67+
}
68+
69+
visiting.add(pkg.name);
70+
71+
for (const dependencyName of getWorkspaceReleaseDependencies(
72+
pkg.manifest,
73+
)) {
74+
const dependency = packageMap.get(dependencyName);
75+
if (dependency) {
76+
visit(dependency);
77+
}
78+
}
79+
80+
visiting.delete(pkg.name);
81+
visited.add(pkg.name);
82+
ordered.push(pkg);
83+
}
84+
}
85+
86+
function getWorkspaceReleaseDependencies(manifest) {
87+
const dependencyNames = new Set();
88+
89+
for (const field of [
90+
"dependencies",
91+
"optionalDependencies",
92+
"peerDependencies",
93+
"devDependencies",
94+
]) {
95+
for (const dependencyName of Object.keys(manifest[field] ?? {})) {
96+
dependencyNames.add(dependencyName);
97+
}
98+
}
99+
100+
dependencyNames.delete(manifest.name);
101+
return dependencyNames;
102+
}

0 commit comments

Comments
 (0)