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
fix(release): refresh the standalone workflow CLI pin (#1683)
Michael D'Angelobb8076c52e60
diff --git a/RELEASING.md b/RELEASING.mdindex 608c6d6f2..589777b7e 100644--- a/RELEASING.md+++ b/RELEASING.md@@ -117,6 +117,12 @@ updates that pin and lockfile to the verified publication. This lets releasePRs run CI while the next npm version is still unavailable; `node-ci` alsotests the Action against the packed CLI candidate before publication.+The standalone workflow in `examples/github-actions/codex-security.yml` also+pins `CODEX_SECURITY_VERSION` to the proposed release version. Only that value+changes; other workflow content comes from the latest `main`. After the release+PR merges, this example can reference the new version before npm publication+finishes. Wait for publication before using that pin.+If a run reports that GitHub has not exposed the updated PR head, manuallyrerun the updater with **dry_run** disabled after the PR catches up. Thisallows any deferred review request or note suggestions to be posted. Verify@@ -136,8 +142,9 @@ pauses updates; restore its `main` base before resuming. Both ready proposalsand existing drafts receive updates. Existing drafts can be marked readywithout pausing the updater. Review the current head before merging if`main` has advanced. The updater rechecks pause conditions before advancing-the branch. Changes to other files on the release branch, or to package-fields other than the version, also pause the+the branch. Changes to other files on the release branch, to package+fields other than the version, or to the standalone example beyond its CLI+version also pause theupdater so those edits cannot be lost. These intentional pauses return`action: "held"` and leave the workflow successful. Preserve or merge theadditional changes, then rerun the updater to resume.diff --git a/sdk/typescript/scripts/release-pr.mjs b/sdk/typescript/scripts/release-pr.mjsindex 15ab07d1b..faa2193c6 100644--- a/sdk/typescript/scripts/release-pr.mjs+++ b/sdk/typescript/scripts/release-pr.mjs@@ -10,6 +10,7 @@ import { isMain } from "./is-main.mjs";export const packagePath = "sdk/typescript/package.json";export const actionPackagePath = "github-action/package.json";export const actionLockPath = "github-action/package-lock.json";+export const exampleWorkflowPath = "examples/github-actions/codex-security.yml";export const notesPath = ".github/release-notes.md";export const statePath = ".github/release-pr-state.json";const packagePaths = [packagePath, actionPackagePath, actionLockPath];@@ -17,6 +18,8 @@ const templatePath = ".github/PULL_REQUEST_TEMPLATE.md";const sectionIds = ["highlights", "upgrades"];const releaseBranchPrefix = "release/next-";const conventionalTitle = /^([a-z][a-z0-9-]*)(?:\(([^)]*)\))?(!)?: (.+)$/u;+const exampleVersionPattern =+ /^([ \t]*CODEX_SECURITY_VERSION:[ \t]*)(["']?)[0-9]+\.[0-9]+\.[0-9]+\2(?=[ \t]*(?:#[^\r\n]*)?\r?$)/gmu;function isReleaseTitle(title) {const [, type, scope] = conventionalTitle.exec(title) ?? [];@@ -185,6 +188,18 @@ function updateActionLockVersion(lockText, version) {return `${JSON.stringify(lock, null, 2)}\n`;}+function updateExampleVersion(exampleText, version) {+ if ([...exampleText.matchAll(exampleVersionPattern)].length !== 1) {+ throw new Error(+ "Unable to update only the GitHub Actions example CLI version.",+ );+ }+ return exampleText.replace(+ exampleVersionPattern,+ (_match, prefix, quote) => `${prefix}${quote}${version}${quote}`,+ );+}+function packageWithoutVersion(text, path) {if (text === null) return null;const metadata = JSON.parse(text);@@ -232,6 +247,12 @@ export function createReleasePlan(history, previous = null) {version,);}+ if (history.exampleWorkflowText != null) {+ files[exampleWorkflowPath] = updateExampleVersion(+ history.exampleWorkflowText,+ version,+ );+ }return {baseVersion,baseCommit,@@ -316,6 +337,7 @@ export async function readReleaseHistory(repo, mainSha, github) {packageText,actionPackageText: repo.readFile(mainSha, actionPackagePath),actionLockText: repo.readFile(mainSha, actionLockPath),+ exampleWorkflowText: repo.readFile(mainSha, exampleWorkflowPath),changes: [...changes.values()],};}@@ -329,7 +351,10 @@ function readReleaseBranch(repo, mainSha, headSha) {.filter(Boolean);if (paths.some(- (path) => ![...packagePaths, notesPath, statePath].includes(path),+ (path) =>+ ![...packagePaths, exampleWorkflowPath, notesPath, statePath].includes(+ path,+ ),)) {return {@@ -353,6 +378,18 @@ function readReleaseBranch(repo, mainSha, headSha) {};}}+ const originalExample = repo+ .readFile(mergeBase, exampleWorkflowPath)+ ?.replace(exampleVersionPattern, "$1$2$2");+ const branchExample = repo+ .readFile(headSha, exampleWorkflowPath)+ ?.replace(exampleVersionPattern, "$1$2$2");+ if (originalExample !== branchExample) {+ return {+ holdReason:+ "The release branch has GitHub Actions example edits beyond its CLI version. Preserve them before running the updater.",+ };+ }const state = JSON.parse(repo.readFile(headSha, statePath));if (!state?.sections) {throw new Error(diff --git a/sdk/typescript/tests-ts/release-pr.test.ts b/sdk/typescript/tests-ts/release-pr.test.tsindex 299cc1731..fe15637b9 100644--- a/sdk/typescript/tests-ts/release-pr.test.ts+++ b/sdk/typescript/tests-ts/release-pr.test.ts@@ -26,11 +26,12 @@ type History = {packageText: string;actionPackageText?: string | null;actionLockText?: string | null;+ exampleWorkflowText?: string | null;changes: Change[];};type Plan = Omit<History,- "packageText" | "actionPackageText" | "actionLockText"+ "packageText" | "actionPackageText" | "actionLockText" | "exampleWorkflowText"> & {version: string;branch: string;@@ -71,6 +72,7 @@ const {packagePath,actionPackagePath,actionLockPath,+ exampleWorkflowPath,notesPath,statePath,isBreakingChange,@@ -84,6 +86,7 @@ const {packagePath: string;actionPackagePath: string;actionLockPath: string;+ exampleWorkflowPath: string;notesPath: string;statePath: string;isBreakingChange: (change: Change) => boolean;@@ -166,6 +169,20 @@ function actionFiles(dependencyVersion = "1.2.3") {};}+function exampleWorkflowText(version = "0.1.23") {+ return [+ "name: Code scan",+ "jobs:",+ " scan:",+ " env:",+ ` CODEX_SECURITY_VERSION: "${version}" # Exact CLI release`,+ ' OTHER_VERSION: "0.1.23"',+ " steps:",+ ' - run: echo "$CODEX_SECURITY_VERSION"',+ "",+ ].join("\n");+}+function change(title: string,number = 1,@@ -1028,6 +1045,51 @@ describe("pre-1.0 release policy", () => {expect(empty.files[packagePath]).toBe(text);},);++ test("updates the checked-in example pin without changing the rest of the workflow", () => {+ const source = readFileSync(+ new URL(`../../../${exampleWorkflowPath}`, import.meta.url),+ "utf8",+ );+ const plan = createReleasePlan({+ ...history([change("fix: repair output")]),+ exampleWorkflowText: source,+ });+ expect(plan.files[exampleWorkflowPath]).toBe(+ source.replace(+ /CODEX_SECURITY_VERSION: "[^"]+"/u,+ 'CODEX_SECURITY_VERSION: "0.1.24"',+ ),+ );+ expect(plan.files[exampleWorkflowPath]).toContain(+ 'CODEX_SECURITY_VERSION: "0.1.24"',+ );+ });++ test("preserves example quotes, CRLF, comments, and unrelated version literals", () => {+ const source = (version: string) =>+ exampleWorkflowText(version)+ .replaceAll('"', "'")+ .replaceAll("\n", "\r\n");+ const plan = createReleasePlan({+ ...history([change("fix: repair output")]),+ exampleWorkflowText: source("0.1.23"),+ });+ expect(plan.files[exampleWorkflowPath]).toBe(source("0.1.24"));+ });++ test.each([+ "name: No CLI pin\n",+ 'env:\n CODEX_SECURITY_VERSION: "latest"\n',+ exampleWorkflowText() + exampleWorkflowText(),+ ])("rejects an example without one exact CLI pin (%#)", (source) => {+ expect(() =>+ createReleasePlan({+ ...history([change("fix: repair output")]),+ exampleWorkflowText: source,+ }),+ ).toThrow("Unable to update only the GitHub Actions example CLI version");+ });});describe("human note ownership", () => {@@ -1167,6 +1229,47 @@ describe("human note ownership", () => {});describe("rolling release reconciliation", () => {+ test("adds and refreshes the example pin from current main without introducing it into earlier history", async () => {+ const fixture = new Fixture();+ fixture.merge("fix: initial fix");+ const beforeExample = await fixture.run();+ expect(beforeExample.plan.files[exampleWorkflowPath]).toBeUndefined();+ expect(+ fixture.repo.readFile(beforeExample.headSha!, exampleWorkflowPath),+ ).toBeNull();++ for (const [title, name, version] of [+ ["docs: add workflow example", "Code scan", "0.1.24"],+ ["docs: clarify workflow name", "Weekly code scan", "0.1.24"],+ ["feat!: change behavior", "Weekly code scan", "0.2.0"],+ ] as const) {+ const source = (pin: string) =>+ exampleWorkflowText(pin).replace("Code scan", name);+ fixture.merge(title, { [exampleWorkflowPath]: source("0.1.23") });+ const result = await fixture.run();+ expect(result.action).toBe("updated");+ expect(result.pull).toBe(beforeExample.pull);+ expect(result.plan.version).toBe(version);+ expect(result.plan.files[exampleWorkflowPath]).toBe(source(version));+ expect(fixture.repo.readFile(result.headSha!, exampleWorkflowPath)).toBe(+ source(version),+ );+ }+ const writes = fixture.github.writes.length;+ expect((await fixture.run()).action).toBe("unchanged");+ expect(fixture.github.writes).toHaveLength(writes);++ fixture.merge("docs: remove workflow example", {+ [exampleWorkflowPath]: null,+ });+ const removed = await fixture.run();+ expect(removed.action).toBe("updated");+ expect(removed.plan.files[exampleWorkflowPath]).toBeUndefined();+ expect(+ fixture.repo.readFile(removed.headSha!, exampleWorkflowPath),+ ).toBeNull();+ });+test("aligns Action metadata when introduced and refreshed without advancing the published runtime pin", async () => {const fixture = new Fixture();fixture.merge("fix: initial fix");@@ -1679,6 +1782,37 @@ describe("rolling release reconciliation", () => {});describe("release proposal pauses", () => {+ test.each(["comment", "formatting", "deletion"] as const)(+ "preserves example workflow %s edits on the release branch",+ async (change) => {+ const fixture = new Fixture();+ fixture.merge("docs: add workflow example", {+ [exampleWorkflowPath]: exampleWorkflowText(),+ });+ const first = await fixture.run();+ const generated = first.plan.files[exampleWorkflowPath]!;+ const edited =+ change === "deletion"+ ? null+ : change === "comment"+ ? generated.replace("Exact CLI release", "Reviewed CLI release")+ : generated.replace('"0.1.24"', "'0.1.24'");+ const humanSha = fixture.commit(+ first.plan.branch,+ { [exampleWorkflowPath]: edited },+ "docs: adjust workflow example",+ );+ fixture.merge("fix: another fix");+ const writes = fixture.github.writes.length;+ const result = await fixture.run();+ expect(result.action).toBe("held");+ expect(result.reason).toContain("example edits beyond its CLI version");+ expect(fixture.head(first.plan.branch)).toBe(humanSha);+ expect(fixture.repo.readFile(humanSha, exampleWorkflowPath)).toBe(edited);+ expect(fixture.github.writes).toHaveLength(writes);+ },+ );+test.each([{ path: actionPackagePath, change: "dependencies" },{ path: actionLockPath, change: "dependencies" },