name: node-release-cut on: workflow_run: workflows: ["node-ci"] types: [completed] branches: [main] workflow_dispatch: permissions: contents: read jobs: progress: if: >- github.repository == 'openai/codex-security' && github.event_name == 'workflow_run' && github.event.workflow_run.event == 'push' uses: ./.github/workflows/release-progress.yml permissions: actions: write contents: read pull-requests: write cut: concurrency: group: node-release-cut queue: max if: >- github.repository == 'openai/codex-security' && (github.event_name == 'workflow_dispatch' || (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push' && github.event.workflow_run.head_branch == 'main')) name: cut release tag runs-on: ubuntu-latest permissions: actions: write contents: write env: RELEASE_SHA: ${{ github.event.workflow_run.head_sha || github.sha }} steps: - name: Checkout repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 sparse-checkout: | .github sdk/typescript/scripts persist-credentials: false ref: ${{ github.event.workflow_run.head_sha || github.sha }} - name: Set up Node.js uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: "24.15.0" package-manager-cache: false - name: Resolve the stable package version id: release shell: bash run: | set -euo pipefail RELEASE_SHA="${RELEASE_SHA:-$GITHUB_SHA}" if [[ "$GITHUB_REF" != "refs/heads/main" ]]; then echo "Release tags can only be cut from main." >&2 exit 1 fi git fetch origin main if ! git merge-base --is-ancestor "$GITHUB_SHA" origin/main; then echo "Release tags can only be cut from commits on main." >&2 exit 1 fi if ! git merge-base --is-ancestor "$RELEASE_SHA" origin/main; then echo "Release tags can only be cut from commits on main." >&2 exit 1 fi version="$(node sdk/typescript/scripts/release-automation.mjs version sdk/typescript/package.json)" release_notes_file="$(mktemp)" trap 'rm -f "$release_notes_file"' EXIT if ! git show "$RELEASE_SHA:.github/release-notes.md" \ > "$release_notes_file" 2>/dev/null; then echo "The tagged commit must include .github/release-notes.md." >&2 exit 1 fi node sdk/typescript/scripts/release-automation.mjs \ validate-release-notes "$version" "$release_notes_file" >/dev/null if ! published_versions="$( npm view @openai/codex-security versions \ --json \ --registry=https://registry.npmjs.org/ )"; then echo "Unable to verify published npm release history." >&2 exit 1 fi if [[ "$GITHUB_EVENT_NAME" == "workflow_run" ]] && previous_manifest_oid="$(git rev-parse --verify "$RELEASE_SHA^:sdk/typescript/package.json" 2>/dev/null)"; then previous_version="$( git cat-file blob "$previous_manifest_oid" | node --input-type=module --eval ' import { readFileSync } from "node:fs"; const manifest = JSON.parse(readFileSync(0, "utf8")); if (typeof manifest.version !== "string") { throw new Error("The previous package version is missing."); } process.stdout.write(manifest.version); ' )" if [[ "$version" == "$previous_version" ]]; then release_mode="$( printf '%s\n' "$published_versions" | node sdk/typescript/scripts/release-automation.mjs \ release-mode "$version" )" if [[ "$release_mode" == "recover" ]]; then echo "Package version is unchanged and already published." echo "changed=false" >> "$GITHUB_OUTPUT" exit 0 fi if tagged_sha="$(git rev-parse --verify "refs/tags/npm-v$version^{commit}" 2>/dev/null)" && [[ "$tagged_sha" != "$RELEASE_SHA" ]] && git merge-base --is-ancestor "$tagged_sha" "$RELEASE_SHA"; then tagged_version="$( git show "$tagged_sha:sdk/typescript/package.json" | node -p 'JSON.parse(require("node:fs").readFileSync(0, "utf8")).version' )" if [[ "$tagged_version" == "$version" ]]; then echo "Package version is unchanged and already tagged at $tagged_sha." echo "changed=false" >> "$GITHUB_OUTPUT" exit 0 fi fi else node sdk/typescript/scripts/release-automation.mjs \ require-increase "$version" "$previous_version" >/dev/null fi fi printf '%s\n' "$published_versions" | node sdk/typescript/scripts/release-automation.mjs \ require-published-increase "$version" >/dev/null { printf 'changed=true\n' printf 'tag=npm-v%s\n' "$version" } >> "$GITHUB_OUTPUT" - name: Create the exact merged release tag if: steps.release.outputs.changed == 'true' shell: bash env: GH_TOKEN: ${{ github.token }} RELEASE_TAG: ${{ steps.release.outputs.tag }} run: | set -euo pipefail RELEASE_SHA="${RELEASE_SHA:-$GITHUB_SHA}" query_status=0 tag_response="$( gh api --include \ "repos/$GITHUB_REPOSITORY/git/ref/tags/$RELEASE_TAG" 2>/dev/null )" || query_status=$? IFS=' ' read -r _ response_status _ <<< "$tag_response" || true response_body="$( awk 'body { print } /^\r?$/ { body = 1 }' <<< "$tag_response" )" if [[ "$query_status" == 0 && "$response_status" =~ ^2[0-9]{2}$ ]]; then if ! existing_ref="$( jq -er '[.object.type, .object.sha] | @tsv' <<< "$response_body" )"; then echo "Unable to query release tag $RELEASE_TAG." >&2 exit 1 fi elif [[ "$query_status" != 0 && "$response_status" == 404 && "$( jq -r '.status // empty' <<< "$response_body" \ 2>/dev/null || true )" == 404 ]]; then existing_ref="" else echo "Unable to query release tag $RELEASE_TAG." >&2 exit 1 fi if [[ -n "$existing_ref" ]]; then IFS=$'\t' read -r tag_type tag_object <<< "$existing_ref" if [[ ! "$tag_object" =~ ^[0-9a-f]{40}$ ]]; then echo "Release tag $RELEASE_TAG does not identify a valid commit." >&2 exit 1 fi case "$tag_type" in commit) existing_sha="$tag_object" ;; tag) if ! existing_sha="$( gh api \ "repos/$GITHUB_REPOSITORY/git/tags/$tag_object" \ --jq 'if .object.type == "commit" then .object.sha else empty end' )"; then echo "Release tag $RELEASE_TAG does not identify a valid commit." >&2 exit 1 fi ;; *) echo "Release tag $RELEASE_TAG does not identify a valid commit." >&2 exit 1 ;; esac if [[ ! "$existing_sha" =~ ^[0-9a-f]{40}$ ]]; then echo "Release tag $RELEASE_TAG does not identify a valid commit." >&2 exit 1 fi if [[ "$existing_sha" != "$RELEASE_SHA" ]]; then echo "Release tag $RELEASE_TAG already points to a different commit." >&2 exit 1 fi echo "Release tag $RELEASE_TAG already points to $RELEASE_SHA." exit 0 fi gh api --method POST "repos/$GITHUB_REPOSITORY/git/refs" \ -f "ref=refs/tags/$RELEASE_TAG" \ -f "sha=$RELEASE_SHA" \ --silent - name: Dispatch the protected npm release id: dispatch if: steps.release.outputs.changed == 'true' shell: bash env: GH_TOKEN: ${{ github.token }} RELEASE_TAG: ${{ steps.release.outputs.tag }} run: | set -euo pipefail run_id="$(gh api --method POST \ -H 'X-GitHub-Api-Version: 2026-03-10' \ "repos/$GITHUB_REPOSITORY/actions/workflows/node-release.yml/dispatches" \ -f "ref=$RELEASE_TAG" --jq '.workflow_run_id')" printf 'run-id=%s\n' "$run_id" >> "$GITHUB_OUTPUT" - name: Start release progress observer if: steps.dispatch.outputs.run-id != '' continue-on-error: true shell: bash env: GH_TOKEN: ${{ github.token }} RELEASE_RUN_ID: ${{ steps.dispatch.outputs.run-id }} run: | # Explicitly observe token-dispatched runs without relying on chained # workflow_run events. Progress notification remains best-effort. timeout --kill-after=5s 10s gh workflow run release-progress.yml \ --repo "$GITHUB_REPOSITORY" --ref main \ -f "run-id=$RELEASE_RUN_ID" -f watch=true