An open source design system that's fully customizable and agent ready
TypeScript
fix: skip unbootstrapped private canaries (#7943)
Cindy Zhang2a22d16e3d87
diff --git a/.github/scripts/release-publish-workflow.test.mjs b/.github/scripts/release-publish-workflow.test.mjsindex 73487339f1..c3c1b0ea3b 100644--- a/.github/scripts/release-publish-workflow.test.mjs+++ b/.github/scripts/release-publish-workflow.test.mjs@@ -1,6 +1,8 @@// Copyright (c) Meta Platforms, Inc. and affiliates.+import {spawnSync} from 'node:child_process';import fs from 'node:fs';+import os from 'node:os';import path from 'node:path';import {describe, expect, it} from 'vitest';import yaml from 'yaml';@@ -20,6 +22,84 @@ const canary = workflow.jobs.canary;const step = (job, name) =>job.steps.find(candidate => candidate.name === name);+function writeJson(root, relative, value) {+ const file = path.join(root, relative);+ fs.mkdirSync(path.dirname(file), {recursive: true});+ fs.writeFileSync(file, JSON.stringify(value, null, 2) + '\n');+}++function writeExecutable(root, name, contents) {+ const file = path.join(root, 'bin', name);+ fs.mkdirSync(path.dirname(file), {recursive: true});+ fs.writeFileSync(file, contents);+ fs.chmodSync(file, 0o755);+}++function runCanaryPublish({+ httpStatus,+ curlExitCode = '0',+ failingPackage = '',+}) {+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-canary-publish-'));+ const publishLog = path.join(root, 'publish.log');+ try {+ writeJson(root, 'packages/core/package.json', {+ name: '@astryxdesign/core',+ version: '0.7.4',+ });+ writeJson(root, 'packages/native/package.json', {+ name: '@astryxdesign/native',+ version: '0.1.0',+ private: true,+ astryx: {canaryOnly: true},+ });+ writeJson(root, 'packages/themes/neutral/package.json', {+ name: '@astryxdesign/theme-neutral',+ version: '0.7.4',+ });+ writeExecutable(+ root,+ 'curl',+ '#!/bin/sh\nprintf %s "$NATIVE_HTTP_STATUS"\nexit "$CURL_EXIT_CODE"\n',+ );+ writeExecutable(+ root,+ 'pnpm',+ '#!/bin/sh\nprintf "%s\\n" "$*" >> "$PUBLISH_LOG"\n' ++ '[ -z "$FAIL_PACKAGE" ] || case "$*" in *"$FAIL_PACKAGE"*) exit 1;; esac\n',+ );++ const runnerTemp = path.join(root, 'runner-temp');+ fs.mkdirSync(runnerTemp, {recursive: true});+ const result = spawnSync(+ 'bash',+ ['-c', step(canary, 'Publish canary versions').run],+ {+ cwd: root,+ encoding: 'utf8',+ env: {+ ...process.env,+ CURL_EXIT_CODE: curlExitCode,+ FAIL_PACKAGE: failingPackage,+ GITHUB_SHA: 'abcdef1234567890',+ NATIVE_HTTP_STATUS: httpStatus,+ PATH: `${path.join(root, 'bin')}:${process.env.PATH}`,+ PUBLISH_LOG: publishLog,+ RUNNER_TEMP: runnerTemp,+ },+ },+ );+ return {+ ...result,+ published: fs.existsSync(publishLog)+ ? fs.readFileSync(publishLog, 'utf8')+ : '',+ };+ } finally {+ fs.rmSync(root, {recursive: true, force: true});+ }+}+describe('stable and canary publication authority', () => {it('keeps stable explicit and canary limited to main pushes', () => {expect(stable.if).toBe("github.event_name == 'workflow_dispatch'");@@ -140,6 +220,59 @@ describe('stable and canary publication authority', () => {expect(canaryText).not.toContain('release-publish-receipt');});+ it('skips only an absent package that was private and canary-only', () => {+ const result = runCanaryPublish({httpStatus: '404'});++ expect(result.status).toBe(0);+ expect(result.stdout).toContain(+ 'Skipping absent private canary-only package @astryxdesign/native',+ );+ expect(result.published).toContain('publish ./packages/core');+ expect(result.published).toContain('publish ./packages/themes/neutral');+ expect(result.published).not.toContain('publish ./packages/native');+ });++ it('publishes a bootstrapped private canary-only package normally', () => {+ const result = runCanaryPublish({httpStatus: '200'});++ expect(result.status).toBe(0);+ expect(result.published).toContain('publish ./packages/native');+ });++ it('fails on registry errors instead of treating them as package absence', () => {+ const result = runCanaryPublish({httpStatus: '503'});++ expect(result.status).toBe(1);+ expect(result.stdout).toContain(+ 'Registry lookup for @astryxdesign/native returned HTTP 503',+ );+ expect(result.published).not.toContain('publish ./packages/native');+ });++ it('records a failed registry request and continues later packages', () => {+ const result = runCanaryPublish({httpStatus: '000', curlExitCode: '28'});++ expect(result.status).toBe(1);+ expect(result.stdout).toContain(+ 'Registry lookup for @astryxdesign/native returned HTTP 000',+ );+ expect(result.published).not.toContain('publish ./packages/native');+ expect(result.published).toContain('publish ./packages/themes/neutral');+ });++ it('still fails when a present package cannot publish', () => {+ const result = runCanaryPublish({+ failingPackage: 'packages/native',+ httpStatus: '200',+ });++ expect(result.status).toBe(1);+ expect(result.stdout).toContain(+ 'Canary publish failed for @astryxdesign/native',+ );+ expect(result.published).toContain('publish ./packages/native');+ });+it('validates every main merge-back against trusted policy and the immutable tag', () => {const mergeBack = ci.jobs['release-merge-back'];expect(mergeBack.if).toContain("github.base_ref == 'main'");diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex c17de096c0..c9d020e38f 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -248,8 +248,15 @@ jobs:echo "Publishing canary ${CANARY_VERSION}"+ # Remember which canaryOnly packages were private before this+ # ephemeral checkout removes the guard. Only those packages may be+ # skipped when their npm name has not been bootstrapped yet.+ PRIVATE_CANARY_PACKAGES="$RUNNER_TEMP/astryx-private-canary-packages.txt"+ : > "$PRIVATE_CANARY_PACKAGES"+ export PRIVATE_CANARY_PACKAGES+# Stamp canary version into all publishable packages. canaryOnly- # packages (e.g. lab) stay `private: true` in git as npm's hard+ # packages (for example Native) stay `private: true` in git as npm's hard# guarantee against a stable publish; here — in the ephemeral CI# checkout ONLY — we strip `private` so they publish to @canary.for pkg in packages/*/package.json packages/themes/*/package.json; do@@ -258,7 +265,10 @@ jobs:const p = JSON.parse(fs.readFileSync('$pkg','utf8'));if (!p.name?.startsWith('@astryxdesign/')) process.exit(0);if (p.private && !p.astryx?.canaryOnly) process.exit(0);- if (p.private && p.astryx?.canaryOnly) delete p.private;+ if (p.private && p.astryx?.canaryOnly) {+ fs.appendFileSync(process.env.PRIVATE_CANARY_PACKAGES, p.name + '\n');+ delete p.private;+ }p.version = '${CANARY_VERSION}';for (const dt of ['dependencies','peerDependencies','devDependencies']) {if (!p[dt]) continue;@@ -273,10 +283,10 @@ jobs:# Publish each package with --tag canary. Failures are collected and# the job still fails at the end (never `|| true`-swallowed), but one- # rejected publish no longer aborts the loop: when lab's first OIDC- # publish was rejected (no npm package/trust bootstrapped yet), every- # package after it in the loop (all seven themes) stopped receiving- # canaries. Publishes are per-package and idempotent, so attempting+ # rejected publish no longer aborts the loop: when a private+ # canary-only package's first OIDC publish is rejected because its npm+ # package/trust is not bootstrapped yet, packages after it still need+ # their canaries. Publishes are per-package and idempotent, so attempting# the rest is always safe.FAILED=""for pkg_dir in packages/* packages/themes/*; do@@ -286,6 +296,22 @@ jobs:IS_PUBLISHABLE=$(node -p "const p=require('./$pkg_dir/package.json'); (!p.private || p.astryx?.canaryOnly) && p.name?.startsWith('@astryxdesign/') ? 'yes' : 'no'")if [ "$IS_PUBLISHABLE" = "yes" ]; thenNAME=$(node -p "require('./$pkg_dir/package.json').name")+ if grep -Fxq "$NAME" "$PRIVATE_CANARY_PACKAGES"; then+ PACKAGE_URL=$(node -e "process.stdout.write(new URL(encodeURIComponent(process.argv[1]), 'https://registry.npmjs.org/').href)" "$NAME")+ HTTP_STATUS=$(curl --silent --show-error --output /dev/null --write-out '%{http_code}' --max-time 30 "$PACKAGE_URL" || true)+ case "$HTTP_STATUS" in+ 200) ;;+ 404)+ echo "::notice::Skipping absent private canary-only package ${NAME}; bootstrap it and register release.yml as its trusted publisher."+ continue+ ;;+ *)+ echo "::error::Registry lookup for ${NAME} returned HTTP ${HTTP_STATUS}"+ FAILED="${FAILED} ${NAME}"+ continue+ ;;+ esac+ fiecho "Publishing ${NAME}@${CANARY_VERSION}"if ! pnpm publish "./$pkg_dir" --tag canary --provenance --access public --no-git-checks; thenecho "::error::Canary publish failed for ${NAME}@${CANARY_VERSION}"