OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security
TypeScript ai-securityapplication-securityclicode-scanningcodexcodex-securitycybersecuritydevsecopsnodejsnpmopenaisdksecuritytypescriptvulnerability-scanning
refactor(release): resolve history in the GitHub publisher (#2475)
Michael D'Angelo5b1e8a53de5e
diff --git a/.github/workflows/node-github-release.yml b/.github/workflows/node-github-release.ymlindex 101c7c3a1..20bdc51b3 100644--- a/.github/workflows/node-github-release.yml+++ b/.github/workflows/node-github-release.yml@@ -405,68 +405,6 @@ jobs:compression-level: 0retention-days: 7- - name: Resolve published release history- id: history- shell: bash- env:- GH_TOKEN: ${{ github.token }}- RELEASE_TAG: ${{ steps.release.outputs.tag }}- RELEASE_SHA: ${{ steps.release.outputs.sha }}- run: |- set -euo pipefail-- published_versions="$(- npm view @openai/codex-security versions \- --json \- --registry=https://registry.npmjs.org/- )"- published_github_tags="$(- gh api --paginate \- "repos/$GITHUB_REPOSITORY/releases?per_page=100" \- --jq '.[] | select(.draft == false and .prerelease == false) | .tag_name'- )"- reachable_tags=""- if git rev-parse "$RELEASE_SHA^" >/dev/null 2>&1; then- reachable_tags="$(- git tag --merged "$RELEASE_SHA^" \- --list 'npm-v*' \- --sort=-version:refname- )"- fi-- history="$(- CODEX_SECURITY_PUBLISHED_NPM_VERSIONS="$published_versions" \- CODEX_SECURITY_PUBLISHED_GITHUB_TAGS="$published_github_tags" \- CODEX_SECURITY_REACHABLE_RELEASE_TAGS="$reachable_tags" \- node sdk/typescript/scripts/release-automation.mjs \- release-history "$RELEASE_TAG"- )"-- previous_tag="$(- printf '%s\n' "$history" |- node --input-type=module --eval '- import { readFileSync } from "node:fs";- const history = JSON.parse(readFileSync(0, "utf8"));- process.stdout.write(history.previousTag ?? "");- '- )"- make_latest="$(- printf '%s\n' "$history" |- node --input-type=module --eval '- import { readFileSync } from "node:fs";- const history = JSON.parse(readFileSync(0, "utf8"));- if (typeof history.makeLatest !== "boolean") {- throw new Error("Release latest status must be explicit.");- }- process.stdout.write(String(history.makeLatest));- '- )"-- {- printf 'previous-tag=%s\n' "$previous_tag"- printf 'make-latest=%s\n' "$make_latest"- } >> "$GITHUB_OUTPUT"-- name: Publish GitHub Release and generated notesshell: bashenv:@@ -475,8 +413,6 @@ jobs:RELEASE_VERSION: ${{ steps.release.outputs.version }}RELEASE_SHA: ${{ steps.release.outputs.sha }}RELEASE_ARCHIVE: ${{ steps.artifact.outputs.archive }}- PREVIOUS_TAG: ${{ steps.history.outputs.previous-tag }}- MAKE_LATEST: ${{ steps.history.outputs.make-latest }}run: |set -euo pipefailrelease_workspace="$(mktemp -d)"diff --git a/sdk/typescript/scripts/publish-github-release.mjs b/sdk/typescript/scripts/publish-github-release.mjsindex 3e30efcc2..79e693a37 100644--- a/sdk/typescript/scripts/publish-github-release.mjs+++ b/sdk/typescript/scripts/publish-github-release.mjs@@ -4,6 +4,7 @@ import { constants } from "node:os";import { basename, join } from "node:path";import {composeReleaseNotes,+ releaseHistory,resolveReleaseSummary,verifyGitHubRelease,} from "./release-automation.mjs";@@ -60,10 +61,45 @@ export function publishGitHubRelease(env, workspace, run = runCommand) {RELEASE_VERSION: version,RELEASE_SHA: sha,RELEASE_ARCHIVE: archive,- PREVIOUS_TAG: previousTag,- MAKE_LATEST: makeLatest,} = env;const base = `repos/${repository}`;+ const npmVersions = output(+ run("npm", [+ "view",+ "@openai/codex-security",+ "versions",+ "--json",+ "--registry=https://registry.npmjs.org/",+ ]),+ );+ const publishedTags = output(+ run("gh", [+ "api",+ "--paginate",+ `${base}/releases?per_page=100`,+ "--jq",+ ".[] | select(.draft == false and .prerelease == false) | .tag_name",+ ]),+ );+ const parent = `${sha}^`;+ let reachableTags = [];+ if (run("git", ["rev-parse", parent], "ignore", "ignore").status === 0) {+ reachableTags = output(+ run("git", [+ "tag",+ "--merged",+ parent,+ "--list",+ "npm-v*",+ "--sort=-version:refname",+ ]),+ ).split("\n");+ }+ const { previousTag, makeLatest } = releaseHistory(tag, {+ registryVersions: JSON.parse(npmVersions),+ githubReleaseTags: publishedTags.split("\n"),+ reachableTags,+ });const release = (action, args, assets = []) => {const result = run("gh",@@ -179,7 +215,7 @@ export function publishGitHubRelease(env, workspace, run = runCommand) {(typeof latest.tag_name !== "string" || latest.tag_name.length === 0))throw new Error("Unable to resolve the current Latest GitHub Release.");- const currentlyLatest = String(latest?.tag_name === tag);+ const currentlyLatest = latest?.tag_name === tag;const notesChanged = !Buffer.from(existingNotes).equals(Buffer.from(notes));if (notesChanged || currentlyLatest !== makeLatest) {const args = [`--latest=${makeLatest}`];diff --git a/sdk/typescript/scripts/release-automation.mjs b/sdk/typescript/scripts/release-automation.mjsindex b661e28b9..1b821c65f 100644--- a/sdk/typescript/scripts/release-automation.mjs+++ b/sdk/typescript/scripts/release-automation.mjs@@ -894,32 +894,6 @@ function main() {return;}- if (command === "release-history" && process.argv.length === 4) {- const registryVersions = JSON.parse(- process.env.CODEX_SECURITY_PUBLISHED_NPM_VERSIONS ?? "[]",- );- const githubReleaseTags = (- process.env.CODEX_SECURITY_PUBLISHED_GITHUB_TAGS ?? ""- )- .split("\n")- .filter(Boolean);- const reachableTags = (- process.env.CODEX_SECURITY_REACHABLE_RELEASE_TAGS ?? ""- )- .split("\n")- .filter(Boolean);- console.log(- JSON.stringify(- releaseHistory(process.argv[3], {- registryVersions,- githubReleaseTags,- reachableTags,- }),- ),- );- return;- }-if ((command === "verify-publication" && process.argv.length === 6) ||(command === "verify-github-publication" && process.argv.length === 8) ||@@ -961,7 +935,6 @@ function main() {"(published npm versions JSON from stdin), " +"release-mode <version> (published npm versions JSON from stdin), " +"validate-release-notes <version> <release-notes-file>, " +- "release-history <tag>, " +"verify-publication <archive> <version> <git-head> " +"(package metadata JSON from stdin), " +"verify-github-publication <archive> <version> <git-head> " +diff --git a/sdk/typescript/tests-ts/release-automation.test.ts b/sdk/typescript/tests-ts/release-automation.test.tsindex a654f6e03..1ea0ed029 100644--- a/sdk/typescript/tests-ts/release-automation.test.ts+++ b/sdk/typescript/tests-ts/release-automation.test.ts@@ -122,15 +122,45 @@ function runPublisher({RELEASE_VERSION: "0.1.2",RELEASE_SHA: releaseCommit,RELEASE_ARCHIVE: archivePath,- PREVIOUS_TAG: "npm-v0.1.1",- MAKE_LATEST: String(makeLatest),},workspace,(program: string, args: string[]) => {calls.push([program, ...args]);+ if (program === "npm") {+ expect(args).toEqual([+ "view",+ "@openai/codex-security",+ "versions",+ "--json",+ "--registry=https://registry.npmjs.org/",+ ]);+ return {+ status: 0,+ stdout: JSON.stringify(makeLatest ? ["0.1.2"] : ["0.1.2", "0.1.3"]),+ };+ }+ if (program === "git" && args[0] === "rev-parse")+ return { status: 0, stdout: "" };+ if (program === "git" && args[0] === "tag") {+ expect(args).toEqual([+ "tag",+ "--merged",+ `${releaseCommit}^`,+ "--list",+ "npm-v*",+ "--sort=-version:refname",+ ]);+ return { status: 0, stdout: "npm-v0.1.1\nnpm-v0.1.0\n" };+ }const endpoint = args.find((argument) => argument.startsWith("repos/"));if (program === "gh" && args[0] === "api") {switch (endpoint) {+ case "repos/test/codex-security/releases?per_page=100":+ expect(args).toContain("--paginate");+ expect(args).toContain(+ ".[] | select(.draft == false and .prerelease == false) | .tag_name",+ );+ return { status: 0, stdout: "npm-v0.1.1\n" };case "repos/test/codex-security/releases/tags/npm-v0.1.2":return existingLookup !== "existing"? lookup(existingLookup)@@ -3130,8 +3160,10 @@ ${workflowStepShell(releaseCutWorkflow, "Resolve the stable package version")}import { syncBuiltinESMExports } from "node:module";import { readFileSync, writeFileSync } from "node:fs";childProcess.spawnSync = (program, args, options) => {+ if (program === "npm") return { status: 0, stdout: '["0.1.2","0.1.3"]' };if (program === "git") return { status: 1, stdout: "" };if (program !== "gh") throw new Error("Unexpected command: " + program);+ if (args.includes("repos/test/codex-security/releases?per_page=100")) return { status: 0, stdout: "" };if (args.includes("repos/test/codex-security/releases/tags/npm-v0.1.2")) {return { status: 1, stdout: 'HTTP/2.0 404 Not Found\\n\\n{"message":"Not Found"}' };}@@ -3167,8 +3199,6 @@ ${workflowStepShell(releaseCutWorkflow, "Resolve the stable package version")}RELEASE_VERSION: "0.1.2",RELEASE_SHA: releaseCommit,RELEASE_ARCHIVE: join(workspace, "verified archive.tgz"),- PREVIOUS_TAG: "",- MAKE_LATEST: "false",},{ cwd: fileURLToPath(new URL("../../../", import.meta.url)) },);@@ -3186,7 +3216,6 @@ ${workflowStepShell(releaseCutWorkflow, "Resolve the stable package version")}const result = runPublisher({ existingLookup: "missing" });expect(result.status).toBe(0);expect(result.calls.at(-1)).toContain("--latest=false");- expect(githubReleaseWorkflow).toContain("release-history");});test.each(["", "not-json"])(@@ -3209,12 +3238,6 @@ ${workflowStepShell(releaseCutWorkflow, "Resolve the stable package version")});test("generates notes only from a previously published release", () => {- expect(githubReleaseWorkflow).toContain(- "npm view @openai/codex-security versions",- );- expect(githubReleaseWorkflow).toContain(- "steps.history.outputs.previous-tag",- );const result = runPublisher({ existingLookup: "missing" });expect(result.calls.find((call) =>@@ -3240,6 +3263,10 @@ ${workflowStepShell(releaseCutWorkflow, "Resolve the stable package version")}"Existing GitHub Release asset must match the verified npm artifact.",);expect(result.calls.map((call) => call.slice(0, 3))).toEqual([+ ["npm", "view", "@openai/codex-security"],+ ["gh", "api", "--paginate"],+ ["git", "rev-parse", `${releaseCommit}^`],+ ["git", "tag", "--merged"],["gh", "api", "--include"],["gh", "release", "download"],]);