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
ci(release): skip unrelated progress updates before checkout (#1896)
Michael D'Angelodb18c769acec
diff --git a/.github/workflows/release-progress.yml b/.github/workflows/release-progress.ymlindex 1b377e704..925c0b68f 100644--- a/.github/workflows/release-progress.yml+++ b/.github/workflows/release-progress.yml@@ -3,7 +3,7 @@ name: release-progresson:workflow_run:workflows: ["node-ci", "node-release", "node-github-release"]- types: [requested, in_progress, completed]+ types: [in_progress, completed]workflow_dispatch:inputs:run-id:@@ -17,20 +17,73 @@ on:permissions: {}+concurrency:+ # Refreshes read the latest upstream state, so only one pending refresh is needed.+ # Observers must not hold that slot while their upstream run awaits approval.+ group: release-progress-${{ inputs.run-id || github.event.workflow_run.id }}-${{ (inputs.watch || (github.event.action == 'in_progress' && github.event.workflow_run.name != 'node-ci')) && github.run_id || 'refresh' }}+ cancel-in-progress: false+jobs:- report:+ identify:if: >-github.repository == 'openai/codex-security' &&(github.event_name != 'workflow_dispatch' || github.ref == 'refs/heads/main') &&(github.event_name != 'workflow_run' ||github.event.workflow_run.name != 'node-ci' ||- (github.event.workflow_run.event == 'push' &&+ (github.event.action == 'completed' &&+ github.event.workflow_run.event == 'push' &&github.event.workflow_run.head_branch == 'main'))+ name: identify release+ runs-on: ubuntu-latest+ continue-on-error: true+ outputs:+ version: ${{ steps.release.outputs.version }}+ permissions:+ actions: read+ contents: read+ pull-requests: read+ steps:+ - name: Select release before checkout+ id: release+ env:+ GH_TOKEN: ${{ github.token }}+ RELEASE_RUN_ID: ${{ inputs.run-id }}+ shell: node {0}+ run: |+ const { execFileSync } = require("node:child_process");+ const { appendFileSync, readFileSync } = require("node:fs");+ const request = (path, ...options) => JSON.parse(execFileSync("gh", [+ "api", `repos/${process.env.GITHUB_REPOSITORY}/${path}`, ...options,+ ], { encoding: "utf8" }));+ const event = JSON.parse(readFileSync(process.env.GITHUB_EVENT_PATH, "utf8"));+ const run = event.workflow_run ?? request(`actions/runs/${process.env.RELEASE_RUN_ID}`);+ const workflow = run.path?.split("@", 1)[0];+ let version;+ if (workflow === ".github/workflows/node-ci.yml" && run.event === "push" && run.head_branch === "main") {+ const pulls = request(`commits/${run.head_sha}/pulls?per_page=100`, "--paginate", "--slurp").flat();+ for (const pull of pulls) {+ const match = /^(?:chore\(release\)|release(?:\([^)]+\))?)!?: (\d+\.\d+\.\d+)$/u.exec(pull.title);+ if (pull.merged_at && pull.base.ref === "main" && match) {+ version = match[1];+ break;+ }+ }+ } else if (workflow === ".github/workflows/node-release.yml" && ["push", "workflow_dispatch"].includes(run.event)) {+ version = /^npm-v(\d+\.\d+\.\d+)$/u.exec(run.head_branch)?.[1];+ } else if (workflow === ".github/workflows/node-github-release.yml" && run.event === "workflow_dispatch" && run.head_branch === "main") {+ version = /^Publish npm-v(\d+\.\d+\.\d+)$/u.exec(run.display_title)?.[1];+ }+ if (version) appendFileSync(process.env.GITHUB_OUTPUT, `version=${version}\n`);++ report:+ needs: identify+ if: needs.identify.outputs.version != ''name: update release PRruns-on: ubuntu-latestcontinue-on-error: trueconcurrency:- group: release-progress-${{ github.repository }}+ # Different stages update one comment; do not discard a stage's first report.+ group: release-progress-${{ github.repository }}-${{ needs.identify.outputs.version }}queue: maxoutputs:pull: ${{ steps.update.outputs.pull }}@@ -39,8 +92,7 @@ jobs:contents: readpull-requests: writesteps:- - &checkout-automation- name: Checkout trusted release automation+ - name: Checkout trusted release automationuses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1with:ref: refs/heads/main@@ -77,7 +129,11 @@ jobs:actions: writecontents: readsteps:- - *checkout-automation+ - name: Checkout trusted release automation+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1+ with:+ ref: refs/heads/main+ persist-credentials: false- *setup-node- name: Refresh changed milestonesenv:diff --git a/sdk/typescript/tests-ts/release-automation.test.ts b/sdk/typescript/tests-ts/release-automation.test.tsindex 43a16ad74..831261bdc 100644--- a/sdk/typescript/tests-ts/release-automation.test.ts+++ b/sdk/typescript/tests-ts/release-automation.test.ts@@ -2604,8 +2604,9 @@ describe("GitHub release workflow safeguards", () => {ref: "refs/heads/main","persist-credentials": false,});- expect(progress.concurrency).toBeUndefined();+ expect(progress.concurrency?.["cancel-in-progress"]).toBe(false);expect(progress.jobs["report"]?.concurrency?.["queue"]).toBe("max");+ expect(progress.jobs["report"]?.needs).toBe("identify");expect(progress.jobs["watch"]?.permissions).toEqual({actions: "write",contents: "read",@@ -2615,7 +2616,10 @@ describe("GitHub release workflow safeguards", () => {"github.event.action == 'in_progress'",);expect(progress.jobs["watch"]?.if).toContain("inputs.watch");- expect(progress.jobs["watch"]?.steps?.[0]?.with).toEqual(checkout?.with);+ expect(progress.jobs["watch"]?.steps?.[0]?.with).toEqual({+ ref: "refs/heads/main",+ "persist-credentials": false,+ });expect(progress.jobs["watch"]?.steps?.at(-1)?.env?.["RELEASE_PROGRESS_WATCH"],).toBe("true");diff --git a/sdk/typescript/tests-ts/release-progress-workflow.test.ts b/sdk/typescript/tests-ts/release-progress-workflow.test.tsnew file mode 100644index 000000000..9b6694c4b--- /dev/null+++ b/sdk/typescript/tests-ts/release-progress-workflow.test.ts@@ -0,0 +1,179 @@+import { readFileSync } from "node:fs";+import { expect, test } from "bun:test";++const workflow = Bun.YAML.parse(+ readFileSync(+ new URL("../../../.github/workflows/release-progress.yml", import.meta.url),+ "utf8",+ ),+) as {+ concurrency: { group: string };+ jobs: {+ identify: {+ permissions: Record<string, string>;+ steps: Array<{ uses?: string; run: string }>;+ };+ report: { concurrency: { group: string; queue: string } };+ };+};++const sha = "a".repeat(40);+const releasePull = {+ title: "chore(release): 99.1.2",+ merged_at: "2026-01-01T00:00:00Z",+ base: { ref: "main" },+};+const ciRun = {+ id: 101,+ path: ".github/workflows/node-ci.yml",+ event: "push",+ head_branch: "main",+ head_sha: sha,+};++function identify(+ run: Record<string, unknown>,+ pages: Array<Array<typeof releasePull>> = [[releasePull]],+ manual = false,+) {+ const output: string[] = [];+ const calls: string[][] = [];+ const execute = new Function(+ "require",+ "process",+ workflow.jobs.identify.steps[0]!.run,+ );+ execute(+ (name: string) => {+ if (name === "node:fs")+ return {+ readFileSync: () =>+ JSON.stringify(manual ? {} : { workflow_run: run }),+ appendFileSync: (_path: string, value: string) => output.push(value),+ };+ expect(name).toBe("node:child_process");+ return {+ execFileSync: (command: string, args: string[]) => {+ expect(command).toBe("gh");+ calls.push(args);+ if (args[1] === "repos/example/security-tool/actions/runs/101")+ return JSON.stringify(run);+ expect(args).toEqual([+ "api",+ `repos/example/security-tool/commits/${sha}/pulls?per_page=100`,+ "--paginate",+ "--slurp",+ ]);+ return JSON.stringify(pages);+ },+ };+ },+ {+ env: {+ GITHUB_REPOSITORY: "example/security-tool",+ GITHUB_EVENT_PATH: "event.json",+ GITHUB_OUTPUT: "outputs",+ RELEASE_RUN_ID: "101",+ },+ },+ );+ return { output: output.join(""), calls };+}++test("ordinary CI commits do not reach release checkout or reporting", () => {+ for (const pull of [+ { ...releasePull, title: "fix: improve reporting" },+ { ...releasePull, title: "chore(release): improve automation" },+ { ...releasePull, title: "chore(release): 99.1.2-beta.1" },+ { ...releasePull, merged_at: "" },+ { ...releasePull, base: { ref: "maintenance" } },+ ]) {+ expect(identify(ciRun, [[pull]]).output).toBe("");+ }+ expect(identify(ciRun, [[]]).output).toBe("");+ expect(workflow.jobs.identify.steps.every((step) => !step.uses)).toBe(true);+ expect(workflow.jobs.identify.permissions).toEqual({+ actions: "read",+ contents: "read",+ "pull-requests": "read",+ });+});++test("release identification uses merged PRs across pages, not commit titles", () => {+ for (const title of [+ "chore(release): 99.1.2",+ "chore(release)!: 99.1.2",+ "release!: 99.1.2",+ "release(npm): 99.1.2",+ ]) {+ expect(+ identify({ ...ciRun, display_title: "A custom merge title" }, [+ [],+ [{ ...releasePull, title }],+ ]).output,+ ).toBe("version=99.1.2\n");+ }+ expect(identify({ ...ciRun, event: "pull_request" }).calls).toEqual([]);+ expect(identify({ ...ciRun, head_branch: "feature" }).calls).toEqual([]);+});++test("release stages share a version key without requiring a version-bump commit", () => {+ for (const run of [+ {+ ...ciRun,+ path: ".github/workflows/[email protected]",+ head_branch: "npm-v99.1.2",+ },+ {+ ...ciRun,+ path: ".github/workflows/node-github-release.yml@main",+ event: "workflow_dispatch",+ display_title: "Publish npm-v99.1.2",+ },+ ]) {+ expect(identify(run).output).toBe("version=99.1.2\n");+ expect(identify(run).calls).toEqual([]);+ expect(identify(run, [], true).output).toBe("version=99.1.2\n");+ expect(identify({ ...run, event: "pull_request" }).output).toBe("");+ }+ expect(+ identify({ ...ciRun, path: ".github/workflows/other.yml" }).output,+ ).toBe("");+});++function refreshGroup(+ id: number,+ action: string,+ name: string,+ inputs: Record<string, unknown> = {},+) {+ return workflow.concurrency.group.replace(+ /\$\{\{(.*?)\}\}/gu,+ (_, expression) =>+ String(+ new Function(+ "github",+ "inputs",+ `return ${expression.replaceAll("inputs.run-id", 'inputs["run-id"]')}`,+ )(+ { run_id: id, event: { action, workflow_run: { id: 101, name } } },+ inputs,+ ),+ ),+ );+}++test("same-run refreshes coalesce without blocking observers or other stages", () => {+ const refresh = refreshGroup(201, "completed", "node-release");+ expect(refreshGroup(202, "", "", { "run-id": "101" })).toBe(refresh);+ expect(refreshGroup(203, "in_progress", "node-release")).not.toBe(refresh);+ expect(refreshGroup(204, "", "", { "run-id": "101", watch: true })).not.toBe(+ refresh,+ );+ expect(refreshGroup(205, "", "", { "run-id": "102" })).not.toBe(refresh);+ expect(workflow.jobs.report.concurrency).toEqual({+ group:+ "release-progress-${{ github.repository }}-${{ needs.identify.outputs.version }}",+ queue: "max",+ });+});