name: Publish jazz-tools alpha on: push: branches: - release paths: - .changeset/pre.json workflow_call: inputs: mode: description: "Execution mode: publish (real release) or dry-run (build + verify only)." required: false type: string default: publish artifacts_run_id: description: "dry-run only: verify the packages of this release-artifacts.yml run (or the calling run) instead of building them." required: false type: string default: "" workflow_dispatch: inputs: mode: description: "Execution mode." required: true type: choice default: publish options: - publish - dry-run expected-sha: description: "Required exact release commit SHA for manual publication." required: false type: string version: description: "Required expected source version for manual publication. Must match the release snapshot." required: false type: string env: JAZZ_RN_CARGO_NDK_VERSION: 4.1.2 CACHE_SCOPE_REPOSITORY_ID: ${{ github.event.pull_request.head.repo.id || github.repository_id }} jobs: release-push-gate: name: Gate release push trigger runs-on: blacksmith-4vcpu-ubuntu-2404 permissions: contents: read pull-requests: read outputs: should_run: ${{ steps.gate.outputs.should_run }} reason: ${{ steps.gate.outputs.reason }} release_pr_number: ${{ steps.gate.outputs.release_pr_number }} release_pr_head_ref: ${{ steps.gate.outputs.release_pr_head_ref }} release_pr_head_sha: ${{ steps.gate.outputs.release_pr_head_sha }} steps: - id: gate uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8 env: EVENT_NAME: ${{ github.event_name }} REF: ${{ github.ref }} SHA: ${{ github.sha }} RELEASE_MODE: ${{ inputs.mode || github.event.inputs.mode || 'publish' }} EXPECTED_SHA: ${{ inputs.expected-sha }} EXPECTED_VERSION: ${{ inputs.version }} with: script: | const eventName = process.env.EVENT_NAME; const ref = process.env.REF; const sha = process.env.SHA; const owner = context.repo.owner; const repo = context.repo.repo; let shouldRun = "false"; let reason = ""; let releasePrNumber = ""; let releasePrHeadRef = ""; let releasePrHeadSha = ""; async function listRecentMergedReleasePrs() { const mergedPulls = await github.paginate(github.rest.pulls.list, { owner, repo, state: "closed", base: "release", sort: "updated", direction: "desc", per_page: 100, }); return mergedPulls.filter( (pr) => pr.merged_at !== null && pr.head.ref === "changeset-release/release", ); } async function getToolsVersion(refish) { const response = await github.rest.repos.getContent({ owner, repo, path: "packages/jazz-tools/package.json", ref: refish, }); if (Array.isArray(response.data) || response.data.type !== "file") { throw new Error(`packages/jazz-tools/package.json is not a file at ${refish}`); } return JSON.parse( Buffer.from(response.data.content, response.data.encoding).toString("utf8"), ).version; } function applyReleasePrMetadata(releasePr) { releasePrNumber = String(releasePr.number); releasePrHeadRef = releasePr.head.ref; releasePrHeadSha = releasePr.head.sha; } if (process.env.RELEASE_MODE === "dry-run") { shouldRun = "true"; reason = "dry-run invocation"; } else if (ref !== "refs/heads/release") { core.setFailed(`Publication requires refs/heads/release, got ${ref}`); reason = "publication is restricted to release"; } else if (eventName !== "push" && (process.env.EXPECTED_SHA !== sha || !process.env.EXPECTED_VERSION)) { core.setFailed("Manual publication requires the exact expected-sha and version inputs"); reason = "missing or mismatched manual release expectations"; } else { let matchSource = "commit pull association"; const associatedPulls = await github.request( "GET /repos/{owner}/{repo}/commits/{commit_sha}/pulls", { owner, repo, commit_sha: sha, }, ); let releasePr = associatedPulls.data.find( (pr) => pr.merged_at !== null && pr.base.ref === "release" && pr.merge_commit_sha === sha && pr.head.ref === "changeset-release/release", ); if (!releasePr) { matchSource = "recent merged PR scan by merge_commit_sha"; const mergedReleasePrs = await listRecentMergedReleasePrs(); releasePr = mergedReleasePrs.find((pr) => pr.merge_commit_sha === sha); } if (releasePr && eventName !== "push" && await getToolsVersion(sha) !== process.env.EXPECTED_VERSION) { core.setFailed("Expected version does not match the release snapshot"); releasePr = null; } if (releasePr) { shouldRun = "true"; reason = `merged changeset release PR #${releasePr.number} (${matchSource})`; applyReleasePrMetadata(releasePr); } else { shouldRun = "false"; reason = "release commit is not from a merged changeset-release/release PR"; if (eventName !== "push") core.setFailed(reason); } } core.setOutput("should_run", shouldRun); core.setOutput("reason", reason); core.setOutput("release_pr_number", releasePrNumber); core.setOutput("release_pr_head_ref", releasePrHeadRef); core.setOutput("release_pr_head_sha", releasePrHeadSha); - name: Show gate decision run: | echo "should_run=${{ steps.gate.outputs.should_run }}" echo "reason=${{ steps.gate.outputs.reason }}" echo "release_pr_number=${{ steps.gate.outputs.release_pr_number }}" echo "release_pr_head_ref=${{ steps.gate.outputs.release_pr_head_ref }}" echo "release_pr_head_sha=${{ steps.gate.outputs.release_pr_head_sha }}" # Publication requires the release test tier on the exact tree being # published: CI, examples E2E and RN device acceptance on the Version # Packages PR head, which changesets-release-pr.yml dispatches. Dry runs # build candidates before that tier has run, so they skip this gate. release-test-gate: name: Require release tests on the published tree runs-on: blacksmith-4vcpu-ubuntu-2404 timeout-minutes: 5 needs: [release-push-gate] if: >- needs.release-push-gate.outputs.should_run == 'true' && (inputs.mode || github.event.inputs.mode || 'publish') == 'publish' permissions: actions: read contents: read steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 with: sparse-checkout: dev/scripts - uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8 env: SHA: ${{ github.sha }} RELEASE_PR_HEAD_REF: ${{ needs.release-push-gate.outputs.release_pr_head_ref }} RELEASE_PR_HEAD_SHA: ${{ needs.release-push-gate.outputs.release_pr_head_sha }} with: script: | const { evaluateReleaseTestGate } = await import( `${process.env.GITHUB_WORKSPACE}/dev/scripts/release-test-gate.mjs` ); const { ok, lines } = await evaluateReleaseTestGate({ github, owner: context.repo.owner, repo: context.repo.repo, sha: process.env.SHA, headSha: process.env.RELEASE_PR_HEAD_SHA, headRef: process.env.RELEASE_PR_HEAD_REF, }); for (const line of lines) core.info(line); if (!ok) { core.setFailed( "Release tests have not passed on the tree being published. Rerun or dispatch the failing workflow on the Version Packages PR head, then rerun this workflow.", ); } resolve-preview-artifacts: name: Resolve preview artifact source runs-on: blacksmith-4vcpu-ubuntu-2404 needs: [release-push-gate] if: needs.release-push-gate.outputs.should_run == 'true' permissions: actions: read contents: read outputs: use_preview_artifacts: ${{ steps.resolve.outputs.use_preview_artifacts }} preview_run_id: ${{ steps.resolve.outputs.preview_run_id }} reason: ${{ steps.resolve.outputs.reason }} steps: - id: resolve uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8 env: EVENT_NAME: ${{ github.event_name }} REF: ${{ github.ref }} SHA: ${{ github.sha }} RELEASE_MODE: ${{ inputs.mode || github.event.inputs.mode || 'publish' }} RELEASE_PR_NUMBER: ${{ needs.release-push-gate.outputs.release_pr_number }} RELEASE_PR_HEAD_REF: ${{ needs.release-push-gate.outputs.release_pr_head_ref }} RELEASE_PR_HEAD_SHA: ${{ needs.release-push-gate.outputs.release_pr_head_sha }} ARTIFACTS_RUN_ID: ${{ inputs.artifacts_run_id }} with: script: | const eventName = process.env.EVENT_NAME; const ref = process.env.REF; const sha = process.env.SHA; const releaseMode = process.env.RELEASE_MODE; const releasePrNumber = process.env.RELEASE_PR_NUMBER; const releasePrHeadRef = process.env.RELEASE_PR_HEAD_REF; const releasePrHeadSha = process.env.RELEASE_PR_HEAD_SHA; const owner = context.repo.owner; const repo = context.repo.repo; let usePreviewArtifacts = "false"; let previewRunId = ""; let reason = ""; async function getToolsVersion(refish) { const response = await github.rest.repos.getContent({ owner, repo, path: "packages/jazz-tools/package.json", ref: refish, }); if (Array.isArray(response.data) || response.data.type !== "file") { throw new Error(`packages/jazz-tools/package.json is not a file at ${refish}`); } return JSON.parse( Buffer.from(response.data.content, response.data.encoding).toString("utf8"), ).version; } const artifactsRunId = process.env.ARTIFACTS_RUN_ID; if (artifactsRunId && releaseMode === "dry-run") { // The release candidate gate passes the release-artifacts run it // verified for this commit (the caller checked commit and status). if (!/^[0-9]+$/.test(artifactsRunId)) throw new Error(`artifacts_run_id must be a run ID, got ${artifactsRunId}`); // Supply-chain rule: that run must have built this very commit. const { data: artifactsRun } = await github.rest.actions.getWorkflowRun({ owner, repo, run_id: Number(artifactsRunId), }); const producer = (artifactsRun.path || "").split("@")[0].split("/").pop(); if (!["release-artifacts.yml", "release-candidate.yml"].includes(producer)) throw new Error(`artifacts_run_id ${artifactsRunId} is a ${producer} run, not release-artifacts or release-candidate`); if (String(artifactsRun.event || "").startsWith("pull_request")) throw new Error(`artifacts_run_id ${artifactsRunId} is a ${artifactsRun.event} run`); if (artifactsRun.head_repository?.full_name !== `${owner}/${repo}`) throw new Error(`artifacts_run_id ${artifactsRunId} built ${artifactsRun.head_repository?.full_name}, not ${owner}/${repo}`); if (artifactsRun.head_sha !== sha) throw new Error(`artifacts_run_id ${artifactsRunId} built ${artifactsRun.head_sha}, not this commit ${sha}`); usePreviewArtifacts = "true"; previewRunId = artifactsRunId; reason = `verifying release-artifacts run ${artifactsRunId}`; } else if (artifactsRunId) { reason = "artifacts_run_id is honoured in dry-run only"; } else if (releaseMode !== "publish") { reason = `preview artifact reuse disabled for mode=${releaseMode}`; } else if (ref !== "refs/heads/release") { reason = `preview artifact reuse disabled for ${eventName} on ${ref}`; } else if (!releasePrNumber || !releasePrHeadRef || !releasePrHeadSha) { reason = "release PR metadata unavailable for artifact reuse"; } else { const [currentCommit, previewCommit, currentVersion, previewVersion] = await Promise.all([ github.rest.git.getCommit({ owner, repo, commit_sha: sha, }), github.rest.git.getCommit({ owner, repo, commit_sha: releasePrHeadSha, }), getToolsVersion(sha), getToolsVersion(releasePrHeadSha), ]); const currentTree = currentCommit.data.tree.sha; const previewTree = previewCommit.data.tree.sha; let treeReuseSafe = currentTree === previewTree; if (!treeReuseSafe) { reason = `release tree ${currentTree} differs from release PR head tree ${previewTree}`; } if (treeReuseSafe && currentVersion !== previewVersion) { reason = `release version ${currentVersion} differs from release PR head version ${previewVersion}`; treeReuseSafe = false; } if (treeReuseSafe) { // No reuse: the Version Packages head's runs (release-artifacts.yml // or the preview) are on changeset-release/*, which restores an // actions/cache scope any write collaborator can seed // (#supply-chain, 2026-11-19). This run builds until // release-artifacts.yml restores no cache on untrusted refs. reason = "reuse of changeset-release/* runs is disabled (cache scope); building"; } } core.setOutput("use_preview_artifacts", usePreviewArtifacts); core.setOutput("preview_run_id", previewRunId); core.setOutput("reason", reason); - name: Show artifact reuse decision run: | echo "use_preview_artifacts=${{ steps.resolve.outputs.use_preview_artifacts }}" echo "preview_run_id=${{ steps.resolve.outputs.preview_run_id }}" echo "reason=${{ steps.resolve.outputs.reason }}" build: name: Build Jazz packages needs: [release-push-gate, resolve-preview-artifacts] if: needs.release-push-gate.outputs.should_run == 'true' && needs.resolve-preview-artifacts.outputs.use_preview_artifacts != 'true' uses: ./.github/workflows/build-jazz-packages.yml secrets: inherit with: # Alpha releases publish jazz-rn, unlike an ordinary pkg.pr.new preview. include_rn: true # What ships is also built without cache, and must match. reproduce_ios_relay: true publish-npm: name: Publish npm alpha # npm trusted publishing and its sigstore provenance accept only # GitHub-hosted runners: on a self-hosted (Blacksmith) runner the registry # refuses the upload with E422 "Unsupported GitHub Actions runner # environment". This job only downloads built artifacts and runs # `npm publish`, so a standard runner is enough. runs-on: ubuntu-24.04 # A real publish runs in the protected `publish` environment, which the # npm trusted publishers can be bound to. Dry-runs (including the PR # preview, which calls this workflow) need no credential and run # outside it. environment: ${{ (inputs.mode || github.event.inputs.mode || 'publish') == 'publish' && 'publish' || '' }} needs: - release-push-gate - release-test-gate - resolve-preview-artifacts - build if: >- always() && needs.release-push-gate.outputs.should_run == 'true' && ( needs.release-test-gate.result == 'success' || (inputs.mode || github.event.inputs.mode || 'publish') == 'dry-run' ) && ( needs.resolve-preview-artifacts.outputs.use_preview_artifacts == 'true' || needs.build.result == 'success' ) permissions: actions: read contents: write # npm trusted publishing: each `npm publish` exchanges this job's OIDC # token for a short-lived publish credential. There is no NPM_TOKEN. id-token: write env: RELEASE_MODE: ${{ inputs.mode || github.event.inputs.mode || 'publish' }} steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 - uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4 with: version: 10.14.0 run_install: false - name: Write cache scope run: echo "${{ env.CACHE_SCOPE_REPOSITORY_ID }}" > .github-cache-scope - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6 with: node-version-file: .nvmrc registry-url: https://registry.npmjs.org cache: pnpm cache-dependency-path: | pnpm-lock.yaml .github-cache-scope - run: pnpm install --frozen-lockfile - name: Show artifact source run: | if [ "${{ needs.resolve-preview-artifacts.outputs.use_preview_artifacts }}" = "true" ]; then echo "Artifact source: preview run ${{ needs.resolve-preview-artifacts.outputs.preview_run_id }}" else echo "Artifact source: current workflow run" fi echo "Artifact decision reason: ${{ needs.resolve-preview-artifacts.outputs.reason }}" - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5 if: needs.resolve-preview-artifacts.outputs.use_preview_artifacts != 'true' with: name: pkg-jazz-tools path: packages/jazz-tools - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5 if: needs.resolve-preview-artifacts.outputs.use_preview_artifacts != 'true' with: name: pkg-jazz-wasm path: crates/jazz-wasm - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5 if: needs.resolve-preview-artifacts.outputs.use_preview_artifacts != 'true' with: name: pkg-jazz-napi path: crates/jazz-napi - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5 if: needs.resolve-preview-artifacts.outputs.use_preview_artifacts != 'true' with: name: pkg-jazz-rn path: crates/jazz-rn - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5 if: needs.resolve-preview-artifacts.outputs.use_preview_artifacts != 'true' with: name: pkg-create-jazz path: packages/create-jazz - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5 if: needs.resolve-preview-artifacts.outputs.use_preview_artifacts == 'true' with: github-token: ${{ github.token }} repository: ${{ github.repository }} run-id: ${{ needs.resolve-preview-artifacts.outputs.preview_run_id }} name: pkg-jazz-tools path: packages/jazz-tools - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5 if: needs.resolve-preview-artifacts.outputs.use_preview_artifacts == 'true' with: github-token: ${{ github.token }} repository: ${{ github.repository }} run-id: ${{ needs.resolve-preview-artifacts.outputs.preview_run_id }} name: pkg-jazz-wasm path: crates/jazz-wasm - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5 if: needs.resolve-preview-artifacts.outputs.use_preview_artifacts == 'true' with: github-token: ${{ github.token }} repository: ${{ github.repository }} run-id: ${{ needs.resolve-preview-artifacts.outputs.preview_run_id }} name: pkg-jazz-napi path: crates/jazz-napi - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5 if: needs.resolve-preview-artifacts.outputs.use_preview_artifacts == 'true' with: github-token: ${{ github.token }} repository: ${{ github.repository }} run-id: ${{ needs.resolve-preview-artifacts.outputs.preview_run_id }} name: pkg-jazz-rn path: crates/jazz-rn - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5 if: needs.resolve-preview-artifacts.outputs.use_preview_artifacts == 'true' with: github-token: ${{ github.token }} repository: ${{ github.repository }} run-id: ${{ needs.resolve-preview-artifacts.outputs.preview_run_id }} name: pkg-create-jazz path: packages/create-jazz - name: Show release mode run: | case "${RELEASE_MODE}" in publish|dry-run) ;; *) echo "Unsupported RELEASE_MODE='${RELEASE_MODE}'" exit 1 ;; esac echo "Release mode: ${RELEASE_MODE}" - name: Verify jazz-wasm publish artifacts run: | test -f crates/jazz-wasm/pkg/jazz_wasm_bg.wasm test -f crates/jazz-wasm/pkg/jazz_wasm.js test -f crates/jazz-wasm/pkg/jazz_wasm.d.ts - name: Verify staged jazz-napi platform artifacts run: | test -f crates/jazz-napi/npm/linux-x64-gnu/jazz-napi.linux-x64-gnu.node test -f crates/jazz-napi/npm/linux-arm64-gnu/jazz-napi.linux-arm64-gnu.node test -f crates/jazz-napi/npm/darwin-x64/jazz-napi.darwin-x64.node test -f crates/jazz-napi/npm/darwin-arm64/jazz-napi.darwin-arm64.node test -f crates/jazz-napi/npm/win32-x64-msvc/jazz-napi.win32-x64-msvc.node - name: Verify jazz-tools publish artifacts run: | test -f packages/jazz-tools/dist/index.js test -f packages/jazz-tools/dist/index.d.ts test -f packages/jazz-tools/dist/backend/index.js test -f packages/jazz-tools/dist/react/index.js test -f packages/jazz-tools/dist/permissions/index.js - name: Verify staged jazz-rn relay artifacts env: &release-artifact-source-revision-env # `resolve-preview-artifacts` only permits reuse after proving the # release source and preview source have equivalent trees. Preserve # the latter's commit SHA here: it is the value sealed into its # relay-artifact manifests, whereas release's merge commit has a # different SHA despite the same source tree. # A release-artifacts run (artifacts_run_id) was built at this very # commit: it sealed GITHUB_SHA, like a build in this run. JAZZ_REUSE_PREVIEW_ARTIFACTS: ${{ needs.resolve-preview-artifacts.outputs.use_preview_artifacts == 'true' && inputs.artifacts_run_id == '' }} JAZZ_RELEASE_PR_HEAD_SHA: ${{ needs.release-push-gate.outputs.release_pr_head_sha }} run: | JAZZ_NATIVE_RELAY_SOURCE_REVISION="$(node dev/artifacts/release-artifact-source-revision.mjs)" \ node dev/artifacts/rn-packages.mjs verify - name: Resolve lock-stepped npm package versions run: | VERSION=$(git show "${GITHUB_SHA}:packages/jazz-tools/package.json" | node -e 'let s="";process.stdin.on("data",d=>s+=d);process.stdin.on("end",()=>console.log(JSON.parse(s).version))') EXPECTED_VERSION="${{ inputs.artifacts_run_id == '' && github.event.inputs.version || '' }}" if [ -n "${EXPECTED_VERSION}" ] && [ "${EXPECTED_VERSION}" != "${VERSION}" ]; then echo "Manual version ${EXPECTED_VERSION} does not match checked-out source version ${VERSION}." echo "Publish a committed release snapshot first; release workflows never rewrite versions in place." exit 1 fi echo "Resolved publish version: ${VERSION}" - name: Sync jazz-napi platform package versions and optional deps run: | cd crates/jazz-napi pnpm exec napi version --npm-dir npm node -e 'const fs=require("fs");const rootPath="package.json";const pkg=JSON.parse(fs.readFileSync(rootPath,"utf8"));const deps=[];for(const entry of fs.readdirSync("npm",{withFileTypes:true})){if(!entry.isDirectory())continue;const child=JSON.parse(fs.readFileSync(`npm/${entry.name}/package.json`,"utf8"));deps.push([child.name,pkg.version]);}deps.sort((a,b)=>a[0].localeCompare(b[0]));pkg.optionalDependencies=Object.fromEntries(deps);fs.writeFileSync(rootPath,`${JSON.stringify(pkg,null,2)}\n`);' # The inspector overlay isn't a published package — its embedded build is # bundled into jazz-tools' own dist so jazz-tools is self-contained. Build # it (against the downloaded jazz-tools/jazz-wasm) and stage it next to the # overlay server module before jazz-tools is packed. - name: Stage inspector overlay assets into jazz-tools run: | pnpm --filter inspector run build:embedded pnpm --filter jazz-tools run stage:inspector-overlay - name: Guard alpha-only lock-stepped publish versions run: | EXPECTED_VERSION="${{ inputs.artifacts_run_id == '' && github.event.inputs.version || '' }}" node -e 'const fs=require("fs");const path=require("path");const expected=process.env.EXPECTED_VERSION;const alphaVersion=/^2\.0\.0-alpha\.[0-9A-Za-z.-]+$/;const tools=JSON.parse(fs.readFileSync("packages/jazz-tools/package.json","utf8"));const wasm=JSON.parse(fs.readFileSync("crates/jazz-wasm/package.json","utf8"));const napi=JSON.parse(fs.readFileSync("crates/jazz-napi/package.json","utf8"));const rn=JSON.parse(fs.readFileSync("crates/jazz-rn/package.json","utf8"));const createJazz=JSON.parse(fs.readFileSync("packages/create-jazz/package.json","utf8"));if(expected){if(!alphaVersion.test(expected)){throw new Error(`Version override must match 2.0.0-alpha.*, got ${expected}`);}if(tools.version!==expected){throw new Error(`Version override mismatch: expected ${expected}, got ${tools.version}`);}}for(const pkg of [tools,wasm,napi,rn,createJazz]){if(!alphaVersion.test(pkg.version)){throw new Error(`${pkg.name} version must match 2.0.0-alpha.*, got ${pkg.version}`);}const tag=pkg.publishConfig&&pkg.publishConfig.tag;if(tag&&tag!=="latest"){throw new Error(`${pkg.name} publishConfig.tag must be latest, got ${tag}`);}}if(!(tools.version===wasm.version&&tools.version===napi.version&&tools.version===rn.version&&napi.version===createJazz.version)){throw new Error(`Versions diverged: tools=${tools.version} wasm=${wasm.version} napi=${napi.version} rn=${rn.version} create-jazz=${createJazz.version}`);}for(const [name,version] of Object.entries(napi.optionalDependencies||{})){if(version!==napi.version){throw new Error(`napi optional dep ${name} is ${version}, expected ${napi.version}`);}}for(const entry of fs.readdirSync("crates/jazz-napi/npm",{withFileTypes:true})){if(!entry.isDirectory())continue;const pkgPath=path.join("crates/jazz-napi/npm",entry.name,"package.json");const pkg=JSON.parse(fs.readFileSync(pkgPath,"utf8"));if(!alphaVersion.test(pkg.version)){throw new Error(`${pkg.name} version must match 2.0.0-alpha.*, got ${pkg.version}`);}if(pkg.version!==napi.version){throw new Error(`${pkg.name} version ${pkg.version} must match jazz-napi ${napi.version}`);}}console.log(`Alpha-only publish guard passed at ${tools.version}`);' - name: Verify immutable release source snapshot run: | PUBLISHED_VERSION=$(node -p 'JSON.parse(require("fs").readFileSync("packages/create-jazz/package.json","utf8")).version') for package_json in \ packages/create-jazz/package.json \ packages/jazz-tools/package.json \ crates/jazz-wasm/package.json \ crates/jazz-napi/package.json \ crates/jazz-rn/package.json \ crates/jazz-rn/npm/android/package.json \ crates/jazz-rn/npm/ios/package.json; do SOURCE_VERSION=$(git show "${GITHUB_SHA}:${package_json}" | node -e 'let s="";process.stdin.on("data",d=>s+=d);process.stdin.on("end",()=>console.log(JSON.parse(s).version))') if [ "${SOURCE_VERSION}" != "${PUBLISHED_VERSION}" ]; then echo "${package_json} is ${SOURCE_VERSION} at ${GITHUB_SHA}, but this workflow would publish ${PUBLISHED_VERSION}." echo "Publish a committed release snapshot first; source tags must exactly match the published packages." exit 1 fi done echo "Source snapshot ${GITHUB_SHA} exactly matches ${PUBLISHED_VERSION}." - name: Ensure release source tag if: env.RELEASE_MODE == 'publish' run: | VERSION=$(node -p 'JSON.parse(require("fs").readFileSync("packages/create-jazz/package.json","utf8")).version') TAG="v${VERSION}" SOURCE_COMMIT=$(git rev-parse "${GITHUB_SHA}^{commit}") EXISTING_TAG_TARGET=$(git ls-remote --tags origin "refs/tags/${TAG}" "refs/tags/${TAG}^{}" | awk -v tag="${TAG}" ' $2 == "refs/tags/" tag "^{}" { peeled = $1 } $2 == "refs/tags/" tag { direct = $1 } END { print peeled ? peeled : direct } ') if [ -n "${EXISTING_TAG_TARGET}" ]; then if [ "${EXISTING_TAG_TARGET}" != "${SOURCE_COMMIT}" ]; then echo "${TAG} already points to ${EXISTING_TAG_TARGET}, not the release source ${SOURCE_COMMIT}." exit 1 fi echo "${TAG} already points at the release source snapshot." else git tag "${TAG}" "${SOURCE_COMMIT}" git push origin "refs/tags/${TAG}" fi - name: Verify packed jazz-wasm payload run: | TMP_DIR=$(mktemp -d) pnpm --filter jazz-wasm pack --pack-destination "${TMP_DIR}" TARBALL=$(ls "${TMP_DIR}"/jazz-wasm-*.tgz | head -n 1) tar -tf "${TARBALL}" | grep -q "package/pkg/jazz_wasm_bg.wasm" tar -tf "${TARBALL}" | grep -q "package/pkg/jazz_wasm.js" tar -tf "${TARBALL}" | grep -q "package/pkg/jazz_wasm.d.ts" # `jazz-wasm/durable-object`: the core a Durable Object hosts. echo "durable-object files: $(tar -tf "${TARBALL}" | grep -c "package/durable-object/")" tar -tf "${TARBALL}" | grep -q "package/durable-object/pkg/jazz_wasm_do_bg.wasm" tar -tf "${TARBALL}" | grep -q "package/durable-object/pkg/jazz_wasm_do.js" tar -tf "${TARBALL}" | grep -q "package/durable-object/index.js" tar -tf "${TARBALL}" | grep -q "package/durable-object/host.js" # `jazz-wasm/backend`: what a backend's `createJazz` runs on in a Worker. echo "backend files: $(tar -tf "${TARBALL}" | grep -c "package/backend/")" tar -tf "${TARBALL}" | grep -q "package/backend/pkg/jazz_wasm_backend_bg.wasm" tar -tf "${TARBALL}" | grep -q "package/backend/pkg/jazz_wasm_backend.js" tar -tf "${TARBALL}" | grep -q "package/backend/index.js" - name: Verify packed jazz-napi payload run: | TMP_DIR=$(mktemp -d) pnpm --filter jazz-napi pack --pack-destination "${TMP_DIR}" TARBALL=$(ls "${TMP_DIR}"/jazz-napi-*.tgz | head -n 1) node dev/artifacts/verify-packed-napi.mjs "${TARBALL}" - name: Verify packed jazz-rn relay payload env: *release-artifact-source-revision-env run: | export JAZZ_NATIVE_RELAY_SOURCE_REVISION="$(node dev/artifacts/release-artifact-source-revision.mjs)" export JAZZ_NATIVE_RELAY_CARGO_NDK_VERSION="${JAZZ_RN_CARGO_NDK_VERSION}" node dev/artifacts/rn-packages.mjs pack "$(mktemp -d)" - name: Verify packed jazz-tools manifest run: | TMP_DIR=$(mktemp -d) pnpm --filter jazz-tools pack --pack-destination "${TMP_DIR}" TARBALL=$(ls "${TMP_DIR}"/jazz-tools-*.tgz | head -n 1) tar -xOf "${TARBALL}" package/package.json | node -e 'let s="";process.stdin.on("data",(d)=>s+=d);process.stdin.on("end",()=>{const p=JSON.parse(s);for(const field of ["dependencies","optionalDependencies","peerDependencies"]){for(const [name,version] of Object.entries(p[field]||{})){if(typeof version==="string"&&version.startsWith("workspace:")){throw new Error(`${field}.${name} uses workspace protocol (${version}) in packed manifest`);}}}console.log(`Packed manifest OK for ${p.name}@${p.version}`);});' # The inspector overlay's embedded build must be bundled into jazz-tools. tar -tf "${TARBALL}" | grep -q "package/dist/dev/inspector-overlay/embedded/embedded.html" # So must the Inspector that createJazz serves at /inspect/. tar -tf "${TARBALL}" | grep -q "package/dist/dev/inspector-overlay/embedded/backend.html" # It serves it from this module, which ships wherever the code does. tar -xOf "${TARBALL}" package/dist/backend/inspector-ui-files.js > "${TMP_DIR}/inspector-ui-files.js" grep -Fq '"backend.html":' "${TMP_DIR}/inspector-ui-files.js" - name: Verify packed create-jazz manifest run: | TMP_DIR=$(mktemp -d) pnpm --filter create-jazz pack --pack-destination "${TMP_DIR}" TARBALL=$(ls "${TMP_DIR}"/create-jazz-*.tgz | head -n 1) tar -xOf "${TARBALL}" package/package.json | node -e 'let s="";process.stdin.on("data",(d)=>s+=d);process.stdin.on("end",()=>{const p=JSON.parse(s);for(const field of ["dependencies","optionalDependencies","peerDependencies"]){for(const [name,version] of Object.entries(p[field]||{})){if(typeof version==="string"&&version.startsWith("workspace:")){throw new Error(`${field}.${name} uses workspace protocol (${version}) in packed manifest`);}}}console.log(`Packed manifest OK for ${p.name}@${p.version}`);});' tar -tf "${TARBALL}" | grep -q "package/bin/create-jazz.js" tar -tf "${TARBALL}" | grep -q "package/dist/index.js" # Trusted publishing needs npm 11.5.1 or newer; the Node in .nvmrc # bundles it. Fail before the first upload rather than mid-release. - name: Require npm with trusted publishing if: env.RELEASE_MODE == 'publish' run: | node -e 'const [a,b,c]=process.argv[1].split(".").map(Number);if(a<11||(a===11&&(b<5||(b===5&&c<1)))){console.error(`::error::npm ${process.argv[1]} cannot use trusted publishing; 11.5.1 or newer is required`);process.exit(1);}console.log(`npm ${process.argv[1]} supports trusted publishing`);' "$(npm --version)" # Every package publishes straight to `latest` (npm's OIDC credentials # can't move dist-tags afterwards), so refuse a re-run of an older # version before it would move `latest` back. - name: Refuse to move latest back if: env.RELEASE_MODE == 'publish' run: node dev/artifacts/latest-guard.mjs - name: Publish jazz-wasm if: env.RELEASE_MODE == 'publish' run: | WASM_VERSION=$(node -p 'JSON.parse(require("fs").readFileSync("crates/jazz-wasm/package.json","utf8")).version') if npm view "jazz-wasm@${WASM_VERSION}" version >/dev/null 2>&1; then echo "jazz-wasm@${WASM_VERSION} already exists on npm; skipping publish." else pnpm --filter jazz-wasm publish --tag latest --access public --no-git-checks fi - name: Publish jazz-napi if: env.RELEASE_MODE == 'publish' run: | NAPI_VERSION=$(node -p 'JSON.parse(require("fs").readFileSync("crates/jazz-napi/package.json","utf8")).version') for pkg_dir in crates/jazz-napi/npm/*; do pkg_name=$(node -p "JSON.parse(require('fs').readFileSync('${pkg_dir}/package.json','utf8')).name") if npm view "${pkg_name}@${NAPI_VERSION}" version >/dev/null 2>&1; then echo "${pkg_name}@${NAPI_VERSION} already exists on npm; skipping publish." else npm publish "${pkg_dir}" --tag latest --access public fi done if npm view "jazz-napi@${NAPI_VERSION}" version >/dev/null 2>&1; then echo "jazz-napi@${NAPI_VERSION} already exists on npm; skipping publish." else pnpm --filter jazz-napi publish --tag latest --access public --no-git-checks fi - name: Publish jazz-rn if: env.RELEASE_MODE == 'publish' run: node dev/artifacts/publish-rn-packages.mjs - name: Publish jazz-tools if: env.RELEASE_MODE == 'publish' run: | TOOLS_VERSION=$(node -p 'JSON.parse(require("fs").readFileSync("packages/jazz-tools/package.json","utf8")).version') if npm view "jazz-tools@${TOOLS_VERSION}" version >/dev/null 2>&1; then echo "jazz-tools@${TOOLS_VERSION} already exists on npm; skipping publish." else pnpm --filter jazz-tools publish --tag latest --access public --no-git-checks fi - name: Publish create-jazz if: env.RELEASE_MODE == 'publish' run: | CREATE_JAZZ_VERSION=$(node -p 'JSON.parse(require("fs").readFileSync("packages/create-jazz/package.json","utf8")).version') if npm view "create-jazz@${CREATE_JAZZ_VERSION}" version >/dev/null 2>&1; then echo "create-jazz@${CREATE_JAZZ_VERSION} already exists on npm; skipping publish." else pnpm --filter create-jazz publish --tag latest --access public --no-git-checks fi # The Rust crates follow npm: dispatch publish-jazz-crates-alpha.yml for # this version. crates.io trusted publishing refuses workflow_run triggers, # and GITHUB_TOKEN may dispatch workflows. That workflow publishes the # v commit, only when its crates match npm, behind the `publish` # environment's approval. dispatch-crates: name: Dispatch the crates.io publish runs-on: blacksmith-4vcpu-ubuntu-2404 needs: [publish-npm] if: >- always() && needs.publish-npm.result == 'success' && (inputs.mode || github.event.inputs.mode || 'publish') == 'publish' permissions: actions: write contents: read steps: - name: Dispatch publish-jazz-crates-alpha.yml env: GH_TOKEN: ${{ github.token }} GH_REPO: ${{ github.repository }} SHA: ${{ github.sha }} DEFAULT_BRANCH: ${{ github.event.repository.default_branch || 'main' }} run: | set -euo pipefail VERSION=$(gh api "repos/${GH_REPO}/contents/packages/jazz-tools/package.json?ref=${SHA}" --jq .content | base64 -d | jq -r .version) if ! [[ "${VERSION}" =~ ^2\.0\.0-alpha\.[0-9]+$ ]]; then echo "::error::jazz-tools at ${SHA} is '${VERSION}', not 2.0.0-alpha.N; not dispatching the crates publish." exit 1 fi gh workflow run publish-jazz-crates-alpha.yml --ref "${DEFAULT_BRANCH}" -f mode=publish -f "tag=v${VERSION}" echo "Dispatched the crates.io publish for v${VERSION}." # Jazz Cloud's images run the Linux server binary from the GitHub release: # npm's jazz-tools carries no native binary. Attach both builds with their # SHA256SUMS to the version's draft; "GitHub release" refuses to publish # without them. Only "GitHub release" creates the draft (with its notes), # so the two never race to create two: without one, this job fails and is # re-run once the draft exists. A published release's assets are never # replaced. attach-server-binaries: name: Attach server binaries to the GitHub release runs-on: blacksmith-4vcpu-ubuntu-2404 needs: - release-push-gate - resolve-preview-artifacts - publish-npm if: >- always() && needs.publish-npm.result == 'success' && (inputs.mode || github.event.inputs.mode || 'publish') == 'publish' permissions: actions: read contents: write env: GH_TOKEN: ${{ github.token }} GH_REPO: ${{ github.repository }} steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5 if: needs.resolve-preview-artifacts.outputs.use_preview_artifacts != 'true' with: pattern: jazz-tools-linux-* merge-multiple: true path: dist - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5 if: needs.resolve-preview-artifacts.outputs.use_preview_artifacts == 'true' with: github-token: ${{ github.token }} repository: ${{ github.repository }} run-id: ${{ needs.resolve-preview-artifacts.outputs.preview_run_id }} pattern: jazz-tools-linux-* merge-multiple: true path: dist - name: Checksums working-directory: dist run: | set -euo pipefail test -s jazz-tools-linux-x64 test -s jazz-tools-linux-arm64 sha256sum jazz-tools-linux-x64 jazz-tools-linux-arm64 > SHA256SUMS cat SHA256SUMS - name: Upload run: | set -euo pipefail VERSION=$(node -p 'JSON.parse(require("fs").readFileSync("packages/create-jazz/package.json","utf8")).version') TAG="v${VERSION}" if ! is_draft=$(gh release view "${TAG}" --json isDraft --jq .isDraft 2>/dev/null); then echo "::error::No draft for ${TAG}. Create it with \"GitHub release\" (publish: false, with the notes), then re-run this job." exit 1 fi if [ "${is_draft}" != true ]; then echo "::error::${TAG} is published; its server binaries are never replaced." exit 1 fi gh release upload "${TAG}" dist/jazz-tools-linux-x64 dist/jazz-tools-linux-arm64 dist/SHA256SUMS --clobber # Read-only check that the Inspector Vercel token can see its project. It runs # in candidate dry-runs too, so a broken token shows up before anything # publishes. It deliberately does not gate npm publication. inspector-preflight: name: Check Inspector Vercel access runs-on: blacksmith-4vcpu-ubuntu-2404 needs: [release-push-gate] if: needs.release-push-gate.outputs.should_run == 'true' timeout-minutes: 5 permissions: contents: read env: VERCEL_ORG_ID: ${{ secrets.VERCEL_INSPECTOR_ORG_ID }} VERCEL_PROJECT_ID: ${{ secrets.VERCEL_INSPECTOR_PROJECT_ID }} VERCEL_TOKEN: ${{ secrets.VERCEL_INSPECTOR_TOKEN }} steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6 with: node-version-file: .nvmrc - run: node dev/scripts/promote-inspector-deployment.mjs preflight # Deploy the exact inspector-prebuilt bytes that were built for this tree # (the tested candidate's when its artifacts were reused) instead of waiting # for Vercel's Git integration to build `release`, which it never does. stage-inspector-production: name: Stage inspector production needs: - release-push-gate - resolve-preview-artifacts - publish-npm - inspector-preflight if: >- always() && needs.release-push-gate.outputs.should_run == 'true' && needs.publish-npm.result == 'success' && needs.inspector-preflight.result == 'success' && (inputs.mode || github.event.inputs.mode || 'publish') == 'publish' uses: ./.github/workflows/stage-inspector-production.yml permissions: actions: read contents: read with: artifact-run-id: ${{ needs.resolve-preview-artifacts.outputs.use_preview_artifacts == 'true' && needs.resolve-preview-artifacts.outputs.preview_run_id || '' }} source-sha: ${{ github.sha }} source-branch: release secrets: inherit deploy-inspector-production: name: Promote inspector production needs: - release-push-gate - publish-npm - stage-inspector-production if: >- always() && needs.release-push-gate.outputs.should_run == 'true' && needs.publish-npm.result == 'success' && needs.stage-inspector-production.result == 'success' && (inputs.mode || github.event.inputs.mode || 'publish') == 'publish' uses: ./.github/workflows/promote-inspector-production.yml with: deploy-sha: ${{ github.sha }} deployment-url: ${{ needs.stage-inspector-production.outputs.deployment-url }} secrets: inherit