Skip to content

Commit 1bf3280

Browse files
authored
ci(release): migrate npm publishing to OIDC (#1914)
* ci(release): migrate npm publishing to OIDC * fix(ci): remove stale website package filters
1 parent bc3191e commit 1bf3280

5 files changed

Lines changed: 68 additions & 7 deletions

File tree

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ jobs:
4646
npx turbo build \
4747
--only \
4848
--concurrency=4 \
49-
--filter='!@rivet-dev/agentos-website' \
5049
--filter='!@agentos-software/codex' \
5150
--filter='!@rivet-dev/agentos-browser' \
5251
--filter='!@rivet-dev/agentos-runtime-browser' \

.github/workflows/publish.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ jobs:
248248
name: Publish npm
249249
if: ${{ !cancelled() && needs.wasm-commands.result == 'success' && needs.codex-wasm.result == 'success' && needs.build-sidecar.result == 'success' && needs.build-sidecar-darwin.result == 'success' }}
250250
runs-on: ubuntu-latest
251+
permissions:
252+
contents: read
253+
id-token: write
251254
steps:
252255
- uses: actions/checkout@v4
253256
- uses: pnpm/action-setup@v4
@@ -257,7 +260,7 @@ jobs:
257260
cache: pnpm
258261
cache-dependency-path: pnpm-lock.yaml
259262
registry-url: https://registry.npmjs.org
260-
- run: pnpm install --frozen-lockfile --filter='!@rivet-dev/agentos-website'
263+
- run: pnpm install --frozen-lockfile
261264
- uses: actions/download-artifact@v4
262265
with:
263266
name: wasm-commands
@@ -307,7 +310,6 @@ jobs:
307310
# Browser support is retained in-tree but intentionally disabled until
308311
# it has a reactor/security design independent of the native sidecar.
309312
npx turbo build \
310-
--filter='!@rivet-dev/agentos-website' \
311313
--filter='!@rivet-dev/agentos-browser' \
312314
--filter='!@rivet-dev/agentos-runtime-browser' \
313315
--filter='!@rivet-dev/agentos-playground' \
@@ -319,7 +321,7 @@ jobs:
319321
--version ${{ needs.context.outputs.version }}
320322
- name: Publish npm packages
321323
env:
322-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
324+
NODE_AUTH_TOKEN: ""
323325
run: |
324326
pnpm --filter=publish exec tsx src/ci/bin.ts publish-npm \
325327
--tag ${{ needs.context.outputs.npm_tag }} \
@@ -433,7 +435,7 @@ jobs:
433435
key: ${{ runner.os }}-x86_64-unknown-linux-gnu-rusty-v8-${{ hashFiles('Cargo.lock') }}
434436
restore-keys: |
435437
${{ runner.os }}-x86_64-unknown-linux-gnu-rusty-v8-
436-
- run: pnpm install --frozen-lockfile --filter='!@rivet-dev/agentos-website'
438+
- run: pnpm install --frozen-lockfile
437439
- name: Bump Cargo versions
438440
run: |
439441
pnpm --filter=publish exec tsx src/ci/bin.ts bump-versions \

scripts/publish/src/ci/bin.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ program
147147
"--version-only",
148148
"Only rewrite version fields without publish-time dependency injection",
149149
)
150+
.option(
151+
"--repository <owner/repo>",
152+
"GitHub repository recorded in publish-time package metadata (defaults to GITHUB_REPOSITORY)",
153+
)
150154
.option("--dry-run", "Do not write, only report")
151155
.action(async (opts) => {
152156
const repoRoot = findRepoRoot();
@@ -155,6 +159,7 @@ program
155159
await bumpPackageJsons(repoRoot, version, {
156160
dryRun: !!opts.dryRun,
157161
versionOnly: !!opts.versionOnly,
162+
repository: opts.repository ?? process.env.GITHUB_REPOSITORY,
158163
});
159164
await bumpCargoVersions(repoRoot, version, { dryRun: !!opts.dryRun });
160165
});

scripts/publish/src/lib/version.test.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import { tmpdir } from "node:os";
44
import { join } from "node:path";
55
import test from "node:test";
66
import { DEFAULT_SIDECAR_PLATFORMS } from "./packages.js";
7-
import { bumpCargoVersions, bumpPackageJsons } from "./version.js";
7+
import {
8+
bumpCargoVersions,
9+
bumpPackageJsons,
10+
githubRepositoryUrl,
11+
} from "./version.js";
812

913
async function writeJson(root: string, rel: string, value: unknown) {
1014
const path = join(root, rel);
@@ -105,7 +109,9 @@ test("bumpPackageJsons injects sidecar platform optional dependencies", async ()
105109
});
106110
}
107111

108-
await bumpPackageJsons(repoRoot, "0.3.0");
112+
await bumpPackageJsons(repoRoot, "0.3.0", {
113+
repository: "rivet-dev/agentos",
114+
});
109115

110116
const sidecarManifest = JSON.parse(
111117
await readFile(
@@ -129,6 +135,11 @@ test("bumpPackageJsons injects sidecar platform optional dependencies", async ()
129135
"utf8",
130136
),
131137
);
138+
assert.deepEqual(sidecarManifest.repository, {
139+
type: "git",
140+
url: "https://github.com/rivet-dev/agentos.git",
141+
directory: "packages/sidecar-binary",
142+
});
132143
assert.deepEqual(
133144
runtimeSidecarManifest.optionalDependencies,
134145
Object.fromEntries(
@@ -178,6 +189,7 @@ test("bumpPackageJsons pins lockstep and independent AgentOS Apps runtimes", asy
178189
}
179190

180191
await bumpPackageJsons(repoRoot, "0.0.0-preview.abc1234", {
192+
repository: "rivet-dev/agentos",
181193
resolveNpmLatestVersion: async (name) => {
182194
assert.equal(name, "@agentos-software/tar");
183195
return "0.3.5";
@@ -199,3 +211,15 @@ test("bumpPackageJsons pins lockstep and independent AgentOS Apps runtimes", asy
199211
await rm(repoRoot, { recursive: true, force: true });
200212
}
201213
});
214+
215+
test("githubRepositoryUrl validates owner/repo slugs", () => {
216+
assert.equal(
217+
githubRepositoryUrl("rivet-dev/agentos"),
218+
"https://github.com/rivet-dev/agentos.git",
219+
);
220+
assert.throws(() => githubRepositoryUrl("rivet-dev"), /expected owner\/repo/);
221+
assert.throws(
222+
() => githubRepositoryUrl("https://github.com/rivet-dev/agentos"),
223+
/expected owner\/repo/,
224+
);
225+
});

scripts/publish/src/lib/version.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ const log = scoped("version");
2828
interface PackageJson {
2929
name?: string;
3030
version?: string;
31+
repository?: {
32+
type: "git";
33+
url: string;
34+
directory: string;
35+
};
3136
dependencies?: Record<string, string>;
3237
devDependencies?: Record<string, string>;
3338
peerDependencies?: Record<string, string>;
@@ -97,6 +102,26 @@ export interface BumpOptions {
97102
* the publish-time mode used by CI — never committed.
98103
*/
99104
versionOnly?: boolean;
105+
/** GitHub repository slug recorded in publish-time package metadata. */
106+
repository?: string;
107+
}
108+
109+
export function githubRepositoryUrl(repository: string): string {
110+
if (!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(repository)) {
111+
throw new Error(
112+
`invalid GitHub repository ${JSON.stringify(repository)}; expected owner/repo`,
113+
);
114+
}
115+
return `https://github.com/${repository}.git`;
116+
}
117+
118+
function requirePublishRepository(repository: string | undefined): string {
119+
if (!repository) {
120+
throw new Error(
121+
"publish-time package metadata requires a GitHub repository",
122+
);
123+
}
124+
return repository;
100125
}
101126

102127
/**
@@ -171,6 +196,12 @@ export async function bumpPackageJsons(
171196
pkgJson.version = version;
172197

173198
if (!versionOnly) {
199+
pkgJson.repository = {
200+
type: "git",
201+
url: githubRepositoryUrl(requirePublishRepository(opts.repository)),
202+
directory: pkg.relDir,
203+
};
204+
174205
// Inject optionalDependencies on meta packages so end users get the
175206
// correct platform-specific binary via npm's os/cpu/libc resolution.
176207
const platformPkgs = metaPlatformMap.get(pkg.name);

0 commit comments

Comments
 (0)