Skip to content

Open-source, local-first social media research agent for Instagram, TikTok, and LinkedIn. Jev routes read-only steps; socai CLI captures cited browser evidence.

ci: add trusted npm publishing (#114)

Asklv193213e1338f
diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml
new file mode 100644
index 0000000..0f671d0
--- /dev/null
+++ b/.github/workflows/npm-publish.yml
@@ -0,0 +1,65 @@
+name: publish npm
+
+on:
+ release:
+ types: [published]
+
+permissions:
+ contents: read
+
+concurrency:
+ group: npm-publish-${{ github.event.release.tag_name }}
+ cancel-in-progress: false
+
+jobs:
+ verify:
+ if: >-
+ startsWith(github.event.release.tag_name, 'v') &&
+ !github.event.release.prerelease &&
+ github.event.release.immutable == true
+ runs-on: ubuntu-latest
+ timeout-minutes: 20
+ steps:
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ ref: ${{ github.sha }}
+ persist-credentials: false
+ - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
+ with:
+ node-version: 24
+ package-manager-cache: false
+ registry-url: https://registry.npmjs.org/
+ - name: Verify immutable release metadata
+ env:
+ RELEASE_TAG: ${{ github.event.release.tag_name }}
+ run: node scripts/verify-release.js
+ - run: npm ci --ignore-scripts
+ - run: npm run check
+ - run: npm test
+
+ publish:
+ needs: verify
+ runs-on: ubuntu-latest
+ timeout-minutes: 10
+ permissions:
+ contents: read
+ id-token: write
+ environment:
+ name: npm
+ steps:
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ ref: ${{ github.sha }}
+ persist-credentials: false
+ - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
+ with:
+ node-version: 24
+ registry-url: https://registry.npmjs.org/
+ - name: Verify checked-out release commit
+ run: test "$(git rev-parse HEAD)" = "$GITHUB_SHA"
+ - name: Recheck release metadata and publishing toolchain
+ env:
+ RELEASE_TAG: ${{ github.event.release.tag_name }}
+ run: node scripts/verify-release.js
+ - name: Publish verified package
+ run: npm publish --ignore-scripts --provenance --access public
diff --git a/package.json b/package.json
index cba9c9e..00d934c 100644
--- a/package.json
+++ b/package.json
@@ -43,7 +43,7 @@
"dev": "node --watch ./bin/jev-social.js serve --no-open",
"benchmark:run": "node ./benchmark/run.js",
"benchmark:summarize": "node ./benchmark/summary.js",
- "check": "node --check ./bin/jev-social.js && node --check ./benchmark/run.js && node --check ./benchmark/schema.js && node --check ./benchmark/summary.js && node --check ./src/server.js && node --check ./src/decision-provider.js && node --check ./src/evidence.js && node --check ./src/report.js && node --check ./public/app.js && node --check ./public/evidence-items.js && node --check ./public/evidence-preview.js && node --check ./public/run-route.js && node --check ./public/report-download.js && node --check ./public/report-stream.js && node --check ./public/prompts.js && node --check ./public/status.js && node --check ./public/view-focus.js",
+ "check": "node --check ./bin/jev-social.js && node --check ./benchmark/run.js && node --check ./benchmark/schema.js && node --check ./benchmark/summary.js && node --check ./scripts/verify-release.js && node --check ./src/server.js && node --check ./src/decision-provider.js && node --check ./src/evidence.js && node --check ./src/report.js && node --check ./public/app.js && node --check ./public/evidence-items.js && node --check ./public/evidence-preview.js && node --check ./public/run-route.js && node --check ./public/report-download.js && node --check ./public/report-stream.js && node --check ./public/prompts.js && node --check ./public/status.js && node --check ./public/view-focus.js",
"test": "node --test"
},
"engines": {
diff --git a/scripts/verify-release.js b/scripts/verify-release.js
new file mode 100644
index 0000000..591f5ed
--- /dev/null
+++ b/scripts/verify-release.js
@@ -0,0 +1,126 @@
+import { execFileSync } from "node:child_process";
+import { readFile } from "node:fs/promises";
+import { resolve } from "node:path";
+import { fileURLToPath } from "node:url";
+
+const SHA_PATTERN = /^[0-9a-f]{40}$/u;
+const STABLE_SEMVER_PATTERN = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/u;
+
+function requireEqual(actual, expected, message) {
+ if (actual !== expected) throw new Error(`${message}: expected ${expected}, received ${actual}`);
+}
+
+export function verifyNpmVersion(value) {
+ const version = String(value ?? "").trim();
+ const match = STABLE_SEMVER_PATTERN.exec(version);
+ if (!match) throw new Error("npm CLI version must be a stable semantic version");
+ const numbers = match.slice(1, 4).map(Number);
+ const minimum = [11, 5, 1];
+ const supported = numbers.some((number, index) => (
+ number > minimum[index]
+ && numbers.slice(0, index).every((part, prior) => part === minimum[prior])
+ )) || numbers.every((number, index) => number === minimum[index]);
+ if (!supported) throw new Error("trusted publishing requires npm 11.5.1 or newer");
+ return version;
+}
+
+export function verifyReleaseMetadata({
+ packageJson,
+ packageLock,
+ codexManifest,
+ grokManifest,
+ skillContents,
+ releaseTag,
+ eventCommit,
+ checkoutCommit,
+}) {
+ requireEqual(packageJson?.name, "jev-social", "package name must remain jev-social");
+ const version = String(packageJson?.version ?? "").trim();
+ if (!STABLE_SEMVER_PATTERN.test(version)) {
+ throw new Error("package version must be stable semantic versioning");
+ }
+ const expectedTag = `v${version}`;
+ requireEqual(releaseTag, expectedTag, "release tag must equal package version");
+ requireEqual(
+ packageJson?.publishConfig?.registry,
+ "https://registry.npmjs.org/",
+ "publish registry must be the public npm registry",
+ );
+ requireEqual(packageJson?.publishConfig?.access, "public", "package access must remain public");
+ requireEqual(packageLock?.version, version, "package-lock version must equal package version");
+ requireEqual(
+ packageLock?.packages?.[""]?.version,
+ version,
+ "package-lock root version must equal package version",
+ );
+ if (codexManifest?.version !== version || grokManifest?.version !== version) {
+ throw new Error("plugin manifest versions must equal package version");
+ }
+ if (!String(skillContents ?? "").includes(`release \`${expectedTag}\``)) {
+ throw new Error("Agent Skill must identify the release tag");
+ }
+ if (!SHA_PATTERN.test(String(eventCommit ?? ""))) {
+ throw new Error("release event revision must be a full commit SHA");
+ }
+ if (!SHA_PATTERN.test(String(checkoutCommit ?? ""))) {
+ throw new Error("checked-out revision must be a full commit SHA");
+ }
+ requireEqual(
+ checkoutCommit,
+ eventCommit,
+ "checked-out commit must equal the release event commit",
+ );
+ return {
+ commit: checkoutCommit,
+ packageName: packageJson.name,
+ releaseTag,
+ version,
+ };
+}
+
+export async function verifyRelease({
+ root = new URL("../", import.meta.url),
+ env = process.env,
+ checkoutCommit = execFileSync("git", ["rev-parse", "HEAD"], {
+ cwd: root,
+ encoding: "utf8",
+ }).trim(),
+ npmVersion = execFileSync(process.platform === "win32" ? "npm.cmd" : "npm", ["--version"], {
+ encoding: "utf8",
+ }).trim(),
+} = {}) {
+ verifyNpmVersion(npmVersion);
+ const [packageJson, packageLock, codexManifest, grokManifest, skillContents] = await Promise.all([
+ readFile(new URL("package.json", root), "utf8").then(JSON.parse),
+ readFile(new URL("package-lock.json", root), "utf8").then(JSON.parse),
+ readFile(new URL(".codex-plugin/plugin.json", root), "utf8").then(JSON.parse),
+ readFile(new URL(".grok-plugin/plugin.json", root), "utf8").then(JSON.parse),
+ readFile(new URL("skills/jev-social/SKILL.md", root), "utf8"),
+ ]);
+ return verifyReleaseMetadata({
+ packageJson,
+ packageLock,
+ codexManifest,
+ grokManifest,
+ skillContents,
+ releaseTag: env.RELEASE_TAG,
+ eventCommit: env.GITHUB_SHA,
+ checkoutCommit,
+ });
+}
+
+async function main() {
+ try {
+ const result = await verifyRelease();
+ process.stdout.write(
+ `Verified ${result.packageName}@${result.version} at ${result.commit} for ${result.releaseTag}.\n`,
+ );
+ } catch (error) {
+ process.stderr.write(`Release verification failed: ${error.message}\n`);
+ process.exitCode = 1;
+ }
+}
+
+if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
+ await main();
+}
diff --git a/test/npm-publish-workflow.test.js b/test/npm-publish-workflow.test.js
new file mode 100644
index 0000000..9c91f34
--- /dev/null
+++ b/test/npm-publish-workflow.test.js
@@ -0,0 +1,194 @@
+import assert from "node:assert/strict";
+import { execFileSync } from "node:child_process";
+import { mkdtempSync, readFileSync, rmSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import test from "node:test";
+
+import { verifyNpmVersion, verifyReleaseMetadata } from "../scripts/verify-release.js";
+
+const root = new URL("../", import.meta.url);
+const packageJson = JSON.parse(readFileSync(new URL("package.json", root), "utf8"));
+const packageLock = JSON.parse(readFileSync(new URL("package-lock.json", root), "utf8"));
+const codexManifest = JSON.parse(
+ readFileSync(new URL(".codex-plugin/plugin.json", root), "utf8"),
+);
+const grokManifest = JSON.parse(
+ readFileSync(new URL(".grok-plugin/plugin.json", root), "utf8"),
+);
+const skillContents = readFileSync(new URL("skills/jev-social/SKILL.md", root), "utf8");
+const workflow = readFileSync(new URL(".github/workflows/npm-publish.yml", root), "utf8");
+const commit = "a".repeat(40);
+
+function metadata(overrides = {}) {
+ return {
+ packageJson,
+ packageLock,
+ codexManifest,
+ grokManifest,
+ skillContents,
+ releaseTag: `v${packageJson.version}`,
+ eventCommit: commit,
+ checkoutCommit: commit,
+ ...overrides,
+ };
+}
+
+function npmPack() {
+ const cache = mkdtempSync(join(tmpdir(), "jev-social-npm-publish-"));
+ try {
+ const args = ["pack", "--dry-run", "--ignore-scripts", "--json", "--cache", cache];
+ const output = process.env.npm_execpath
+ ? execFileSync(process.execPath, [process.env.npm_execpath, ...args], {
+ cwd: root,
+ encoding: "utf8",
+ })
+ : execFileSync(process.platform === "win32" ? "npm.cmd" : "npm", args, {
+ cwd: root,
+ encoding: "utf8",
+ });
+ return JSON.parse(output)[0];
+ } finally {
+ rmSync(cache, { recursive: true, force: true });
+ }
+}
+
+test("release metadata must identify one immutable package build", () => {
+ assert.deepEqual(verifyReleaseMetadata(metadata()), {
+ commit,
+ packageName: "jev-social",
+ releaseTag: `v${packageJson.version}`,
+ version: packageJson.version,
+ });
+
+ assert.throws(
+ () => verifyReleaseMetadata(metadata({ releaseTag: "v9.9.9" })),
+ /release tag must equal package version/u,
+ );
+ assert.throws(
+ () => verifyReleaseMetadata(metadata({
+ packageJson: { ...packageJson, version: "1.2.3-beta.1" },
+ releaseTag: "v1.2.3-beta.1",
+ })),
+ /package version must be stable semantic versioning/u,
+ );
+ assert.throws(
+ () => verifyReleaseMetadata(metadata({ checkoutCommit: "b".repeat(40) })),
+ /checked-out commit must equal the release event commit/u,
+ );
+ assert.throws(
+ () => verifyReleaseMetadata(metadata({ eventCommit: "b".repeat(40) })),
+ /checked-out commit must equal the release event commit/u,
+ );
+ assert.throws(
+ () => verifyReleaseMetadata(metadata({
+ packageLock: { ...packageLock, version: "9.9.9" },
+ })),
+ /package-lock version must equal package version/u,
+ );
+ assert.throws(
+ () => verifyReleaseMetadata(metadata({
+ codexManifest: { ...codexManifest, version: "9.9.9" },
+ })),
+ /plugin manifest versions must equal package version/u,
+ );
+});
+
+test("trusted publishing requires an OIDC-capable npm CLI", () => {
+ assert.equal(verifyNpmVersion("11.5.1"), "11.5.1");
+ assert.equal(verifyNpmVersion("12.0.0"), "12.0.0");
+ assert.throws(() => verifyNpmVersion("11.5.0"), /npm 11\.5\.1 or newer/u);
+ assert.throws(() => verifyNpmVersion("10.9.9"), /npm 11\.5\.1 or newer/u);
+ assert.throws(() => verifyNpmVersion("11.5.1-beta.0"), /stable semantic version/u);
+ assert.throws(() => verifyNpmVersion("latest"), /stable semantic version/u);
+});
+
+test("npm publishing uses a release-only OIDC workflow without a registry token", () => {
+ assert.match(workflow, /^on:\n release:\n types: \[published\]/mu);
+ assert.match(workflow, /permissions:\n contents: read\n/u);
+ assert.match(workflow, /github\.event\.release\.immutable == true/u);
+ assert.match(workflow, /verify:[\s\S]+publish:\n needs: verify/u);
+ assert.match(workflow, /environment:\n name: npm/u);
+ assert.match(workflow, /actions\/checkout@[0-9a-f]{40} # v7\.0\.1/u);
+ assert.match(workflow, /persist-credentials: false/u);
+ assert.equal(workflow.match(/ref: \$\{\{ github\.sha \}\}/gu)?.length, 2);
+ assert.match(workflow, /actions\/setup-node@[0-9a-f]{40} # v7\.0\.0/u);
+ assert.match(workflow, /node-version: 24/u);
+ assert.match(workflow, /package-manager-cache: false/u);
+ assert.match(workflow, /registry-url: https:\/\/registry\.npmjs\.org/u);
+ assert.match(workflow, /RELEASE_TAG: \$\{\{ github\.event\.release\.tag_name \}\}/u);
+ assert.equal(workflow.match(/run: node scripts\/verify-release\.js/gu)?.length, 2);
+ assert.match(workflow, /npm ci --ignore-scripts/u);
+ assert.match(workflow, /npm run check/u);
+ assert.match(workflow, /npm test/u);
+ assert.match(workflow, /permissions:\n contents: read\n id-token: write/u);
+ assert.match(workflow, /npm publish --ignore-scripts --provenance --access public/u);
+ assert.doesNotMatch(workflow, /NPM_TOKEN|NODE_AUTH_TOKEN|secrets\./u);
+ assert.doesNotMatch(workflow, /workflow_dispatch/u);
+
+ const verifyPosition = workflow.indexOf("run: node scripts/verify-release.js");
+ const installPosition = workflow.indexOf("run: npm ci --ignore-scripts");
+ const publishVerifyPosition = workflow.lastIndexOf("run: node scripts/verify-release.js");
+ const publishPosition = workflow.indexOf("run: npm publish --ignore-scripts");
+ assert.ok(verifyPosition > -1 && verifyPosition < installPosition);
+ assert.ok(installPosition < publishPosition);
+ assert.ok(publishVerifyPosition > installPosition && publishVerifyPosition < publishPosition);
+});
+
+test("the npm tarball has one reviewed file set and no bundled dependencies", () => {
+ const packed = npmPack();
+ const files = packed.files.map(({ path }) => path);
+
+ assert.equal(packed.name, "jev-social");
+ assert.equal(packed.version, packageJson.version);
+ assert.deepEqual(packed.bundled, []);
+ assert.deepEqual(files, [
+ "LICENSE",
+ "README.md",
+ "benchmark/fixtures/valid-row.json",
+ "benchmark/README.md",
+ "benchmark/run.js",
+ "benchmark/schema.js",
+ "benchmark/summary.js",
+ "benchmark/tasks/instagram.json",
+ "benchmark/tasks/linkedin.json",
+ "benchmark/tasks/tiktok.json",
+ "bin/jev-social.js",
+ "docs/troubleshooting.md",
+ "package.json",
+ "public/app.js",
+ "public/evidence-items.js",
+ "public/evidence-preview.js",
+ "public/index.html",
+ "public/platforms/instagram.png",
+ "public/platforms/linkedin.svg",
+ "public/platforms/tiktok.png",
+ "public/prompts.js",
+ "public/report-download.js",
+ "public/report-stream.js",
+ "public/run-route.js",
+ "public/status.js",
+ "public/styles.css",
+ "public/view-focus.js",
+ "skills/jev-social/agents/openai.yaml",
+ "skills/jev-social/SKILL.md",
+ "src/actions.js",
+ "src/app.js",
+ "src/classifier.js",
+ "src/config.js",
+ "src/decision-provider.js",
+ "src/env.js",
+ "src/errors.js",
+ "src/evidence.js",
+ "src/index.js",
+ "src/onboard.js",
+ "src/process.js",
+ "src/query.js",
+ "src/report.js",
+ "src/runs.js",
+ "src/server.js",
+ "src/socai.js",
+ ]);
+ assert.ok(files.every((path) => !path.startsWith("/") && !path.includes("..")));
+ assert.ok(files.every((path) => !/(?:^|\/)(?:\.env(?:[./]|$)|\.git(?:\/|$)|\.github(?:\/|$)|runs?(?:\/|$)|cookies?(?:\/|$))/iu.test(path)));
+});