# Generated file - DO NOT EDIT # Source: release.yml.genie.ts name: Release on: workflow_dispatch: inputs: npm_tag: description: npm dist-tag for the release required: true default: latest type: string pr_number: description: PR number selector for trusted snapshot promotion required: false default: '0' type: string head_sha: description: Expected PR head selector for trusted snapshot promotion required: false default: '' type: string ci_run_id: description: Exact successful PR CI run selector for trusted snapshot promotion required: false default: '0' type: string mode: description: Release workflow mode required: true default: create-release-pr type: choice options: [create-release-pr, validate-release-plan, publish-release, publish-snapshot, promote-pr-snapshot] workflow_run: workflows: [ci] types: [completed] schedule: - cron: '*/5 * * * *' pull_request: paths: - .github/workflows/release.yml - .github/workflows/release.yml.genie.ts - .github/workflows/deploy-prod.yml - .github/workflows/deploy-prod.yml.genie.ts - .github/scripts/validate-stable-docs-release.mjs - .github/scripts/validate-stable-docs-release.test.mjs - genie/repo.ts - nix/devenv-modules/tasks/local/mono-wrappers.nix - release/release-plan.json - release/release-notes.md - release/version.json - release/devtools-artifact.json - scripts/src/commands/release.ts - scripts/src/commands/devtools-artifact.ts - scripts/src/commands/changesets.ts - scripts/src/commands/docs.ts - scripts/src/shared/netlify.ts push: branches: [main] paths: [release/release-plan.json] permissions: contents: read id-token: write env: CI: 'true' FORCE_SETUP: '1' jobs: source-policy: runs-on: [namespace-profile-linux-x86-64, 'namespace-features:github.run-id=${{ github.run_id }}'] permissions: contents: read defaults: run: shell: bash steps: - uses: actions/checkout@v6 with: persist-credentials: false - name: Install Nix uses: DeterminateSystems/determinate-nix-action@v3 env: GITHUB_TOKEN: ${{ github.token }} with: extra-conf: | experimental-features = nix-command flakes accept-flake-config = true extra-substituters = https://devenv.cachix.org extra-trusted-public-keys = devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw= access-tokens = github.com=${{ github.token }} summarize: true - name: Check first-party default refs env: GITHUB_TOKEN: ${{ github.token }} FIRST_PARTY_OWNERS_JSON: '["overengineeringstudio"]' DEFAULT_REF: main DEFAULT_REFS_JSON: '{}' VERIFY_REACHABLE: '1' NORMALIZE_GIT_BRANCH_REFS: '1' ALLOW_LEGACY_MEMBER_COMMIT_REFS: '0' run: | nix shell nixpkgs#nodejs_24 -c node <<'NODE' const fs = require('node:fs') const path = require('node:path') const os = require('node:os') const cp = require('node:child_process') const cwd = process.cwd() const firstPartyOwners = new Set(JSON.parse(process.env.FIRST_PARTY_OWNERS_JSON).map((owner) => owner.toLowerCase())) const defaultRef = process.env.DEFAULT_REF || 'main' const defaultRefs = new Map(Object.entries(JSON.parse(process.env.DEFAULT_REFS_JSON || '{}')).map(([repo, ref]) => [repo.toLowerCase(), ref])) const verifyReachable = process.env.VERIFY_REACHABLE === '1' const allowLegacyMemberCommitRefs = process.env.ALLOW_LEGACY_MEMBER_COMMIT_REFS === '1' const violations = [] const repoKey = (repo) => repo.owner.toLowerCase() + '/' + repo.repo.toLowerCase() const isFirstParty = (repo) => firstPartyOwners.has(repo.owner.toLowerCase()) const normalizeGitBranchRefs = process.env.NORMALIZE_GIT_BRANCH_REFS === '1' const normalizeRef = (ref) => normalizeGitBranchRefs && ref.startsWith('refs/heads/') ? ref.slice('refs/heads/'.length) : ref const expectedRefFor = (repo) => normalizeRef(defaultRefs.get(repoKey(repo)) || defaultRef) const immutableCommitRef = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/i const isAllowedLegacyMemberRef = ({ memberName, ref }) => allowLegacyMemberCommitRefs && typeof memberName === 'string' && memberName.endsWith('-legacy') && immutableCommitRef.test(ref) const githubRepoFromUrl = (url) => { const match = url.match(/github\.com[/:]([^/]+)\/([^/#?]+?)(?:\.git)?(?:[#?].*)?$/) return match ? { owner: match[1], repo: match[2] } : undefined } const parseGithubLikeRef = (value) => { const hashIndex = value.indexOf('#') const baseWithQuery = hashIndex >= 0 ? value.slice(0, hashIndex) : value const hashRef = hashIndex >= 0 ? value.slice(hashIndex + 1) : undefined const queryIndex = baseWithQuery.indexOf('?') const base = queryIndex >= 0 ? baseWithQuery.slice(0, queryIndex) : baseWithQuery const params = new URLSearchParams(queryIndex >= 0 ? baseWithQuery.slice(queryIndex + 1) : '') const queryRef = params.get('ref') || undefined if (base.startsWith('github:')) { const parts = base.slice('github:'.length).split('/') if (parts.length < 2) return undefined return { repo: { owner: parts[0], repo: parts[1] }, ref: hashRef || queryRef || (parts.length > 2 ? parts.slice(2).join('/') : undefined), } } if (base.startsWith('git+https://github.com/')) { const repo = githubRepoFromUrl(base.slice('git+'.length)) return repo ? { repo, ref: hashRef || queryRef } : undefined } if (base.startsWith('git+ssh://git@github.com/')) { const pathParts = base.slice('git+ssh://git@github.com/'.length).replace(/\.git$/, '').split('/') return pathParts.length >= 2 ? { repo: { owner: pathParts[0], repo: pathParts[1] }, ref: hashRef || queryRef } : undefined } const urlRepo = githubRepoFromUrl(base) if (urlRepo) return { repo: urlRepo, ref: hashRef || queryRef } if (!value.includes('://') && !value.startsWith('./') && !value.startsWith('../') && !value.startsWith('/')) { const parts = base.split('/') if (parts.length === 2 && parts[0] && parts[1]) { return { repo: { owner: parts[0], repo: parts[1] }, ref: hashRef } } } return undefined } const addRefViolation = ({ file, repo, ref, field, inputName, memberName }) => { if (!repo || !ref || !isFirstParty(repo)) return const expectedRef = expectedRefFor(repo) const normalizedRef = normalizeRef(ref) if (normalizedRef === expectedRef) return if (isAllowedLegacyMemberRef({ memberName, ref: normalizedRef })) return violations.push({ type: 'ref', file, repo: repoKey(repo), ref: normalizedRef, expectedRef, field, inputName, memberName, }) } const readJson = (file) => { try { return JSON.parse(fs.readFileSync(file, 'utf8')) } catch { return undefined } } const displayPath = (file) => path.relative(cwd, file) || path.basename(file) const authorityNames = new Set(['megarepo.kdl', 'megarepo.json', 'megarepo.lock', 'flake.nix', 'flake.lock', 'devenv.yaml', 'devenv.lock']) const ignoredDirs = new Set(['.git', 'node_modules', 'dist', 'result', '.devenv', '.direnv', '.next', '.storybook-static']) const collectAuthorityFiles = (root) => { const files = [] const walk = (dir) => { let entries = [] try { entries = fs.readdirSync(dir) } catch { return } for (const entry of entries) { const full = path.join(dir, entry) let stat try { stat = fs.statSync(full) } catch { continue } if (stat.isDirectory()) { if (ignoredDirs.has(entry)) continue if (dir === root && entry === 'repos') continue walk(full) } else if (stat.isFile() && authorityNames.has(entry)) { files.push(full) } } } walk(root) return files } const extractFlakeNixInputs = (content) => { const inputs = [] const directPattern = /(?:inputs\.)?([a-zA-Z0-9_-]+)\.url\s*=\s*"([^"]+)"/g let match while ((match = directPattern.exec(content)) !== null) { inputs.push({ inputName: match[1], url: match[2] }) } const lines = content.split('\n') let inInputs = false let inputsIndent = -1 let currentInputName let currentInputIndent = -1 for (const line of lines) { const trimmed = line.trimStart() const indent = line.length - trimmed.length if (trimmed.startsWith('inputs = {')) { inInputs = true inputsIndent = indent currentInputName = undefined currentInputIndent = -1 continue } if (!inInputs) continue if (trimmed && indent <= inputsIndent && trimmed.startsWith('};')) { inInputs = false currentInputName = undefined continue } if (currentInputName && trimmed === '};' && indent <= currentInputIndent) { currentInputName = undefined continue } const inputStart = trimmed.match(/^(?:inputs\.)?([a-zA-Z0-9_-]+)\s*=\s*\{\s*$/) if (inputStart && indent > inputsIndent) { currentInputName = inputStart[1] currentInputIndent = indent continue } const urlMatch = trimmed.match(/^url\s*=\s*"([^"]+)"/) if (currentInputName && urlMatch) inputs.push({ inputName: currentInputName, url: urlMatch[1] }) } return inputs } const extractDevenvYamlInputs = (content) => { const inputs = [] const lines = content.split('\n') let inInputs = false let inputsIndent = -1 let currentInputName for (const line of lines) { const trimmed = line.trimStart() const indent = line.length - trimmed.length if (trimmed === 'inputs:' && !inInputs) { inInputs = true inputsIndent = indent currentInputName = undefined continue } if (!inInputs) continue if (trimmed && indent <= inputsIndent && !trimmed.startsWith('#')) { inInputs = false currentInputName = undefined continue } const inputNameMatch = trimmed.match(/^([a-zA-Z0-9_-]+):$/) if (inputNameMatch && indent > inputsIndent) { currentInputName = inputNameMatch[1] continue } const urlMatch = trimmed.match(/^url:\s*(.+)$/) if (currentInputName && urlMatch) { const raw = urlMatch[1].trim() const url = (raw.startsWith('"') && raw.endsWith('"')) || (raw.startsWith("'") && raw.endsWith("'")) ? raw.slice(1, -1) : raw inputs.push({ inputName: currentInputName, url }) } } return inputs } const lockInputs = (content) => { const parsed = readJsonContent(content) const rootName = parsed && (parsed.root || 'root') const root = parsed && parsed.nodes && parsed.nodes[rootName] if (!root || !root.inputs || !parsed.nodes) return [] return Object.entries(root.inputs).flatMap(([inputName, nodeName]) => { const node = parsed.nodes[nodeName] return node ? [{ inputName, original: node.original, locked: node.locked }] : [] }) } const readJsonContent = (content) => { try { return JSON.parse(content) } catch { return undefined } } const repoFromLockSection = (section) => { if (!section || typeof section !== 'object') return undefined if (section.type === 'github' && typeof section.owner === 'string' && typeof section.repo === 'string') { return { owner: section.owner, repo: section.repo } } if (section.type === 'git' && typeof section.url === 'string') return githubRepoFromUrl(section.url) if (typeof section.url === 'string') return parseGithubLikeRef(section.url)?.repo || githubRepoFromUrl(section.url) return undefined } const refFromLockSection = (section) => { if (!section || typeof section !== 'object') return undefined if (typeof section.ref === 'string') return section.ref if (typeof section.url === 'string') return parseGithubLikeRef(section.url)?.ref return undefined } const roots = [cwd] const reposRoot = path.join(cwd, 'repos') if (fs.existsSync(reposRoot)) { for (const entry of fs.readdirSync(reposRoot)) { roots.push(path.join(reposRoot, entry)) } } for (const root of roots) { for (const file of collectAuthorityFiles(root)) { const base = path.basename(file) const rel = displayPath(file) const content = fs.readFileSync(file, 'utf8') if (base === 'megarepo.kdl') { for (const line of content.split('\n')) { const match = line.trim().match(/^([A-Za-z0-9_.-]+)\s+"([^"]+)"/) if (!match) continue const parsed = parseGithubLikeRef(match[2]) addRefViolation({ file: rel, repo: parsed && parsed.repo, ref: parsed && parsed.ref, field: 'members.source', memberName: match[1] }) } } else if (base === 'megarepo.lock') { const parsed = readJson(file) for (const [memberName, member] of Object.entries((parsed && parsed.members) || {})) { const repo = typeof member.url === 'string' ? githubRepoFromUrl(member.url) : undefined addRefViolation({ file: rel, repo, ref: member.ref, field: 'members.ref', memberName }) } } else if (base === 'flake.nix') { for (const input of extractFlakeNixInputs(content)) { const parsed = parseGithubLikeRef(input.url) addRefViolation({ file: rel, repo: parsed && parsed.repo, ref: parsed && parsed.ref, field: 'url.ref', inputName: input.inputName }) } } else if (base === 'devenv.yaml') { for (const input of extractDevenvYamlInputs(content)) { const parsed = parseGithubLikeRef(input.url) addRefViolation({ file: rel, repo: parsed && parsed.repo, ref: parsed && parsed.ref, field: 'url.ref', inputName: input.inputName }) } } else if (base === 'flake.lock' || base === 'devenv.lock') { for (const input of lockInputs(content)) { for (const [field, section] of [['original', input.original], ['locked', input.locked]]) { addRefViolation({ file: rel, repo: repoFromLockSection(section), ref: refFromLockSection(section), field: field + '.ref', inputName: input.inputName }) } } } } } if (verifyReachable) { const lock = readJson(path.join(cwd, 'megarepo.lock')) for (const [memberName, member] of Object.entries((lock && lock.members) || {})) { const repo = typeof member.url === 'string' ? githubRepoFromUrl(member.url) : undefined if (!repo || !isFirstParty(repo)) continue if ( typeof member.ref === 'string' && isAllowedLegacyMemberRef({ memberName, ref: normalizeRef(member.ref) }) ) { continue } const expectedRef = expectedRefFor(repo) const remote = 'https://github.com/' + repo.owner + '/' + repo.repo + '.git' const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'default-ref-policy-')) let ok = false try { cp.execFileSync('git', ['-C', tmp, 'init', '-q'], { stdio: 'ignore' }) cp.execFileSync('git', ['-C', tmp, 'remote', 'add', 'origin', remote], { stdio: 'ignore' }) cp.execFileSync('git', ['-C', tmp, 'fetch', '-q', '--filter=blob:none', 'origin', 'refs/heads/' + expectedRef + ':refs/remotes/origin/' + expectedRef], { stdio: 'ignore' }) cp.execFileSync('git', ['-C', tmp, 'cat-file', '-e', member.commit + '^{commit}'], { stdio: 'ignore' }) cp.execFileSync('git', ['-C', tmp, 'merge-base', '--is-ancestor', member.commit, 'refs/remotes/origin/' + expectedRef], { stdio: 'ignore' }) ok = true } catch { ok = false } finally { fs.rmSync(tmp, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 }) } if (!ok) { violations.push({ type: 'reachability', file: 'megarepo.lock', repo: repoKey(repo), rev: member.commit, expectedRef, memberName }) } } } if (violations.length === 0) { console.log('Default ref policy OK') process.exit(0) } console.error('Default ref policy failed:') for (const violation of violations) { if (violation.type === 'reachability') { console.error(' - ' + violation.file + ': member ' + violation.memberName + ' ' + violation.repo + ' locks ' + violation.rev.slice(0, 12) + " outside '" + violation.expectedRef + "'") } else { const name = violation.memberName ? ' member ' + violation.memberName : violation.inputName ? ' input ' + violation.inputName : '' console.error(' - ' + violation.file + ':' + name + ' ' + violation.repo + " uses ref '" + violation.ref + "' in " + violation.field + "; expected '" + violation.expectedRef + "'") } } console.error('') console.error('Fix: merge upstream PRs first, retarget first-party inputs back to their default refs, then refresh locks.') process.exit(1) NODE shell: bash if: github.event_name != 'schedule' && github.event_name != 'workflow_run' dispatch-authorized-pr-snapshots: if: github.event_name == 'schedule' runs-on: ubuntu-24.04 permissions: actions: write contents: read pull-requests: read env: GH_TOKEN: ${{ github.token }} defaults: run: shell: bash steps: - name: Checkout trusted package topology uses: actions/checkout@v4 with: ref: ${{ github.workflow_sha }} persist-credentials: false sparse-checkout: | .github/scripts/pr-snapshot-artifact.mjs scripts/src/generated/release-topology.json - name: Dispatch incomplete authorized cohorts to trusted main workflow run: | set -euo pipefail test "$GITHUB_WORKFLOW_REF" = "$GITHUB_REPOSITORY/.github/workflows/release.yml@refs/heads/main" prs_json=$(gh api --paginate "/repos/$GITHUB_REPOSITORY/pulls?state=open&base=main&per_page=100" --slurp) release_workflow_id=$(gh api "/repos/$GITHUB_REPOSITORY/actions/workflows/release.yml" --jq .id) [[ "$release_workflow_id" =~ ^[1-9][0-9]*$ ]] scan_failed=false while IFS=$' ' read -r pr_number head_sha head_repository head_ref fork_label_present; do cohort_failed=false verified_receipt=false registry_state_file="$RUNNER_TEMP/registry-state-$pr_number.json" printf '[] ' > "$registry_state_file" [[ "$pr_number" =~ ^[1-9][0-9]*$ ]] [[ "$head_sha" =~ ^[0-9a-f]{40}$ ]] test -n "$head_repository" test -n "$head_ref" if [ "$head_repository" = "$GITHUB_REPOSITORY" ]; then review_json=$(gh api graphql -f query='query($owner:String!,$name:String!,$number:Int!){repository(owner:$owner,name:$name){pullRequest(number:$number){reviewDecision}}}' -f owner="${GITHUB_REPOSITORY%%/*}" -f name="${GITHUB_REPOSITORY#*/}" -F number="$pr_number") if [ "$(jq -r '.data.repository.pullRequest.reviewDecision // ""' <<<"$review_json")" != APPROVED ]; then continue fi elif [ "$fork_label_present" != true ]; then continue fi version="0.0.0-snapshot-pr.$pr_number.$head_sha" snapshot_tag="pr-$pr_number-$head_sha" selected_run_id='' selected_pack_attempt='' runs_json=$(gh api --paginate --method GET "/repos/$GITHUB_REPOSITORY/actions/workflows/ci.yml/runs" -f event=pull_request -f status=success -f branch="$head_ref" -F per_page=100 --slurp) while IFS= read -r candidate_run_id; do [[ "$candidate_run_id" =~ ^[1-9][0-9]*$ ]] jobs_json=$(gh api --paginate "/repos/$GITHUB_REPOSITORY/actions/runs/$candidate_run_id/jobs?filter=all&per_page=100" --slurp) pack_job=$(jq -c '[.[] | .jobs[] | select(.name == "pack-pr-snapshot" and .conclusion == "success")] | sort_by(.run_attempt) | last' <<<"$jobs_json") if [ "$pack_job" = null ]; then continue fi pack_attempt=$(jq -r '.run_attempt' <<<"$pack_job") [[ "$pack_attempt" =~ ^[1-9][0-9]*$ ]] artifact_name="pr-snapshot-$head_sha-$pack_attempt" artifacts_json=$(gh api --paginate "/repos/$GITHUB_REPOSITORY/actions/runs/$candidate_run_id/artifacts?per_page=100" --slurp) if ! jq -e --arg name "$artifact_name" 'any(.[] | .artifacts[]; .name == $name and .expired == false)' <<<"$artifacts_json" >/dev/null; then continue fi selected_run_id="$candidate_run_id" selected_pack_attempt="$pack_attempt" break done < <(jq -r --arg sha "$head_sha" --arg head_repository "$head_repository" --arg head_ref "$head_ref" '[.[] | .workflow_runs[] | select(.event == "pull_request" and .conclusion == "success" and .head_repository.full_name == $head_repository and .head_branch == $head_ref and .head_sha == $sha)] | sort_by(.created_at) | reverse | .[].id' <<<"$runs_json") if [ -z "$selected_run_id" ]; then echo "PR #$pr_number has no exact successful pack artifact yet; skipping" continue fi receipt_name="verified-pr-snapshot-$head_sha-$selected_run_id-$selected_pack_attempt" receipts_json=$(gh api --paginate --method GET "/repos/$GITHUB_REPOSITORY/actions/artifacts" -f name="$receipt_name" -F per_page=100 --slurp) while IFS= read -r receipt_run_id; do [[ "$receipt_run_id" =~ ^[1-9][0-9]*$ ]] receipt_run=$(gh api "/repos/$GITHUB_REPOSITORY/actions/runs/$receipt_run_id") if [ "$(jq -r .workflow_id <<<"$receipt_run")" = "$release_workflow_id" ] && [ "$(jq -r .event <<<"$receipt_run")" = workflow_dispatch ] && [ "$(jq -r .head_branch <<<"$receipt_run")" = main ] && [ "$(jq -r .conclusion <<<"$receipt_run")" = success ]; then verified_receipt=true break fi done < <(jq -r --arg name "$receipt_name" '.[] | .artifacts[]? | select(.name == $name and .expired == false) | .workflow_run.id' <<<"$receipts_json") while IFS= read -r package_name; do remote_version=$(npm view "$package_name@$version" version --json --registry=https://registry.npmjs.org 2>/dev/null | jq -r . || true) remote_tag=$(npm view "$package_name" dist-tags --json --registry=https://registry.npmjs.org 2>/dev/null | jq -r --arg tag "$snapshot_tag" '.[$tag] // empty' || true) jq --arg name "$package_name" --arg version "$remote_version" --arg tag "$remote_tag" '. + [{name: $name, version: $version, tag: $tag}]' "$registry_state_file" > "$registry_state_file.next" mv "$registry_state_file.next" "$registry_state_file" done < <(jq -r '.publishablePackageNames[]' scripts/src/generated/release-topology.json) assessment=$(node .github/scripts/pr-snapshot-artifact.mjs assess-registry --state-file="$registry_state_file" --version="$version" --verified-receipt="$verified_receipt") action=$(jq -r .action <<<"$assessment") if [ "$action" = conflict ]; then package_name=$(jq -r .packageName <<<"$assessment") conflicting_version=$(jq -r .conflictingVersion <<<"$assessment") echo "::error::PR #$pr_number package $package_name tag $snapshot_tag points to unexpected version $conflicting_version" cohort_failed=true elif [ "$action" = complete ]; then echo "PR #$pr_number snapshot cohort has a trusted verification receipt" continue elif [ "$action" != dispatch ]; then echo "Unknown registry assessment action: $action" >&2 cohort_failed=true fi if [ "$cohort_failed" = true ]; then scan_failed=true continue fi gh workflow run release.yml --repo "$GITHUB_REPOSITORY" --ref main -f mode=promote-pr-snapshot -f npm_tag=latest -f pr_number="$pr_number" -f head_sha="$head_sha" -f ci_run_id="$selected_run_id" done < <(jq -r '.[][] | select(.draft == false and .base.ref == "main") | [.number, .head.sha, .head.repo.full_name, .head.ref, (any(.labels[]?; .name == "ci:publish-snapshot") | tostring)] | @tsv' <<<"$prs_json") if [ "$scan_failed" = true ]; then exit 1 fi validate-pr-snapshot: if: (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request') || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main' && inputs.mode == 'promote-pr-snapshot') runs-on: ubuntu-24.04 permissions: actions: read contents: read pull-requests: read outputs: head-sha: ${{ steps.identity.outputs.head-sha }} manifest-digest: ${{ steps.validate.outputs.manifest-digest }} npm-tag: ${{ steps.validate.outputs.npm-tag }} package-count: ${{ steps.validate.outputs.package-count }} pr-number: ${{ steps.identity.outputs.pr-number }} release-run-attempt: ${{ steps.validate.outputs.release-run-attempt }} run-attempt: ${{ steps.identity.outputs.run-attempt }} run-id: ${{ steps.identity.outputs.run-id }} source-run-url: ${{ steps.identity.outputs.source-run-url }} topology-digest: ${{ steps.validate.outputs.topology-digest }} version: ${{ steps.validate.outputs.version }} env: ARTIFACT_DIR: '${{ github.workspace }}/tmp/pr-snapshot-artifact' CACHIX_AUTH_TOKEN: '' GH_TOKEN: ${{ github.token }} PUBLISH_LIST: '${{ github.workspace }}/tmp/pr-snapshot-publish-list.tsv' defaults: run: shell: bash steps: - id: identity name: Resolve exact successful CI run and current PR head run: | set -euo pipefail test "$GITHUB_WORKFLOW_REF" = "$GITHUB_REPOSITORY/.github/workflows/release.yml@refs/heads/main" [[ "$GITHUB_WORKFLOW_SHA" =~ ^[0-9a-f]{40}$ ]] if [ "$GITHUB_EVENT_NAME" = workflow_run ]; then run_id='${{ github.event.workflow_run.id }}' else test "$GITHUB_EVENT_NAME" = workflow_dispatch pr_number='${{ inputs.pr_number }}' head_sha='${{ inputs.head_sha }}' run_id='${{ inputs.ci_run_id }}' fi [[ "$run_id" =~ ^[1-9][0-9]*$ ]] run_json=$(gh api "/repos/$GITHUB_REPOSITORY/actions/runs/$run_id") test "$(jq -r '.event' <<<"$run_json")" = pull_request test "$(jq -r '.status' <<<"$run_json")" = completed test "$(jq -r '.conclusion' <<<"$run_json")" = success test "$(jq -r '.path' <<<"$run_json")" = .github/workflows/ci.yml run_head_repository=$(jq -r '.head_repository.full_name' <<<"$run_json") run_head_branch=$(jq -r '.head_branch' <<<"$run_json") run_head_sha=$(jq -r '.head_sha' <<<"$run_json") test -n "$run_head_repository" test -n "$run_head_branch" [[ "$run_head_sha" =~ ^[0-9a-f]{40}$ ]] if [ "$GITHUB_EVENT_NAME" = workflow_run ]; then prs_json=$(gh api --paginate "/repos/$GITHUB_REPOSITORY/pulls?state=open&base=main&per_page=100" --slurp) matching_prs=$(jq --arg head_repository "$run_head_repository" --arg head_branch "$run_head_branch" --arg head_sha "$run_head_sha" '[.[][] | select(.draft == false and .base.ref == "main" and .head.repo.full_name == $head_repository and .head.ref == $head_branch and .head.sha == $head_sha)]' <<<"$prs_json") test "$(jq 'length' <<<"$matching_prs")" = 1 pr_number=$(jq -r '.[0].number' <<<"$matching_prs") head_sha="$run_head_sha" else test "$run_head_sha" = "$head_sha" fi [[ "$pr_number" =~ ^[1-9][0-9]*$ ]] [[ "$head_sha" =~ ^[0-9a-f]{40}$ ]] source_run_url=$(jq -r '.html_url' <<<"$run_json") jobs_json=$(gh api --paginate "/repos/$GITHUB_REPOSITORY/actions/runs/$run_id/jobs?filter=all&per_page=100" --slurp) pack_job=$(jq -c '[.[] | .jobs[] | select(.name == "pack-pr-snapshot" and .conclusion == "success")] | sort_by(.run_attempt) | last' <<<"$jobs_json") test "$pack_job" != null run_attempt=$(jq -r '.run_attempt' <<<"$pack_job") [[ "$run_attempt" =~ ^[1-9][0-9]*$ ]] pr_json=$(gh api "/repos/$GITHUB_REPOSITORY/pulls/$pr_number") test "$(jq -r '.state' <<<"$pr_json")" = open test "$(jq -r '.base.ref' <<<"$pr_json")" = main test "$(jq -r '.head.sha' <<<"$pr_json")" = "$head_sha" test "$(jq -r '.head.repo.full_name' <<<"$pr_json")" = "$run_head_repository" test "$(jq -r '.head.ref' <<<"$pr_json")" = "$run_head_branch" echo "head-sha=$head_sha" >> "$GITHUB_OUTPUT" echo "pr-number=$pr_number" >> "$GITHUB_OUTPUT" echo "run-id=$run_id" >> "$GITHUB_OUTPUT" echo "run-attempt=$run_attempt" >> "$GITHUB_OUTPUT" echo "source-run-url=$source_run_url" >> "$GITHUB_OUTPUT" - name: Checkout trusted validator only uses: actions/checkout@v4 with: ref: ${{ github.workflow_sha }} persist-credentials: false sparse-checkout: | .github/scripts/pr-snapshot-artifact.mjs scripts/src/generated/release-topology.json - name: Use pinned Node validator runtime uses: actions/setup-node@v4 with: node-version: 24.15.0 - name: Download exact-run snapshot candidate uses: actions/download-artifact@v4 with: name: 'pr-snapshot-${{ steps.identity.outputs.head-sha }}-${{ steps.identity.outputs.run-attempt }}' path: '${{ github.workspace }}/tmp/pr-snapshot-artifact' github-token: ${{ github.token }} run-id: ${{ steps.identity.outputs.run-id }} - id: validate name: Validate immutable snapshot candidate env: EXPECTED_HEAD_SHA: ${{ steps.identity.outputs.head-sha }} EXPECTED_PR_NUMBER: ${{ steps.identity.outputs.pr-number }} EXPECTED_RUN_ID: ${{ steps.identity.outputs.run-id }} EXPECTED_RUN_ATTEMPT: ${{ steps.identity.outputs.run-attempt }} run: | set -euo pipefail result=$(node .github/scripts/pr-snapshot-artifact.mjs validate \ --artifact-dir="$ARTIFACT_DIR" \ --topology=scripts/src/generated/release-topology.json \ --repository="$GITHUB_REPOSITORY" \ --pr-number="$EXPECTED_PR_NUMBER" \ --head-sha="$EXPECTED_HEAD_SHA" \ --run-id="$EXPECTED_RUN_ID" \ --run-attempt="$EXPECTED_RUN_ATTEMPT" \ --publish-list="$PUBLISH_LIST") echo "version=$(jq -r '.version' <<<"$result")" >> "$GITHUB_OUTPUT" echo "manifest-digest=$(jq -r '.manifestDigest' <<<"$result")" >> "$GITHUB_OUTPUT" echo "topology-digest=$(jq -r '.topologyDigest' <<<"$result")" >> "$GITHUB_OUTPUT" echo "npm-tag=$(jq -r '.npmTag' <<<"$result")" >> "$GITHUB_OUTPUT" echo "package-count=$(jq -r '.packageCount' <<<"$result")" >> "$GITHUB_OUTPUT" echo "release-run-attempt=$GITHUB_RUN_ATTEMPT" >> "$GITHUB_OUTPUT" cp "$PUBLISH_LIST" "$ARTIFACT_DIR/trusted-publish-list.tsv" - name: Upload validated snapshot candidate uses: actions/upload-artifact@v4 with: name: 'validated-pr-snapshot-${{ steps.identity.outputs.head-sha }}-${{ steps.identity.outputs.run-id }}-${{ steps.validate.outputs.release-run-attempt }}' path: '${{ github.workspace }}/tmp/pr-snapshot-artifact/' if-no-files-found: error retention-days: 1 attest-pr-snapshot: needs: [validate-pr-snapshot] runs-on: ubuntu-24.04 permissions: actions: read attestations: write artifact-metadata: write contents: read id-token: write env: ARTIFACT_DIR: '${{ github.workspace }}/tmp/validated-pr-snapshot' CACHIX_AUTH_TOKEN: '' defaults: run: shell: bash outputs: promotion-attempt: ${{ steps.handoff.outputs.promotion-attempt }} steps: - name: Download validated snapshot candidate uses: actions/download-artifact@v4 with: name: 'validated-pr-snapshot-${{ needs.validate-pr-snapshot.outputs.head-sha }}-${{ needs.validate-pr-snapshot.outputs.run-id }}-${{ needs.validate-pr-snapshot.outputs.release-run-attempt }}' path: '${{ github.workspace }}/tmp/validated-pr-snapshot' - id: handoff name: Verify validated artifact identity and write predicate env: HEAD_SHA: ${{ needs.validate-pr-snapshot.outputs.head-sha }} MANIFEST_DIGEST: ${{ needs.validate-pr-snapshot.outputs.manifest-digest }} PR_NUMBER: ${{ needs.validate-pr-snapshot.outputs.pr-number }} SOURCE_RUN_ATTEMPT: ${{ needs.validate-pr-snapshot.outputs.run-attempt }} SOURCE_RUN_ID: ${{ needs.validate-pr-snapshot.outputs.run-id }} TOPOLOGY_DIGEST: ${{ needs.validate-pr-snapshot.outputs.topology-digest }} run: | set -euo pipefail test "$(sha256sum "$ARTIFACT_DIR/manifest.json" | cut -d' ' -f1)" = "$MANIFEST_DIGEST" echo "promotion-attempt=$GITHUB_RUN_ATTEMPT" >> "$GITHUB_OUTPUT" jq -n --arg repository "$GITHUB_REPOSITORY" --argjson prNumber "$PR_NUMBER" --arg headSha "$HEAD_SHA" --argjson sourceRunId "$SOURCE_RUN_ID" --argjson sourceRunAttempt "$SOURCE_RUN_ATTEMPT" --arg manifestSha256 "$MANIFEST_DIGEST" --arg topologySha256 "$TOPOLOGY_DIGEST" '{repository, prNumber, headSha, sourceRunId, sourceRunAttempt, manifestSha256, topologySha256}' > "$RUNNER_TEMP/pr-snapshot-attestation.json" - name: Attest validated snapshot candidate uses: actions/attest@v4 with: subject-path: | ${{ env.ARTIFACT_DIR }}/*.tgz ${{ env.ARTIFACT_DIR }}/manifest.json predicate-type: 'https://livestore.dev/attestations/pr-snapshot-candidate/v1' predicate-path: '${{ runner.temp }}/pr-snapshot-attestation.json' - name: Upload attested promotion artifact uses: actions/upload-artifact@v4 with: name: 'promotion-pr-snapshot-${{ needs.validate-pr-snapshot.outputs.head-sha }}-${{ needs.validate-pr-snapshot.outputs.run-id }}-${{ steps.handoff.outputs.promotion-attempt }}' path: '${{ github.workspace }}/tmp/validated-pr-snapshot/' if-no-files-found: error retention-days: 1 authorize-pr-snapshot: needs: [validate-pr-snapshot] runs-on: ubuntu-24.04 permissions: contents: read pull-requests: read outputs: authorized: ${{ steps.approval.outputs.authorized }} defaults: run: shell: bash steps: - name: Checkout trusted validator only uses: actions/checkout@v4 with: ref: ${{ github.workflow_sha }} persist-credentials: false sparse-checkout: .github/scripts/pr-snapshot-artifact.mjs - name: Use pinned Node validator runtime uses: actions/setup-node@v4 with: node-version: 24.15.0 - id: approval name: Require current-head review or fork trust label env: EXPECTED_HEAD_SHA: ${{ needs.validate-pr-snapshot.outputs.head-sha }} GH_TOKEN: ${{ github.token }} PR_NUMBER: ${{ needs.validate-pr-snapshot.outputs.pr-number }} run: | set -euo pipefail pr_json=$(gh api "/repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER") authorized=false authorized_by='none' if [ "$(jq -r '.state' <<<"$pr_json")" = open ] && [ "$(jq -r '.draft' <<<"$pr_json")" = false ] && [ "$(jq -r '.base.ref' <<<"$pr_json")" = main ]; then head_repository=$(jq -r '.head.repo.full_name' <<<"$pr_json") reviews_json=$(gh api --paginate "/repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER/reviews?per_page=100" --slurp | jq -s 'flatten') owner="${GITHUB_REPOSITORY%%/*}" name="${GITHUB_REPOSITORY#*/}" review_decision=$(gh api graphql -f query='query($owner:String!,$name:String!,$number:Int!){repository(owner:$owner,name:$name){pullRequest(number:$number){reviewDecision}}}' -f owner="$owner" -f name="$name" -F number="$PR_NUMBER" --jq '.data.repository.pullRequest.reviewDecision' || echo '') printf '%s' "$reviews_json" > "$RUNNER_TEMP/reviews.json" authorized=$(node .github/scripts/pr-snapshot-artifact.mjs authorize --repository="$GITHUB_REPOSITORY" --head-repository="$head_repository" --head-sha="$EXPECTED_HEAD_SHA" --current-head-sha="$(jq -r '.head.sha' <<<"$pr_json")" --label-names="$(jq -c '[.labels[]?.name]' <<<"$pr_json")" --review-decision="$review_decision" --reviews-file="$RUNNER_TEMP/reviews.json" --trust-label='ci:publish-snapshot' | jq -r '.authorized') if [ "$authorized" = true ]; then if [ "$head_repository" = "$GITHUB_REPOSITORY" ]; then authorized_by='current-head review' else authorized_by='ci:publish-snapshot fork trust label' fi fi fi echo "authorized=$authorized" >> "$GITHUB_OUTPUT" echo "Snapshot promotion authorized: $authorized ($authorized_by)" >> "$GITHUB_STEP_SUMMARY" publish-pr-snapshot: if: needs.authorize-pr-snapshot.outputs.authorized == 'true' needs: [validate-pr-snapshot, attest-pr-snapshot, authorize-pr-snapshot] runs-on: ubuntu-24.04 concurrency: group: 'pr-snapshot-${{ needs.validate-pr-snapshot.outputs.head-sha }}' cancel-in-progress: false permissions: actions: read contents: read id-token: write pull-requests: read env: ARTIFACT_DIR: '${{ github.workspace }}/tmp/validated-pr-snapshot' CACHIX_AUTH_TOKEN: '' GH_TOKEN: ${{ github.token }} PUBLISH_LIST: '${{ github.workspace }}/tmp/validated-pr-snapshot/trusted-publish-list.tsv' defaults: run: shell: bash steps: - name: Use pinned npm trusted-publishing client uses: actions/setup-node@v4 with: node-version: 24.15.0 - name: Checkout trusted validator only uses: actions/checkout@v4 with: ref: ${{ github.workflow_sha }} persist-credentials: false sparse-checkout: .github/scripts/pr-snapshot-artifact.mjs - name: Download validated promotion artifact uses: actions/download-artifact@v4 with: name: 'promotion-pr-snapshot-${{ needs.validate-pr-snapshot.outputs.head-sha }}-${{ needs.validate-pr-snapshot.outputs.run-id }}-${{ needs.attest-pr-snapshot.outputs.promotion-attempt }}' path: '${{ github.workspace }}/tmp/validated-pr-snapshot' - name: Recheck current-head authorization before OIDC publication env: EXPECTED_HEAD_SHA: ${{ needs.validate-pr-snapshot.outputs.head-sha }} PR_NUMBER: ${{ needs.validate-pr-snapshot.outputs.pr-number }} run: | set -euo pipefail pr_json=$(gh api "/repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER") test "$(jq -r '.state' <<<"$pr_json")" = open test "$(jq -r '.draft' <<<"$pr_json")" = false test "$(jq -r '.base.ref' <<<"$pr_json")" = main head_repository=$(jq -r '.head.repo.full_name' <<<"$pr_json") reviews_json=$(gh api --paginate "/repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER/reviews?per_page=100" --slurp | jq -s 'flatten') owner="${GITHUB_REPOSITORY%%/*}" name="${GITHUB_REPOSITORY#*/}" review_decision=$(gh api graphql -f query='query($owner:String!,$name:String!,$number:Int!){repository(owner:$owner,name:$name){pullRequest(number:$number){reviewDecision}}}' -f owner="$owner" -f name="$name" -F number="$PR_NUMBER" --jq '.data.repository.pullRequest.reviewDecision' || echo '') printf '%s' "$reviews_json" > "$RUNNER_TEMP/recheck-reviews.json" # The same predicate the authorize job used, invoked again rather than restated. This is the # time-of-use check, so it must re-read live state — but it must not re-decide differently. test "$(node .github/scripts/pr-snapshot-artifact.mjs authorize --repository="$GITHUB_REPOSITORY" --head-repository="$head_repository" --head-sha="$EXPECTED_HEAD_SHA" --current-head-sha="$(jq -r '.head.sha' <<<"$pr_json")" --label-names="$(jq -c '[.labels[]?.name]' <<<"$pr_json")" --review-decision="$review_decision" --reviews-file="$RUNNER_TEMP/recheck-reviews.json" --trust-label='ci:publish-snapshot' | jq -r '.authorized')" = true - name: Verify promotion handoff env: EXPECTED_MANIFEST_DIGEST: ${{ needs.validate-pr-snapshot.outputs.manifest-digest }} run: | set -euo pipefail test -f "$ARTIFACT_DIR/manifest.json" test -f "$PUBLISH_LIST" actual_manifest_digest=$(sha256sum "$ARTIFACT_DIR/manifest.json" | cut -d' ' -f1) test "$actual_manifest_digest" = "$EXPECTED_MANIFEST_DIGEST" jq -r '.packages[] | [.name, .file] | @tsv' "$ARTIFACT_DIR/manifest.json" > "$RUNNER_TEMP/expected-publish-list.tsv" cmp "$RUNNER_TEMP/expected-publish-list.tsv" "$PUBLISH_LIST" jq -r '.packages[] | [.file, .sha256] | @tsv' "$ARTIFACT_DIR/manifest.json" | while IFS=$' ' read -r file expected_sha256; do [[ "$file" =~ ^[a-zA-Z0-9._-]+[.]tgz$ ]] actual_sha256=$(sha256sum "$ARTIFACT_DIR/$file" | cut -d' ' -f1) test "$actual_sha256" = "$expected_sha256" done if [ -n "${NODE_AUTH_TOKEN:-}" ] || [ -n "${NPM_TOKEN:-}" ]; then echo "PR snapshot publishing must use npm trusted publishing; token auth is not allowed." >&2 exit 1 fi - name: Publish exact-SHA package cohort env: SNAPSHOT_TAG: ${{ needs.validate-pr-snapshot.outputs.npm-tag }} SNAPSHOT_VERSION: ${{ needs.validate-pr-snapshot.outputs.version }} run: | set -euo pipefail while IFS=$' ' read -r package_name file; do test -n "$package_name" test -n "$file" tarball="$ARTIFACT_DIR/$file" local_sha1=$(sha1sum "$tarball" | cut -d' ' -f1) if remote_sha1=$(npm view "$package_name@$SNAPSHOT_VERSION" dist.shasum --json --registry=https://registry.npmjs.org 2>/dev/null); then remote_sha1=$(jq -r . <<<"$remote_sha1") if [ "$remote_sha1" != "$local_sha1" ]; then echo "$package_name@$SNAPSHOT_VERSION already exists with a different tarball digest" >&2 exit 1 fi remote_tag=$(npm view "$package_name" dist-tags --json --registry=https://registry.npmjs.org 2>/dev/null | jq -r --arg tag "$SNAPSHOT_TAG" '.[$tag] // empty' || true) if [ -n "$remote_tag" ] && [ "$remote_tag" != "$SNAPSHOT_VERSION" ]; then echo "$package_name tag $SNAPSHOT_TAG points to unexpected version $remote_tag" >&2 exit 1 fi if [ -z "$remote_tag" ]; then echo "::warning::$package_name@$SNAPSHOT_VERSION matches the candidate but mutable tag $SNAPSHOT_TAG is absent; OIDC publishing cannot repair dist-tags" fi echo "$package_name@$SNAPSHOT_VERSION already matches candidate; skipping" continue fi npm publish "$tarball" --registry=https://registry.npmjs.org --tag="$SNAPSHOT_TAG" --access=public --ignore-scripts --provenance done < "$PUBLISH_LIST" - name: Verify complete immutable registry cohort env: SNAPSHOT_TAG: ${{ needs.validate-pr-snapshot.outputs.npm-tag }} SNAPSHOT_VERSION: ${{ needs.validate-pr-snapshot.outputs.version }} run: | set -euo pipefail verified=0 while IFS=$' ' read -r package_name file; do tarball="$ARTIFACT_DIR/$file" local_integrity="sha512-$(openssl dgst -sha512 -binary "$tarball" | base64 -w0)" matched=false for attempt in $(seq 1 12); do remote_version=$(npm view "$package_name@$SNAPSHOT_VERSION" version --json --registry=https://registry.npmjs.org 2>/dev/null | jq -r . || true) remote_integrity=$(npm view "$package_name@$SNAPSHOT_VERSION" dist.integrity --json --registry=https://registry.npmjs.org 2>/dev/null | jq -r . || true) remote_tag=$(npm view "$package_name" dist-tags --json --registry=https://registry.npmjs.org 2>/dev/null | jq -r --arg tag "$SNAPSHOT_TAG" '.[$tag] // empty' || true) if [ -n "$remote_tag" ] && [ "$remote_tag" != "$SNAPSHOT_VERSION" ]; then echo "$package_name tag $SNAPSHOT_TAG points to unexpected version $remote_tag" >&2 exit 1 fi if [ "$remote_version" = "$SNAPSHOT_VERSION" ] && [ "$remote_integrity" = "$local_integrity" ]; then matched=true break fi sleep 5 done if [ "$matched" != true ]; then echo "Registry verification failed for $package_name@$SNAPSHOT_VERSION" >&2 exit 1 fi verified=$((verified + 1)) done < "$PUBLISH_LIST" test "$verified" = '${{ needs.validate-pr-snapshot.outputs.package-count }}' echo "Verified $verified immutable package versions and SHA-512 integrities; tag bindings are present or absent, never conflicting." >> "$GITHUB_STEP_SUMMARY" - name: Write trusted verification receipt env: HEAD_SHA: ${{ needs.validate-pr-snapshot.outputs.head-sha }} MANIFEST_DIGEST: ${{ needs.validate-pr-snapshot.outputs.manifest-digest }} PR_NUMBER: ${{ needs.validate-pr-snapshot.outputs.pr-number }} SNAPSHOT_VERSION: ${{ needs.validate-pr-snapshot.outputs.version }} SOURCE_RUN_ATTEMPT: ${{ needs.validate-pr-snapshot.outputs.run-attempt }} SOURCE_RUN_ID: ${{ needs.validate-pr-snapshot.outputs.run-id }} run: jq -n --arg repository "$GITHUB_REPOSITORY" --argjson prNumber "$PR_NUMBER" --arg headSha "$HEAD_SHA" --argjson sourceRunId "$SOURCE_RUN_ID" --argjson sourceRunAttempt "$SOURCE_RUN_ATTEMPT" --arg version "$SNAPSHOT_VERSION" --arg manifestSha256 "$MANIFEST_DIGEST" '{repository, prNumber, headSha, sourceRunId, sourceRunAttempt, version, manifestSha256}' > "$RUNNER_TEMP/verified-pr-snapshot.json" - name: Upload trusted verification receipt uses: actions/upload-artifact@v4 with: name: 'verified-pr-snapshot-${{ needs.validate-pr-snapshot.outputs.head-sha }}-${{ needs.validate-pr-snapshot.outputs.run-id }}-${{ needs.validate-pr-snapshot.outputs.run-attempt }}' path: '${{ runner.temp }}/verified-pr-snapshot.json' if-no-files-found: error overwrite: true retention-days: 30 - name: Record snapshot provenance env: SNAPSHOT_VERSION: ${{ needs.validate-pr-snapshot.outputs.version }} MANIFEST_DIGEST: ${{ needs.validate-pr-snapshot.outputs.manifest-digest }} PACKAGE_COUNT: ${{ needs.validate-pr-snapshot.outputs.package-count }} PR_NUMBER: ${{ needs.validate-pr-snapshot.outputs.pr-number }} SNAPSHOT_TAG: ${{ needs.validate-pr-snapshot.outputs.npm-tag }} SOURCE_RUN_URL: ${{ needs.validate-pr-snapshot.outputs.source-run-url }} run: | cat >> "$GITHUB_STEP_SUMMARY" <> "$GITHUB_PATH" - name: Enable Cachix cache uses: cachix/cachix-action@v17 with: name: livestore skipPush: true - name: Restore megarepo store id: restore-megarepo-store uses: actions/cache/restore@v4 with: path: '${{ runner.temp }}/megarepo-store' key: "megarepo-store-v1-${{ runner.os }}-full-${{ hashFiles('megarepo.lock') }}" - name: Sync megarepo dependencies env: GITHUB_TOKEN: ${{ github.token }} MEGAREPO_STORE: '${{ runner.temp }}/megarepo-store' run: | __genie_ci_retry_script='${{ runner.temp }}/composition-state/ci-runtime/run-with-nix-gc-race-retry.sh' bash "$__genie_ci_retry_script" 'Sync megarepo dependencies' 'EU_REV=$(jq -r '\''.members["effect-utils"].commit'\'' megarepo.lock) if [ -z "$EU_REV" ] || [ "$EU_REV" = "null" ]; then echo '\''::error::megarepo.lock missing members["effect-utils"].commit'\'' exit 1 fi mkdir -p "$MEGAREPO_STORE" echo "Using job-local megarepo store: $MEGAREPO_STORE" if [ -n "${GITHUB_ENV:-}" ]; then printf '\''MEGAREPO_STORE=%s\n'\'' "$MEGAREPO_STORE" >> "$GITHUB_ENV" fi nix run --no-write-lock-file "github:overengineeringstudio/effect-utils/$EU_REV#megarepo" -- apply --all' shell: bash - name: Save megarepo store if: ${{ success() && steps.restore-megarepo-store.outputs.cache-hit != 'true' }} uses: actions/cache/save@v4 with: path: '${{ runner.temp }}/megarepo-store' key: "megarepo-store-v1-${{ runner.os }}-full-${{ hashFiles('megarepo.lock') }}" - name: Use pinned devenv from lock run: | cd "${GITHUB_WORKSPACE:-$PWD}" && DEVENV_REV=$(jq -r .nodes.devenv.locked.rev 'devenv.lock') if [ -z "$DEVENV_REV" ] || [ "$DEVENV_REV" = "null" ]; then printf '::error::%s missing .nodes.devenv.locked.rev\n' 'devenv.lock' exit 1 fi echo "DEVENV_REV=$DEVENV_REV" >> "$GITHUB_ENV" echo "Pinned devenv rev: $DEVENV_REV" shell: bash - name: Isolate pnpm state shell: bash run: | cd "${GITHUB_WORKSPACE:-$PWD}" && set -euo pipefail mkdir -p "${{ runner.temp }}/composition-state/pnpm-store-pure-v1" "${{ runner.temp }}/composition-state/pnpm-home" .devenv member_store=.devenv/pnpm-store-pure-v1 if [ -L "$member_store" ]; then if [ "$(readlink "$member_store")" != "${{ runner.temp }}/composition-state/pnpm-store-pure-v1" ]; then echo "::error::owned member pnpm store symlink has the wrong target: $member_store" >&2 exit 1 fi elif [ -e "$member_store" ]; then echo "::error::refusing non-symlink owned member pnpm store path: $member_store" >&2 exit 1 else ln -s "${{ runner.temp }}/composition-state/pnpm-store-pure-v1" "$member_store" fi echo "PNPM_STORE_DIR=${{ runner.temp }}/composition-state/pnpm-store-pure-v1" >> "$GITHUB_ENV" echo "PNPM_CONFIG_STORE_DIR=${{ runner.temp }}/composition-state/pnpm-store-pure-v1" >> "$GITHUB_ENV" echo "PNPM_HOME=${{ runner.temp }}/composition-state/pnpm-home" >> "$GITHUB_ENV" - id: restore-pnpm-state name: Restore pnpm state uses: actions/cache/restore@v4 with: path: | ${{ runner.temp }}/composition-state/pnpm-home ${{ runner.temp }}/composition-state/pnpm-store-pure-v1 key: "livestore-pnpm-state-v1-v3-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/pnpm-lock.yaml') }}" - name: Resolve devenv env: GITHUB_TOKEN: ${{ github.token }} run: | __genie_ci_retry_script='${{ runner.temp }}/composition-state/ci-runtime/run-with-nix-gc-race-retry.sh' bash "$__genie_ci_retry_script" 'Resolve devenv' '__genie_ci_retry_script='\''${{ runner.temp }}/composition-state/ci-runtime/run-with-nix-gc-race-retry.sh'\'' bash "$__genie_ci_retry_script" '\''resolve devenv (devenv.lock)'\'' '\''cd "${GITHUB_WORKSPACE:-$PWD}" && '\''"'\''"'\''${{ runner.temp }}/composition-state/ci-runtime/resolve-devenv.sh'\''"'\''"'\'' '\''"'\''"'\''devenv.lock'\''"'\''"'\'''\''' shell: bash - name: Generate release plan from Changesets run: | __genie_ci_retry_script='${{ runner.temp }}/composition-state/ci-runtime/run-with-nix-gc-race-retry.sh' bash "$__genie_ci_retry_script" 'devenv tasks run release:changeset:version' 'cd "${GITHUB_WORKSPACE:-$PWD}" && if [ -n "${NIX_CONFIG:-}" ]; then NIX_CONFIG_WITH_APPEND=$(printf '"'"'%s\n%s'"'"' "$NIX_CONFIG" '"'"'restrict-eval = false'"'"'); else NIX_CONFIG_WITH_APPEND='"'"'restrict-eval = false'"'"'; fi; NIX_CONFIG="$NIX_CONFIG_WITH_APPEND" DEVENV_TASK_PASSTHROUGH=1 DEVENV_TUI=false "${DEVENV_BIN:?DEVENV_BIN not set}" tasks run release:changeset:version' env: LIVESTORE_NPM_TAG: ${{ inputs.npm_tag }} - name: Extract release notes run: | __genie_ci_retry_script='${{ runner.temp }}/composition-state/ci-runtime/run-with-nix-gc-race-retry.sh' bash "$__genie_ci_retry_script" 'devenv tasks run release:notes:extract' 'cd "${GITHUB_WORKSPACE:-$PWD}" && if [ -n "${NIX_CONFIG:-}" ]; then NIX_CONFIG_WITH_APPEND=$(printf '"'"'%s\n%s'"'"' "$NIX_CONFIG" '"'"'restrict-eval = false'"'"'); else NIX_CONFIG_WITH_APPEND='"'"'restrict-eval = false'"'"'; fi; NIX_CONFIG="$NIX_CONFIG_WITH_APPEND" DEVENV_TASK_PASSTHROUGH=1 DEVENV_TUI=false "${DEVENV_BIN:?DEVENV_BIN not set}" tasks run release:notes:extract' - name: Open release plan PR env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} LIVESTORE_NPM_TAG: ${{ inputs.npm_tag }} run: | set -euo pipefail LIVESTORE_RELEASE_VERSION="$(jq -r '.version' release/release-plan.json)" : "${LIVESTORE_RELEASE_VERSION:?Missing generated release version}" : "${LIVESTORE_NPM_TAG:?Missing npm tag}" git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" branch="automation/release-$LIVESTORE_RELEASE_VERSION" git checkout -B "$branch" git add \ .changeset \ package.json \ pnpm-lock.yaml \ release/devtools-artifact.json \ release/release-notes.md \ release/release-plan.json \ release/version.json \ docs/package.json \ docs/src/content/_assets/code/package.json \ examples \ packages \ tests if git diff --cached --quiet; then echo "Release plan already current." else git commit -m "Prepare LiveStore $LIVESTORE_RELEASE_VERSION release" git fetch origin "refs/heads/$branch:refs/remotes/origin/$branch" || true git push --force-with-lease="refs/heads/$branch" origin "$branch" fi body="$(cat </dev/null 2>&1; then gh pr edit "$branch" --repo "$GITHUB_REPOSITORY" --title "Prepare LiveStore $LIVESTORE_RELEASE_VERSION release" --body "$body" else gh pr create \ --repo "$GITHUB_REPOSITORY" \ --base main \ --head "$branch" \ --title "Prepare LiveStore $LIVESTORE_RELEASE_VERSION release" \ --body "$body" fi gh workflow run ci.yml --repo "$GITHUB_REPOSITORY" --ref "$branch" gh workflow run release.yml --repo "$GITHUB_REPOSITORY" --ref "$branch" \ -f mode=validate-release-plan \ -f npm_tag="$LIVESTORE_NPM_TAG" # Stable (npm_tag=latest) release PRs are gated by a human reviewer. For # prerelease channels (dev, next, etc.) the release PR is fully automated, so # auto-merge is enabled to drive the publish on green CI. if [ "$LIVESTORE_NPM_TAG" = "latest" ]; then echo "npm_tag=latest: leaving auto-merge disabled; this PR requires a human ready-for-review and merge." elif gh pr view "$branch" --repo "$GITHUB_REPOSITORY" --json autoMergeRequest --jq '.autoMergeRequest != null' | grep -qx true; then echo "Auto-merge already enabled for $branch." else gh pr merge "$branch" --repo "$GITHUB_REPOSITORY" --auto --merge fi validate-release-plan: if: github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && inputs.mode == 'validate-release-plan') runs-on: ubuntu-24.04 defaults: run: shell: bash steps: - uses: actions/checkout@v6 with: persist-credentials: false - name: Install Nix uses: DeterminateSystems/determinate-nix-action@v3 env: GITHUB_TOKEN: ${{ github.token }} with: extra-conf: | experimental-features = nix-command flakes accept-flake-config = true extra-substituters = https://devenv.cachix.org extra-trusted-public-keys = devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw= access-tokens = github.com=${{ github.token }} extra-substituters = https://cache.nixos.org extra-trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= summarize: true - name: Prepare CI helper scripts shell: bash run: | cd "${GITHUB_WORKSPACE:-$PWD}" && set -euo pipefail scripts_src='genie/ci-scripts' scripts_dst='${{ runner.temp }}/composition-state/ci-runtime' if [ ! -d "$scripts_src" ]; then echo "::error::CI helper script directory is missing: $scripts_src" exit 1 fi rm -rf "$scripts_dst" mkdir -p "$scripts_dst" cp -R "$scripts_src/." "$scripts_dst/" rm -f "$scripts_dst"/*.genie.ts chmod +x "$scripts_dst"/*.sh - name: Provide cachix CLI from nixpkgs shell: bash env: GITHUB_TOKEN: ${{ github.token }} run: | set -euo pipefail out=$(nix build --no-link --print-out-paths nixpkgs#cachix) echo "$out/bin" >> "$GITHUB_PATH" - name: Enable Cachix cache uses: cachix/cachix-action@v17 with: name: livestore skipPush: true - name: Restore megarepo store id: restore-megarepo-store uses: actions/cache/restore@v4 with: path: '${{ runner.temp }}/megarepo-store' key: "megarepo-store-v1-${{ runner.os }}-full-${{ hashFiles('megarepo.lock') }}" - name: Sync megarepo dependencies env: GITHUB_TOKEN: ${{ github.token }} MEGAREPO_STORE: '${{ runner.temp }}/megarepo-store' run: | __genie_ci_retry_script='${{ runner.temp }}/composition-state/ci-runtime/run-with-nix-gc-race-retry.sh' bash "$__genie_ci_retry_script" 'Sync megarepo dependencies' 'EU_REV=$(jq -r '\''.members["effect-utils"].commit'\'' megarepo.lock) if [ -z "$EU_REV" ] || [ "$EU_REV" = "null" ]; then echo '\''::error::megarepo.lock missing members["effect-utils"].commit'\'' exit 1 fi mkdir -p "$MEGAREPO_STORE" echo "Using job-local megarepo store: $MEGAREPO_STORE" if [ -n "${GITHUB_ENV:-}" ]; then printf '\''MEGAREPO_STORE=%s\n'\'' "$MEGAREPO_STORE" >> "$GITHUB_ENV" fi nix run --no-write-lock-file "github:overengineeringstudio/effect-utils/$EU_REV#megarepo" -- apply --all' shell: bash - name: Save megarepo store if: ${{ success() && steps.restore-megarepo-store.outputs.cache-hit != 'true' }} uses: actions/cache/save@v4 with: path: '${{ runner.temp }}/megarepo-store' key: "megarepo-store-v1-${{ runner.os }}-full-${{ hashFiles('megarepo.lock') }}" - name: Use pinned devenv from lock run: | cd "${GITHUB_WORKSPACE:-$PWD}" && DEVENV_REV=$(jq -r .nodes.devenv.locked.rev 'devenv.lock') if [ -z "$DEVENV_REV" ] || [ "$DEVENV_REV" = "null" ]; then printf '::error::%s missing .nodes.devenv.locked.rev\n' 'devenv.lock' exit 1 fi echo "DEVENV_REV=$DEVENV_REV" >> "$GITHUB_ENV" echo "Pinned devenv rev: $DEVENV_REV" shell: bash - name: Isolate pnpm state shell: bash run: | cd "${GITHUB_WORKSPACE:-$PWD}" && set -euo pipefail mkdir -p "${{ runner.temp }}/composition-state/pnpm-store-pure-v1" "${{ runner.temp }}/composition-state/pnpm-home" .devenv member_store=.devenv/pnpm-store-pure-v1 if [ -L "$member_store" ]; then if [ "$(readlink "$member_store")" != "${{ runner.temp }}/composition-state/pnpm-store-pure-v1" ]; then echo "::error::owned member pnpm store symlink has the wrong target: $member_store" >&2 exit 1 fi elif [ -e "$member_store" ]; then echo "::error::refusing non-symlink owned member pnpm store path: $member_store" >&2 exit 1 else ln -s "${{ runner.temp }}/composition-state/pnpm-store-pure-v1" "$member_store" fi echo "PNPM_STORE_DIR=${{ runner.temp }}/composition-state/pnpm-store-pure-v1" >> "$GITHUB_ENV" echo "PNPM_CONFIG_STORE_DIR=${{ runner.temp }}/composition-state/pnpm-store-pure-v1" >> "$GITHUB_ENV" echo "PNPM_HOME=${{ runner.temp }}/composition-state/pnpm-home" >> "$GITHUB_ENV" - id: restore-pnpm-state name: Restore pnpm state uses: actions/cache/restore@v4 with: path: | ${{ runner.temp }}/composition-state/pnpm-home ${{ runner.temp }}/composition-state/pnpm-store-pure-v1 key: "livestore-pnpm-state-v1-v3-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/pnpm-lock.yaml') }}" - name: Resolve devenv env: GITHUB_TOKEN: ${{ github.token }} run: | __genie_ci_retry_script='${{ runner.temp }}/composition-state/ci-runtime/run-with-nix-gc-race-retry.sh' bash "$__genie_ci_retry_script" 'Resolve devenv' '__genie_ci_retry_script='\''${{ runner.temp }}/composition-state/ci-runtime/run-with-nix-gc-race-retry.sh'\'' bash "$__genie_ci_retry_script" '\''resolve devenv (devenv.lock)'\'' '\''cd "${GITHUB_WORKSPACE:-$PWD}" && '\''"'\''"'\''${{ runner.temp }}/composition-state/ci-runtime/resolve-devenv.sh'\''"'\''"'\'' '\''"'\''"'\''devenv.lock'\''"'\''"'\'''\''' shell: bash - name: Select release plan for validation run: | set -euo pipefail use_synthetic_plan=false if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then if [ "$GITHUB_BASE_REF" = "docs/stable" ]; then exit 0 fi git fetch origin "${{ github.base_ref }}" --depth=1 if ! git diff --name-only "origin/${{ github.base_ref }}...HEAD" | grep -qx 'release/release-plan.json'; then use_synthetic_plan=true fi elif [ ! -f release/release-plan.json ]; then use_synthetic_plan=true fi if [ "$use_synthetic_plan" = "false" ]; then exit 0 fi mkdir -p release # PRs that touch release machinery but do not carry an actual release plan still # need to exercise package publishing and DevTools repacking. Use a unique, # unpublished prerelease instead of the checked-in package version: current dev # versions can already exist on npm, while snapshot versions intentionally # belong to the separate snapshot publisher. short_sha="${GITHUB_SHA:0:12}" version="0.0.0-ci.release-validation.$short_sha" npm_tag="next" jq -n \ --arg version "$version" \ --arg npmTag "$npm_tag" \ '{ schemaVersion: 1, version: $version, npmTag: $npmTag }' > release/release-plan.json - name: Dry-run stable package publish if: github.event_name != 'pull_request' || github.base_ref != 'docs/stable' run: | __genie_ci_retry_script='${{ runner.temp }}/composition-state/ci-runtime/run-with-nix-gc-race-retry.sh' bash "$__genie_ci_retry_script" 'devenv tasks run release:stable:dryrun' 'cd "${GITHUB_WORKSPACE:-$PWD}" && if [ -n "${NIX_CONFIG:-}" ]; then NIX_CONFIG_WITH_APPEND=$(printf '"'"'%s\n%s'"'"' "$NIX_CONFIG" '"'"'restrict-eval = false'"'"'); else NIX_CONFIG_WITH_APPEND='"'"'restrict-eval = false'"'"'; fi; NIX_CONFIG="$NIX_CONFIG_WITH_APPEND" DEVENV_TASK_PASSTHROUGH=1 DEVENV_TUI=false "${DEVENV_BIN:?DEVENV_BIN not set}" tasks run release:stable:dryrun' - name: Validate published stable docs release if: github.event_name == 'pull_request' && github.base_ref == 'docs/stable' run: node .github/scripts/validate-stable-docs-release.mjs "$PR_HEAD_SHA" env: PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} - name: Test stable docs release validation run: node --test .github/scripts/validate-stable-docs-release.test.mjs - name: Read release plan run: | set -euo pipefail release_version="$(jq -r '.version' release/release-plan.json)" npm_tag="$(jq -r '.npmTag' release/release-plan.json)" : "${release_version:?Missing release version}" : "${npm_tag:?Missing npm tag}" echo "LIVESTORE_RELEASE_VERSION=$release_version" >> "$GITHUB_ENV" echo "LIVESTORE_NPM_TAG=$npm_tag" >> "$GITHUB_ENV" - name: Certify DevTools artifact liveness run: | __genie_ci_retry_script='${{ runner.temp }}/composition-state/ci-runtime/run-with-nix-gc-race-retry.sh' bash "$__genie_ci_retry_script" 'devenv tasks run release:devtools-artifact:certify-liveness:no-install' 'cd "${GITHUB_WORKSPACE:-$PWD}" && if [ -n "${NIX_CONFIG:-}" ]; then NIX_CONFIG_WITH_APPEND=$(printf '"'"'%s\n%s'"'"' "$NIX_CONFIG" '"'"'restrict-eval = false'"'"'); else NIX_CONFIG_WITH_APPEND='"'"'restrict-eval = false'"'"'; fi; NIX_CONFIG="$NIX_CONFIG_WITH_APPEND" DEVENV_TASK_PASSTHROUGH=1 DEVENV_TUI=false "${DEVENV_BIN:?DEVENV_BIN not set}" tasks run release:devtools-artifact:certify-liveness:no-install' - uses: actions/upload-artifact@v4 if: ${{ !cancelled() }} with: name: 'devtools-certification-playwright-artifacts-${{ github.job }}' path: | tests/integration/playwright-report/ tests/integration/test-results/devtools/ retention-days: 30 if-no-files-found: ignore - name: Dry-run DevTools artifact repack run: | __genie_ci_retry_script='${{ runner.temp }}/composition-state/ci-runtime/run-with-nix-gc-race-retry.sh' bash "$__genie_ci_retry_script" 'devenv tasks run release:devtools-artifact:repack-dryrun:no-install' 'cd "${GITHUB_WORKSPACE:-$PWD}" && if [ -n "${NIX_CONFIG:-}" ]; then NIX_CONFIG_WITH_APPEND=$(printf '"'"'%s\n%s'"'"' "$NIX_CONFIG" '"'"'restrict-eval = false'"'"'); else NIX_CONFIG_WITH_APPEND='"'"'restrict-eval = false'"'"'; fi; NIX_CONFIG="$NIX_CONFIG_WITH_APPEND" DEVENV_TASK_PASSTHROUGH=1 DEVENV_TUI=false "${DEVENV_BIN:?DEVENV_BIN not set}" tasks run release:devtools-artifact:repack-dryrun:no-install' - name: Save pnpm state if: ${{ success() && steps.restore-pnpm-state.outputs.cache-hit != 'true' }} uses: actions/cache/save@v4 with: path: | ${{ runner.temp }}/composition-state/pnpm-home ${{ runner.temp }}/composition-state/pnpm-store-pure-v1 key: "livestore-pnpm-state-v1-v3-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/pnpm-lock.yaml') }}" - name: Upload Nix diagnostics artifact if: failure() && env.NIX_STORE_DIAGNOSTICS_DIR != '' uses: actions/upload-artifact@v4 with: name: 'nix-store-diagnostics-${{ github.job }}-${{ runner.os }}-run-${{ github.run_id }}-attempt-${{ github.run_attempt }}' path: ${{ env.NIX_STORE_DIAGNOSTICS_DIR }} if-no-files-found: ignore retention-days: 14 publish-release: if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main' && inputs.mode == 'publish-release') runs-on: ubuntu-24.04 permissions: contents: write id-token: write env: GH_TOKEN: ${{ github.token }} defaults: run: shell: bash steps: - uses: actions/checkout@v6 with: persist-credentials: false - name: Install Nix uses: DeterminateSystems/determinate-nix-action@v3 env: GITHUB_TOKEN: ${{ github.token }} with: extra-conf: | experimental-features = nix-command flakes accept-flake-config = true extra-substituters = https://devenv.cachix.org extra-trusted-public-keys = devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw= access-tokens = github.com=${{ github.token }} extra-substituters = https://cache.nixos.org extra-trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= summarize: true - name: Prepare CI helper scripts shell: bash run: | cd "${GITHUB_WORKSPACE:-$PWD}" && set -euo pipefail scripts_src='genie/ci-scripts' scripts_dst='${{ runner.temp }}/composition-state/ci-runtime' if [ ! -d "$scripts_src" ]; then echo "::error::CI helper script directory is missing: $scripts_src" exit 1 fi rm -rf "$scripts_dst" mkdir -p "$scripts_dst" cp -R "$scripts_src/." "$scripts_dst/" rm -f "$scripts_dst"/*.genie.ts chmod +x "$scripts_dst"/*.sh - name: Provide cachix CLI from nixpkgs shell: bash env: GITHUB_TOKEN: ${{ github.token }} run: | set -euo pipefail out=$(nix build --no-link --print-out-paths nixpkgs#cachix) echo "$out/bin" >> "$GITHUB_PATH" - name: Enable Cachix cache uses: cachix/cachix-action@v17 with: name: livestore skipPush: true - name: Restore megarepo store id: restore-megarepo-store uses: actions/cache/restore@v4 with: path: '${{ runner.temp }}/megarepo-store' key: "megarepo-store-v1-${{ runner.os }}-full-${{ hashFiles('megarepo.lock') }}" - name: Sync megarepo dependencies env: GITHUB_TOKEN: ${{ github.token }} MEGAREPO_STORE: '${{ runner.temp }}/megarepo-store' run: | __genie_ci_retry_script='${{ runner.temp }}/composition-state/ci-runtime/run-with-nix-gc-race-retry.sh' bash "$__genie_ci_retry_script" 'Sync megarepo dependencies' 'EU_REV=$(jq -r '\''.members["effect-utils"].commit'\'' megarepo.lock) if [ -z "$EU_REV" ] || [ "$EU_REV" = "null" ]; then echo '\''::error::megarepo.lock missing members["effect-utils"].commit'\'' exit 1 fi mkdir -p "$MEGAREPO_STORE" echo "Using job-local megarepo store: $MEGAREPO_STORE" if [ -n "${GITHUB_ENV:-}" ]; then printf '\''MEGAREPO_STORE=%s\n'\'' "$MEGAREPO_STORE" >> "$GITHUB_ENV" fi nix run --no-write-lock-file "github:overengineeringstudio/effect-utils/$EU_REV#megarepo" -- apply --all' shell: bash - name: Save megarepo store if: ${{ success() && steps.restore-megarepo-store.outputs.cache-hit != 'true' }} uses: actions/cache/save@v4 with: path: '${{ runner.temp }}/megarepo-store' key: "megarepo-store-v1-${{ runner.os }}-full-${{ hashFiles('megarepo.lock') }}" - name: Use pinned devenv from lock run: | cd "${GITHUB_WORKSPACE:-$PWD}" && DEVENV_REV=$(jq -r .nodes.devenv.locked.rev 'devenv.lock') if [ -z "$DEVENV_REV" ] || [ "$DEVENV_REV" = "null" ]; then printf '::error::%s missing .nodes.devenv.locked.rev\n' 'devenv.lock' exit 1 fi echo "DEVENV_REV=$DEVENV_REV" >> "$GITHUB_ENV" echo "Pinned devenv rev: $DEVENV_REV" shell: bash - name: Isolate pnpm state shell: bash run: | cd "${GITHUB_WORKSPACE:-$PWD}" && set -euo pipefail mkdir -p "${{ runner.temp }}/composition-state/pnpm-store-pure-v1" "${{ runner.temp }}/composition-state/pnpm-home" .devenv member_store=.devenv/pnpm-store-pure-v1 if [ -L "$member_store" ]; then if [ "$(readlink "$member_store")" != "${{ runner.temp }}/composition-state/pnpm-store-pure-v1" ]; then echo "::error::owned member pnpm store symlink has the wrong target: $member_store" >&2 exit 1 fi elif [ -e "$member_store" ]; then echo "::error::refusing non-symlink owned member pnpm store path: $member_store" >&2 exit 1 else ln -s "${{ runner.temp }}/composition-state/pnpm-store-pure-v1" "$member_store" fi echo "PNPM_STORE_DIR=${{ runner.temp }}/composition-state/pnpm-store-pure-v1" >> "$GITHUB_ENV" echo "PNPM_CONFIG_STORE_DIR=${{ runner.temp }}/composition-state/pnpm-store-pure-v1" >> "$GITHUB_ENV" echo "PNPM_HOME=${{ runner.temp }}/composition-state/pnpm-home" >> "$GITHUB_ENV" - id: restore-pnpm-state name: Restore pnpm state uses: actions/cache/restore@v4 with: path: | ${{ runner.temp }}/composition-state/pnpm-home ${{ runner.temp }}/composition-state/pnpm-store-pure-v1 key: "livestore-pnpm-state-v1-v3-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/pnpm-lock.yaml') }}" - name: Resolve devenv env: GITHUB_TOKEN: ${{ github.token }} run: | __genie_ci_retry_script='${{ runner.temp }}/composition-state/ci-runtime/run-with-nix-gc-race-retry.sh' bash "$__genie_ci_retry_script" 'Resolve devenv' '__genie_ci_retry_script='\''${{ runner.temp }}/composition-state/ci-runtime/run-with-nix-gc-race-retry.sh'\'' bash "$__genie_ci_retry_script" '\''resolve devenv (devenv.lock)'\'' '\''cd "${GITHUB_WORKSPACE:-$PWD}" && '\''"'\''"'\''${{ runner.temp }}/composition-state/ci-runtime/resolve-devenv.sh'\''"'\''"'\'' '\''"'\''"'\''devenv.lock'\''"'\''"'\'''\''' shell: bash - name: Read release plan run: | set -euo pipefail release_version="$(jq -r '.version' release/release-plan.json)" npm_tag="$(jq -r '.npmTag' release/release-plan.json)" : "${release_version:?Missing release version}" : "${npm_tag:?Missing npm tag}" echo "LIVESTORE_RELEASE_VERSION=$release_version" >> "$GITHUB_ENV" echo "LIVESTORE_NPM_TAG=$npm_tag" >> "$GITHUB_ENV" - name: Assert tokenless npm trusted publishing run: | set -euo pipefail if [ -n "${NODE_AUTH_TOKEN:-}" ] || [ -n "${NPM_TOKEN:-}" ]; then echo "npm publishing must use trusted publishing; token auth is not allowed in this job." >&2 exit 1 fi - name: Set OTEL_EXPORTER_OTLP_HEADERS environment variable env: GRAFANA_CLOUD_OTLP_INSTANCE_ID: '1227256' GRAFANA_CLOUD_OTLP_API_KEY: ${{ secrets.GRAFANA_CLOUD_OTLP_API_KEY }} run: | echo "OTEL_EXPORTER_OTLP_HEADERS=Authorization=Basic $(echo -n "$GRAFANA_CLOUD_OTLP_INSTANCE_ID:$GRAFANA_CLOUD_OTLP_API_KEY" | base64 -w 0)" >> $GITHUB_ENV echo "GRAFANA_ENDPOINT=https://livestore.grafana.net" >> $GITHUB_ENV echo "OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp-gateway-prod-us-east-2.grafana.net/otlp" >> $GITHUB_ENV # Disable in Vite (otherwise CORS issues) echo "VITE_OTEL_EXPORTER_OTLP_ENDPOINT=" >> $GITHUB_ENV - name: Publish stable package release run: | __genie_ci_retry_script='${{ runner.temp }}/composition-state/ci-runtime/run-with-nix-gc-race-retry.sh' bash "$__genie_ci_retry_script" 'devenv tasks run release:stable:publish' 'cd "${GITHUB_WORKSPACE:-$PWD}" && if [ -n "${NIX_CONFIG:-}" ]; then NIX_CONFIG_WITH_APPEND=$(printf '"'"'%s\n%s'"'"' "$NIX_CONFIG" '"'"'restrict-eval = false'"'"'); else NIX_CONFIG_WITH_APPEND='"'"'restrict-eval = false'"'"'; fi; NIX_CONFIG="$NIX_CONFIG_WITH_APPEND" DEVENV_TASK_PASSTHROUGH=1 DEVENV_TUI=false "${DEVENV_BIN:?DEVENV_BIN not set}" tasks run release:stable:publish' - name: Certify DevTools artifact liveness run: | __genie_ci_retry_script='${{ runner.temp }}/composition-state/ci-runtime/run-with-nix-gc-race-retry.sh' bash "$__genie_ci_retry_script" 'devenv tasks run release:devtools-artifact:certify-liveness:no-install' 'cd "${GITHUB_WORKSPACE:-$PWD}" && if [ -n "${NIX_CONFIG:-}" ]; then NIX_CONFIG_WITH_APPEND=$(printf '"'"'%s\n%s'"'"' "$NIX_CONFIG" '"'"'restrict-eval = false'"'"'); else NIX_CONFIG_WITH_APPEND='"'"'restrict-eval = false'"'"'; fi; NIX_CONFIG="$NIX_CONFIG_WITH_APPEND" DEVENV_TASK_PASSTHROUGH=1 DEVENV_TUI=false "${DEVENV_BIN:?DEVENV_BIN not set}" tasks run release:devtools-artifact:certify-liveness:no-install' - uses: actions/upload-artifact@v4 if: ${{ !cancelled() }} with: name: 'devtools-certification-playwright-artifacts-${{ github.job }}' path: | tests/integration/playwright-report/ tests/integration/test-results/devtools/ retention-days: 30 if-no-files-found: ignore - name: Publish DevTools artifact release run: | __genie_ci_retry_script='${{ runner.temp }}/composition-state/ci-runtime/run-with-nix-gc-race-retry.sh' bash "$__genie_ci_retry_script" 'devenv tasks run release:devtools-artifact:publish:no-install' 'cd "${GITHUB_WORKSPACE:-$PWD}" && if [ -n "${NIX_CONFIG:-}" ]; then NIX_CONFIG_WITH_APPEND=$(printf '"'"'%s\n%s'"'"' "$NIX_CONFIG" '"'"'restrict-eval = false'"'"'); else NIX_CONFIG_WITH_APPEND='"'"'restrict-eval = false'"'"'; fi; NIX_CONFIG="$NIX_CONFIG_WITH_APPEND" DEVENV_TASK_PASSTHROUGH=1 DEVENV_TUI=false "${DEVENV_BIN:?DEVENV_BIN not set}" tasks run release:devtools-artifact:publish:no-install' - name: Save pnpm state if: ${{ success() && steps.restore-pnpm-state.outputs.cache-hit != 'true' }} uses: actions/cache/save@v4 with: path: | ${{ runner.temp }}/composition-state/pnpm-home ${{ runner.temp }}/composition-state/pnpm-store-pure-v1 key: "livestore-pnpm-state-v1-v3-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/pnpm-lock.yaml') }}" - name: Upload Nix diagnostics artifact if: failure() && env.NIX_STORE_DIAGNOSTICS_DIR != '' uses: actions/upload-artifact@v4 with: name: 'nix-store-diagnostics-${{ github.job }}-${{ runner.os }}-run-${{ github.run_id }}-attempt-${{ github.run_attempt }}' path: ${{ env.NIX_STORE_DIAGNOSTICS_DIR }} if-no-files-found: ignore retention-days: 14 publish-snapshot-version: if: (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push') || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main' && inputs.mode == 'publish-snapshot') runs-on: ubuntu-24.04 permissions: contents: write id-token: write env: GH_TOKEN: ${{ github.token }} defaults: run: shell: bash steps: - name: Checkout uses: actions/checkout@v4 with: ref: ${{ github.event.workflow_run.head_sha || github.sha }} - name: Install Nix uses: DeterminateSystems/determinate-nix-action@v3 env: GITHUB_TOKEN: ${{ github.token }} with: extra-conf: | experimental-features = nix-command flakes accept-flake-config = true extra-substituters = https://devenv.cachix.org extra-trusted-public-keys = devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw= access-tokens = github.com=${{ github.token }} extra-substituters = https://cache.nixos.org extra-trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= summarize: true - name: Prepare CI helper scripts shell: bash run: | cd "${GITHUB_WORKSPACE:-$PWD}" && set -euo pipefail scripts_src='genie/ci-scripts' scripts_dst='${{ runner.temp }}/composition-state/ci-runtime' if [ ! -d "$scripts_src" ]; then echo "::error::CI helper script directory is missing: $scripts_src" exit 1 fi rm -rf "$scripts_dst" mkdir -p "$scripts_dst" cp -R "$scripts_src/." "$scripts_dst/" rm -f "$scripts_dst"/*.genie.ts chmod +x "$scripts_dst"/*.sh - name: Provide cachix CLI from nixpkgs shell: bash env: GITHUB_TOKEN: ${{ github.token }} run: | set -euo pipefail out=$(nix build --no-link --print-out-paths nixpkgs#cachix) echo "$out/bin" >> "$GITHUB_PATH" - name: Enable Cachix cache uses: cachix/cachix-action@v17 with: name: livestore skipPush: true - name: Restore megarepo store id: restore-megarepo-store uses: actions/cache/restore@v4 with: path: '${{ runner.temp }}/megarepo-store' key: "megarepo-store-v1-${{ runner.os }}-full-${{ hashFiles('megarepo.lock') }}" - name: Sync megarepo dependencies env: GITHUB_TOKEN: ${{ github.token }} MEGAREPO_STORE: '${{ runner.temp }}/megarepo-store' run: | __genie_ci_retry_script='${{ runner.temp }}/composition-state/ci-runtime/run-with-nix-gc-race-retry.sh' bash "$__genie_ci_retry_script" 'Sync megarepo dependencies' 'EU_REV=$(jq -r '\''.members["effect-utils"].commit'\'' megarepo.lock) if [ -z "$EU_REV" ] || [ "$EU_REV" = "null" ]; then echo '\''::error::megarepo.lock missing members["effect-utils"].commit'\'' exit 1 fi mkdir -p "$MEGAREPO_STORE" echo "Using job-local megarepo store: $MEGAREPO_STORE" if [ -n "${GITHUB_ENV:-}" ]; then printf '\''MEGAREPO_STORE=%s\n'\'' "$MEGAREPO_STORE" >> "$GITHUB_ENV" fi nix run --no-write-lock-file "github:overengineeringstudio/effect-utils/$EU_REV#megarepo" -- apply --all' shell: bash - name: Save megarepo store if: ${{ success() && steps.restore-megarepo-store.outputs.cache-hit != 'true' }} uses: actions/cache/save@v4 with: path: '${{ runner.temp }}/megarepo-store' key: "megarepo-store-v1-${{ runner.os }}-full-${{ hashFiles('megarepo.lock') }}" - name: Use pinned devenv from lock run: | cd "${GITHUB_WORKSPACE:-$PWD}" && DEVENV_REV=$(jq -r .nodes.devenv.locked.rev 'devenv.lock') if [ -z "$DEVENV_REV" ] || [ "$DEVENV_REV" = "null" ]; then printf '::error::%s missing .nodes.devenv.locked.rev\n' 'devenv.lock' exit 1 fi echo "DEVENV_REV=$DEVENV_REV" >> "$GITHUB_ENV" echo "Pinned devenv rev: $DEVENV_REV" shell: bash - name: Isolate pnpm state shell: bash run: | cd "${GITHUB_WORKSPACE:-$PWD}" && set -euo pipefail mkdir -p "${{ runner.temp }}/composition-state/pnpm-store-pure-v1" "${{ runner.temp }}/composition-state/pnpm-home" .devenv member_store=.devenv/pnpm-store-pure-v1 if [ -L "$member_store" ]; then if [ "$(readlink "$member_store")" != "${{ runner.temp }}/composition-state/pnpm-store-pure-v1" ]; then echo "::error::owned member pnpm store symlink has the wrong target: $member_store" >&2 exit 1 fi elif [ -e "$member_store" ]; then echo "::error::refusing non-symlink owned member pnpm store path: $member_store" >&2 exit 1 else ln -s "${{ runner.temp }}/composition-state/pnpm-store-pure-v1" "$member_store" fi echo "PNPM_STORE_DIR=${{ runner.temp }}/composition-state/pnpm-store-pure-v1" >> "$GITHUB_ENV" echo "PNPM_CONFIG_STORE_DIR=${{ runner.temp }}/composition-state/pnpm-store-pure-v1" >> "$GITHUB_ENV" echo "PNPM_HOME=${{ runner.temp }}/composition-state/pnpm-home" >> "$GITHUB_ENV" - id: restore-pnpm-state name: Restore pnpm state uses: actions/cache/restore@v4 with: path: | ${{ runner.temp }}/composition-state/pnpm-home ${{ runner.temp }}/composition-state/pnpm-store-pure-v1 key: "livestore-pnpm-state-v1-v3-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/pnpm-lock.yaml') }}" - name: Resolve devenv env: GITHUB_TOKEN: ${{ github.token }} run: | __genie_ci_retry_script='${{ runner.temp }}/composition-state/ci-runtime/run-with-nix-gc-race-retry.sh' bash "$__genie_ci_retry_script" 'Resolve devenv' '__genie_ci_retry_script='\''${{ runner.temp }}/composition-state/ci-runtime/run-with-nix-gc-race-retry.sh'\'' bash "$__genie_ci_retry_script" '\''resolve devenv (devenv.lock)'\'' '\''cd "${GITHUB_WORKSPACE:-$PWD}" && '\''"'\''"'\''${{ runner.temp }}/composition-state/ci-runtime/resolve-devenv.sh'\''"'\''"'\'' '\''"'\''"'\''devenv.lock'\''"'\''"'\'''\''' shell: bash - name: Assert tokenless npm trusted publishing run: | set -euo pipefail if [ -n "${NODE_AUTH_TOKEN:-}" ] || [ -n "${NPM_TOKEN:-}" ]; then echo "npm snapshot publishing must use trusted publishing; token auth is not allowed in this job." >&2 exit 1 fi - name: Publish snapshot version run: | __genie_ci_retry_script='${{ runner.temp }}/composition-state/ci-runtime/run-with-nix-gc-race-retry.sh' bash "$__genie_ci_retry_script" 'devenv tasks run release:snapshot:git-sha' 'cd "${GITHUB_WORKSPACE:-$PWD}" && if [ -n "${NIX_CONFIG:-}" ]; then NIX_CONFIG_WITH_APPEND=$(printf '"'"'%s\n%s'"'"' "$NIX_CONFIG" '"'"'restrict-eval = false'"'"'); else NIX_CONFIG_WITH_APPEND='"'"'restrict-eval = false'"'"'; fi; NIX_CONFIG="$NIX_CONFIG_WITH_APPEND" DEVENV_TASK_PASSTHROUGH=1 DEVENV_TUI=false "${DEVENV_BIN:?DEVENV_BIN not set}" tasks run release:snapshot:git-sha' env: GIT_SHA: ${{ github.event.workflow_run.head_sha || github.sha }} - name: Publish DevTools artifact snapshot run: | __genie_ci_retry_script='${{ runner.temp }}/composition-state/ci-runtime/run-with-nix-gc-race-retry.sh' bash "$__genie_ci_retry_script" 'devenv tasks run release:devtools-artifact:publish' 'cd "${GITHUB_WORKSPACE:-$PWD}" && if [ -n "${NIX_CONFIG:-}" ]; then NIX_CONFIG_WITH_APPEND=$(printf '"'"'%s\n%s'"'"' "$NIX_CONFIG" '"'"'restrict-eval = false'"'"'); else NIX_CONFIG_WITH_APPEND='"'"'restrict-eval = false'"'"'; fi; NIX_CONFIG="$NIX_CONFIG_WITH_APPEND" DEVENV_TASK_PASSTHROUGH=1 DEVENV_TUI=false "${DEVENV_BIN:?DEVENV_BIN not set}" tasks run release:devtools-artifact:publish' env: LIVESTORE_DEVTOOLS_OUT_DIR: '${{ runner.temp }}/livestore-devtools-snapshot' LIVESTORE_RELEASE_VERSION: '0.0.0-snapshot-${{ github.event.workflow_run.head_sha || github.sha }}' - name: Upload DevTools Chrome snapshot artifact uses: actions/upload-artifact@v4 with: name: 'livestore-devtools-chrome-0.0.0-snapshot-${{ github.event.workflow_run.head_sha || github.sha }}' path: '${{ runner.temp }}/livestore-devtools-snapshot/livestore-devtools-chrome-0.0.0-snapshot-${{ github.event.workflow_run.head_sha || github.sha }}.zip' if-no-files-found: error retention-days: 14 - name: Save pnpm state if: ${{ success() && steps.restore-pnpm-state.outputs.cache-hit != 'true' }} uses: actions/cache/save@v4 with: path: | ${{ runner.temp }}/composition-state/pnpm-home ${{ runner.temp }}/composition-state/pnpm-store-pure-v1 key: "livestore-pnpm-state-v1-v3-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/pnpm-lock.yaml') }}" - name: Upload Nix diagnostics artifact if: failure() && env.NIX_STORE_DIAGNOSTICS_DIR != '' uses: actions/upload-artifact@v4 with: name: 'nix-store-diagnostics-${{ github.job }}-${{ runner.os }}-run-${{ github.run_id }}-attempt-${{ github.run_attempt }}' path: ${{ env.NIX_STORE_DIAGNOSTICS_DIR }} if-no-files-found: ignore retention-days: 14