Clone any viral video with AI agents. Not just a script, the whole workflow: swap the face, the words, the B-roll, ship 100 variants in one command, and get your 100M views.
TypeScript agentic-aiaiai-agentsai-videocompilerdslffmpeggenerative-aillmmarkup-languagemonorepoplugin-systemprogramming-languagetext-to-videotypescriptvideovideo-automationvideo-clonevideo-editingvideo-generation
ci: publish tested artifacts without rebuilding
kashorin7a0952ae214d
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 5f149d78..1a6e315c 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -3,21 +3,30 @@ name: CIon:push:branches: [main]- # Nothing under docs/ is in tsconfig's include or reachable from the test suite, so- # documentation-only changes are intentionally excluded from this package CI.paths-ignore:- "docs/**"+ - "skills/**"+ - "design/**"+ - "**/*.md"pull_request:paths-ignore:- "docs/**"+ - "skills/**"+ - "design/**"+ - "**/*.md"workflow_dispatch:- workflow_call:++permissions:+ contents: readconcurrency:group: ci-${{ github.workflow }}-${{ github.ref }}cancel-in-progress: truejobs:+ package:+ uses: ./.github/workflows/npm-package.yml+check:# Windows-only breakage used to reach authors instead of this file — a render whose temporary# paths ran past the length a Windows path may be, a transcriber that opened a console windowdiff --git a/.github/workflows/npm-package.yml b/.github/workflows/npm-package.ymlindex 83ac5167..b2f9a5cb 100644--- a/.github/workflows/npm-package.yml+++ b/.github/workflows/npm-package.yml@@ -1,11 +1,6 @@name: npm package executionon:- pull_request:- paths-ignore:- - "docs/**"- - "skills/**"- - "design/**"workflow_dispatch:workflow_call:outputs:@@ -80,5 +75,13 @@ jobs:with:name: npm-packagepath: dist/release+ - name: Reuse npm downloads for the clean consumer installation+ uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4+ with:+ path: ${{ runner.temp }}/hypit-npm-downloads+ key: npm-consumer-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}+ restore-keys: npm-consumer-${{ runner.os }}-- name: Install the complete candidate, render and export outside the checkout+ env:+ npm_config_cache: ${{ runner.temp }}/hypit-npm-downloadsrun: npm run check:release-candidatediff --git a/.github/workflows/publish-npm.yml b/.github/workflows/publish-npm.ymlindex bc5f8dc4..2cd542b5 100644--- a/.github/workflows/publish-npm.yml+++ b/.github/workflows/publish-npm.yml@@ -1,37 +1,40 @@name: Publish npm-run-name: "npm ${{ github.event.release.tag_name || inputs.version }} — ${{ (github.event_name == 'release' || inputs.publish) && 'publish' || 'package only' }}"+run-name: "npm ${{ github.event.release.tag_name || inputs.candidate_run }} — ${{ (github.event_name == 'release' || inputs.publish) && 'publish' || 'inspect candidate' }}"on:release:types: [published]workflow_dispatch:inputs:- version:- description: "Version already committed in main's package.json"+ candidate_run:+ description: "Successful main CI run ID containing the tested npm-package artifact"type: stringrequired: truepublish:- description: "Publish to npm (unchecked: checks and downloadable package only)"+ description: "Publish the verified artifact to npm (unchecked: inspect only)"type: booleandefault: falsepackages:- description: "Optional space-separated package names to publish; empty publishes the complete candidate"+ description: "Optional space-separated package names; empty publishes the complete candidate"type: stringrequired: falsepermissions:contents: read+ actions: readconcurrency:group: publish-npmcancel-in-progress: falsejobs:- version:+ publish:if: github.event_name == 'release' || github.ref == 'refs/heads/main'runs-on: ubuntu-latest- outputs:- version: ${{ steps.version.outputs.version }}+ permissions:+ contents: write+ actions: read+ id-token: writesteps:- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0with:@@ -41,65 +44,48 @@ jobs:- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0with:node-version: 24- - name: Confirm version and main ancestry+ registry-url: https://registry.npmjs.org+ - name: Select a successful main CI candidate+ id: candidate+ env:+ GH_TOKEN: ${{ github.token }}+ CANDIDATE_RUN: ${{ inputs.candidate_run }}+ RELEASE_PRERELEASE: ${{ github.event.release.prerelease }}+ run: node scripts/select-release-run.mjs+ - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0+ with:+ name: npm-package+ path: release+ run-id: ${{ steps.candidate.outputs.run_id }}+ github-token: ${{ github.token }}+ - name: Confirm candidate version and package selectionid: versionenv:- EVENT_NAME: ${{ github.event_name }}RELEASE_TAG: ${{ github.event.release.tag_name }}- PRERELEASE: ${{ github.event.release.prerelease }}- EXPECTED_VERSION: ${{ inputs.version }}+ RELEASE_PACKAGES: ${{ inputs.packages }}run: |- git merge-base --is-ancestor HEAD origin/mainnode --input-type=module <<'JS'import { readFileSync, appendFileSync } from 'node:fs';- const { version } = JSON.parse(readFileSync('package.json', 'utf8'));- if (!/^\d+\.\d+\.\d+$/.test(version)) {- throw new Error('package.json must declare a stable npm version.');+ import { selectReleasePackages } from './scripts/release-candidate.mjs';+ const plan = JSON.parse(readFileSync('release/release-plan.json', 'utf8'));+ const version = plan.distribution?.version;+ if (plan.format !== 'hypit.release-plan@1' || !/^\d+\.\d+\.\d+$/.test(version ?? '')) {+ throw new Error('Candidate must declare a stable npm version.');}- if (process.env.EVENT_NAME === 'release') {- if (process.env.PRERELEASE === 'true' || process.env.RELEASE_TAG !== `v${version}`- || process.env.GITHUB_REF !== `refs/tags/v${version}`) {- throw new Error('Publish a stable Release tagged v<package.json version>.');- }- } else if (version !== process.env.EXPECTED_VERSION) {- throw new Error('Enter the stable version already committed in main/package.json.');+ if (process.env.RELEASE_TAG && process.env.RELEASE_TAG !== `v${version}`) {+ throw new Error('Release tag does not match the tested candidate version.');}+ const names = (process.env.RELEASE_PACKAGES ?? '').trim().split(/\s+/).filter(Boolean);+ selectReleasePackages(plan, names);appendFileSync(process.env.GITHUB_OUTPUT, `version=${version}\n`);JS-- checks:- needs: version- uses: ./.github/workflows/ci.yml-- package:- needs: version- uses: ./.github/workflows/npm-package.yml-- publish:- if: github.event_name == 'release' || inputs.publish- needs: [checks, package]- runs-on: ubuntu-latest- permissions:- contents: read- id-token: write- steps:- - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0- with:- ref: ${{ github.sha }}- persist-credentials: false- - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0- with:- node-version: 24- registry-url: https://registry.npmjs.org- name: Use npm with trusted publishing support+ if: github.event_name == 'release' || inputs.publishrun: npm install --global npm@11- - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0- with:- name: npm-package- path: release- - name: Publish the explicitly selected packages in dependency order+ - name: Inspect or publish the selected immutable packagesenv:RELEASE_PACKAGES: ${{ inputs.packages }}+ PUBLISH: ${{ github.event_name == 'release' || inputs.publish }}run: |node --input-type=module <<'JS'import { execFileSync } from 'node:child_process';@@ -107,26 +93,16 @@ jobs:execFileSync(process.execPath, ['scripts/publish-release-candidate.mjs', 'release/release-plan.json',...names.map(name => `--package=${name}`),+ ...(process.env.PUBLISH === 'true' ? [] : ['--preflight-only']),], { stdio: 'inherit' });JS-- release-assets:- if: github.event_name == 'release'- needs: [package, publish]- runs-on: ubuntu-latest- permissions:- contents: write- steps:- - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0- with:- name: npm-package- path: release- - name: Attach the package to the GitHub Release+ - name: Attach the tested root package to the GitHub Release+ if: github.event_name == 'release'env:GH_TOKEN: ${{ github.token }}GH_REPO: ${{ github.repository }}RELEASE_TAG: ${{ github.event.release.tag_name }}- VERSION: ${{ needs.package.outputs.version }}+ VERSION: ${{ steps.version.outputs.version }}run: |filename="hypit-hypit-$VERSION.tgz"assets="$(gh release view "$RELEASE_TAG" --json assets --jq '.assets[].name')"diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex a365941a..cc4e1125 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -50,7 +50,7 @@ page belongs with the change to its counterpart.## Check your work-CI runs these commands on every pull request. Run them locally first:+CI runs these commands on code pull requests. Run them locally first:```bashpnpm check # TypeScript type-check@@ -90,43 +90,37 @@ With FFmpeg and FFprobe available, runthe checkout, build its chat example component, prepare its font and local renderer, render and exportthe video, and decode the result. It disables implicit Puppeteer downloads, checks missing-browserdiagnostics, and prepares the browser in an isolated cache. It uses a separate Hypit state directory, stops its Runtime Worker,-and retains the temporary project on failure. The `npm package execution` workflow runs this on PRs-and is reused by publication; publication uploads the same tarball that was installed and executed.--For a formal release, use the existing GitHub workflows. Commit the next stable npm version in-`package.json` to `main`, then run **Actions → Publish npm → Run workflow** with **Publish to npm**-unchecked to validate that exact commit on Linux and Windows. After it passes, open-**Releases → Draft a new release**, choose that commit with tag `v<version>` (for example `v0.1.8`),-write the release notes, and publish the Release. The tagged commit must contain this workflow.-`Publish npm` verifies the tag/version match and that the commit belongs to main's history, runs-repository checks and release-candidate construction in parallel, then installs and executes that-one candidate on Linux and Windows. It preflights every package in the release plan against npm,-publishes dependencies first and the Distribution last as `latest`, and attaches the Distribution-tarball to the Release. No npm write occurs unless every check, package installation and registry-preflight succeeds. Checks and packaging use the triggering commit, even if main advances meanwhile.-This path supports stable releases, not prereleases.--**Actions → Publish npm → Run workflow** on `main` remains available: enter the committed version-and leave **Publish to npm** unchecked for an optional package-only rehearsal and downloadable-candidate; check it for a manual npm publication. Both paths build the candidate once and make both-operating systems consume the same uploaded files. To finish a failed Release publication, fix the-external problem and rerun that Release's workflow. A failed check or package preflight does not-consume the npm version. If no-package from the candidate reached npm, the Release and tag may be withdrawn, the code fixed while-retaining the intended version, and the complete candidate validated again. If publication stops-after some independent packages, rerun the same immutable candidate: matching versions are skipped-and publication resumes in dependency order. Only after the root Distribution version exists on npm-does a root code change require a new patch version; a failed asset upload or other external step can-still be rerun without one. An existing Release attachment is retained.-Pushing main, pushing a tag alone, or saving a draft Release does not publish npm. The workflow-does not edit versions or create tags. A visible Release can precede successful npm publication;-check its Actions result before announcing that the npm version is available.--For an independent-package update, use the workflow's **packages** input with the exact space-separated-names to publish, such as `@hypit/studio`. The full candidate is still installed and checked, but only-the selected packages are preflighted and published; this does not require a new root version when+and retains the temporary project on failure. Set `npm_config_cache` to reuse downloaded package+bytes; the consumer project, node_modules, Runtime state and browser installation remain isolated.+CI runs `npm package execution` alongside the repository checks and uploads the tested candidate.++For a formal release, commit the intended versions to `main` and wait for **CI** to succeed. It runs+repository checks and candidate packing in parallel, then installs and executes that same candidate+on Linux and Windows. PRs use the same checks but their artifacts are not publication candidates.+Documentation-only changes skip automatic CI; run **Actions → CI → Run workflow** on `main` when+such a commit is intended for release. One successful CI run supplies the `npm-package` artifact.++Then publish a GitHub Release tagged `v<version>` at that exact tested commit. **Publish npm** finds+the successful main CI run for the tag, downloads its artifact, checks the version and npm state,+publishes dependencies before the root, and attaches the tested root tarball to the Release. It does+not compile, reinstall or render again. The tag must contain this workflow. Stable releases only.++For manual publication or an independent-package update, open **Actions → Publish npm → Run workflow**+on `main` and enter the successful **CI run ID**. Leave **Publish** unchecked to download and inspect+the candidate without npm writes; check it to publish. The run ID selects the tested files even if+main has since advanced. The **packages** input selects exact space-separated names, such as+`@hypit/studio`; empty selects the complete candidate. This does not require a new root version whenthe existing root dependency ranges remain valid. Locally the equivalent selection is`node scripts/publish-release-candidate.mjs dist/release/release-plan.json --package=@hypit/studio`.++If publication or attachment fails, rerun publication with the same candidate, not CI. Matching+immutable npm versions are skipped; existing Release attachments are retained. A publishing-tool+fix can be committed to main and used with the original CI run ID. If the artifact has expired or+is missing, run CI again explicitly. A failed check or npm preflight consumes no version. Once a+package version is on npm, changing that package's bytes requires a new version; retrying its+unchanged publication does not. Pushing main, pushing a tag alone, or saving a draft Release does+not publish npm. Check the publication result before announcing availability.+Workspace release dependencies use explicit compatibility ranges, such as `workspace:^0.3.0`;packing removes the workspace prefix without raising the minimum to the current checkout version.@@ -136,16 +130,17 @@ name. The publishing job uses OIDC; no npm token secret is needed. An already pucannot be overwritten. npm versions such as `0.1.2` are separate from the logical `@1` interfaces.Trusted Publisher authority belongs to each npm package rather than to the `@hypit` scope. When a-new independently published package first enters the Distribution, prepare and check the exact-candidate locally, sign in with `npm login`, then run:+new independently published package first enters the Distribution, download the successful CI+candidate, sign in with `npm login`, then publish and bind that new package:```sh-npm run publish:release-dependencies-npm run trust:release-dependencies -- --package=@hypit/new-package+gh run download <ci-run-id> --name npm-package --dir <candidate-directory>+node scripts/publish-release-candidate.mjs <candidate-directory>/release-plan.json --package=@hypit/new-package+npm exec --yes --package=npm@^11.15.0 -- node scripts/configure-release-publishers.mjs <candidate-directory>/release-plan.json --package=@hypit/new-package```-The first command publishes only missing independent packages and never the root Distribution;-existing versions are skipped only when their registry integrity matches the candidate. The second+The publication command selects only the named new package, not the root Distribution; existing+versions are skipped only when their registry integrity matches the candidate. The trust commanduses npm 11.15 or newer to bind the named package to this repository and workflow. Omit `--package`only when bootstrapping every independent package in a new release plan. npm's first authorizationpage can grant a five-minute window for the remaining package bindings; the command spaces requestsdiff --git a/CONTRIBUTING.zh-CN.md b/CONTRIBUTING.zh-CN.mdindex da1e2c10..724854dc 100644--- a/CONTRIBUTING.zh-CN.md+++ b/CONTRIBUTING.zh-CN.md@@ -44,7 +44,7 @@ pnpm install --frozen-lockfile## 自查-每个 Pull Request 的 CI 都会运行下面这些命令,提交前先在本地跑一遍:+包含代码改动的 Pull Request 会通过 CI 运行下面这些命令,提交前先在本地跑一遍:```bashpnpm check # TypeScript 类型检查@@ -82,33 +82,30 @@ SVML 的逻辑 Module 引用仍保持 `@1`,这里改变的是 npm 归属和 Ty编译包内的聊天示例组件,准备字体和本地渲染器,渲染、导出并解码视频。检查使用独立的Hypit 状态目录,关闭 Puppeteer 隐式下载,先验证缺少浏览器的诊断,再在独立缓存中显式准备浏览器。结束时停止自己的 Runtime Worker,失败时保留临时项目。-`npm package execution` 工作流在 PR 上执行这项检查,发布流程复用它;发布的就是已经-安装并执行过的同一份 tarball。--正式发布请走现有的 GitHub 工作流。把下一个稳定 npm 版本写入 `package.json` 并提交到-`main`,然后先在 `main` 上运行 **Actions → Publish npm → Run workflow**,填写该版本且不要勾选-**Publish to npm**。这会在不改动 npm 的情况下,对完整且不可变的候选版本运行 Linux/Windows-检查,并将其保留为可下载构件。这个准确提交通过后,再打开 **Releases → Draft a new release**,-选择该提交,打上标签 `v<version>`(例如 `v0.1.8`),写好发布说明后发布 Release。带标签的提交-必须包含此工作流。`Publish npm` 会核对标签与版本一致、且该提交属于 main 的历史,运行-Linux/Windows 检查,构建并检查打包后的 CLI,预检发布计划中的每个包在 npm 上的状态,-按依赖优先、根 Distribution 最后的顺序以 `latest` 发布,并把 tarball 附加到这次 Release。-只有全部检查、包安装与 Registry 预检成功后,才会发生任何 npm 写入。检查与打包使用触发时的-提交,即使随后 main 继续前进。此路径只支持稳定版,不支持预发布。--**Actions → Publish npm → Run workflow** 在 `main` 上仍然可用:填写已提交的版本,不勾选-**Publish to npm** 时只运行检查并提供可下载构件;勾选后则手动发布 npm。补完一次失败的 Release-发布时,先修好外部问题再重跑该 Release 的工作流。检查或包预检失败不会消耗 npm 版本。如果候选-版本没有任何包进入 npm,可以撤回 Release 与标签,修复代码但保留原定版本,再重新验证完整候选。-如果独立包已经发布了一部分,重跑同一个不可变候选即可:匹配的版本会被跳过,发布按依赖顺序继续。-只有根 Distribution 版本已经存在于 npm 后,根包代码变更才必须使用新的 patch 版本;资源上传失败等-外部步骤仍可在原版本上重跑。已经附在 Release 上的文件会保留。-push main、只 push 标签、或保存草稿 Release 都不会发布 npm。工作流不修改版本,也不创建标签。-可见的 Release 可以早于 npm 发布成功;对外宣布该 npm 版本可用前,先看这次 Actions 的结果。--独立包更新可在工作流的 **packages** 输入中填写空格分隔的准确包名,例如 `@hypit/studio`。-完整候选仍需安装检查,但只预检和发布所选包;现有根依赖范围仍适用时,不需要为此发布根包。+可通过 `npm_config_cache` 复用已下载的包;验证项目、node_modules、Runtime 状态和浏览器安装+仍保持独立。CI 在源码检查之外并行调用 `npm package execution`,保留测试过的候选制品。++正式发布时,将预定版本提交到 `main`,等待 **CI** 成功。它并行进行源码检查与候选打包,再在+Linux 和 Windows 上安装、执行同一份候选。PR 使用相同检查,但其制品不能用于正式发布。+纯文档改动不自动触发 CI;如果要发布这种提交,在 `main` 上手动运行 **Actions → CI → Run workflow**。+一次成功的 CI 提供后续发布使用的 `npm-package` 制品。++在这个准确提交上创建标签 `v<version>` 并发布 GitHub Release。**Publish npm** 查找该提交成功的+main CI,下载其制品,核对版本和 npm 状态,按依赖优先、根包最后的顺序发布,再附上根包 tarball。+发布不重新编译、安装或渲染。标签提交必须包含这套工作流;此路径只支持稳定版。++手动发布或更新独立包时,在 `main` 上打开 **Actions → Publish npm → Run workflow**,填写成功的+**CI run ID**。不勾选 **Publish** 时只下载、检查候选,不写 npm;勾选后才发布。即使 main 后来+继续前进,run ID 仍选择原来测试过的文件。**packages** 输入填写空格分隔的准确包名,例如+`@hypit/studio`;留空表示完整候选。现有根依赖范围仍适用时,独立包更新不需要发布根包。本地对应命令是 `node scripts/publish-release-candidate.mjs dist/release/release-plan.json --package=@hypit/studio`。++发布或附件上传失败时,用同一个候选重跑发布,不重跑 CI。已存在且内容一致的 npm 版本会跳过,+已有 Release 附件保留。发布工具修复可以提交到 main,再选择原来的 CI run ID。制品过期或丢失时,+才显式重跑 CI。检查或 npm 预检失败不消耗版本;一个包的版本进入 npm 后,更改该包内容才需要新版本,+重试原内容的发布不需要。push main、只 push 标签或保存草稿 Release 都不会发布 npm。+对外宣布版本可用前,先核对发布结果。+发行依赖使用明确的兼容范围,例如 `workspace:^0.3.0`;打包只去掉 workspace 前缀,不会自动把兼容下限抬高到当前源码版本。@@ -116,6 +113,17 @@ npm 包的 Trusted Publisher 应配置 GitHub Actions:组织 `hypit-ai`、仓`publish-npm.yml`,允许直接 `npm publish`,环境名称留空。发布 job 使用 OIDC,不需要保存 npm Token。已发布的版本不能覆盖;`0.1.2` 等 npm 版本与逻辑接口 `@1` 分开管理。+新独立包首次进入发行时,下载成功 CI 的候选,执行 `npm login`,再创建该包并绑定可信发布:++```sh+gh run download <ci-run-id> --name npm-package --dir <candidate-directory>+node scripts/publish-release-candidate.mjs <candidate-directory>/release-plan.json --package=@hypit/new-package+npm exec --yes --package=npm@^11.15.0 -- node scripts/configure-release-publishers.mjs <candidate-directory>/release-plan.json --package=@hypit/new-package+```++首次发包只选择新包,不选择根包。可信发布配置由 npm 11.15 或更新版本完成,可能需要浏览器授权。+绑定完成后,普通发布仍由 GitHub OIDC 执行,无需保存长期 npm Token。+发布说明应写明变化的用户行为,以及受影响的安装。npm Distribution 与已安装的 Skill 分开更新:一次发布若两者都变,请同时链到相关 Skill 变更并说明两条更新路径。已保存的视频项目及其现有素材独立于这两种安装。发布后,先核对工作流结果和 npm 上的已发布版本,再告诉用户更新可用。diff --git a/scripts/check-distribution.mjs b/scripts/check-distribution.mjsindex fca3858e..30e52e0b 100644--- a/scripts/check-distribution.mjs+++ b/scripts/check-distribution.mjs@@ -17,7 +17,8 @@ await mkdir(project);const env = {...process.env,HYPIT_STATE_HOME: join(root, "state"),- npm_config_cache: join(root, "npm-cache"),+ // Downloaded package bytes may be reused; project, node_modules and Runtime state stay fresh.+ npm_config_cache: process.env.npm_config_cache || join(root, "npm-cache"),};// Old shell hints must not redirect the installed launcher, Worker or capture child.env.HYPIT_DISTRIBUTION_ROOT = join(root, "stale-distribution");diff --git a/scripts/pack-distribution.mjs b/scripts/pack-distribution.mjsindex f1668e5d..888e4477 100644--- a/scripts/pack-distribution.mjs+++ b/scripts/pack-distribution.mjs@@ -27,7 +27,9 @@ function npm(args, cwd, capture = false) {});}-npm(["run", "build:public-types"], root);+const arguments_ = process.argv.slice(2);+if (arguments_.some((argument) => argument !== "--types-built")) throw new Error("Unknown distribution pack option.");+if (!arguments_.includes("--types-built")) npm(["run", "build:public-types"], root);const [inventory] = JSON.parse(npm(["pack", "--dry-run", "--ignore-scripts", "--json"], root, true));const embeddedPackageDirectories = await distributionEmbeddedPackageDirectories(root);let readme = await readFile(resolve(root, "README.md"), "utf8");diff --git a/scripts/release-candidate.mjs b/scripts/release-candidate.mjsindex 1b1ab9e2..12e8cf21 100644--- a/scripts/release-candidate.mjs+++ b/scripts/release-candidate.mjs@@ -119,7 +119,7 @@ export async function packReleaseCandidate(outputDirectory = "dist/release") {const tarball = await packIndependentPackage(item.directory, outputDirectory, { buildPublicTypes: false });console.log(`Prepared ${item.name}@${item.version}: ${tarball}`);}- runNpm(["run", "pack:distribution"]);+ runNpm(["run", "pack:distribution", "--", "--types-built"]);const candidate = await releaseCandidateTarballs(outputDirectory);await writeFile(candidate.plan, `${JSON.stringify({format: "hypit.release-plan@1",diff --git a/scripts/select-release-run.mjs b/scripts/select-release-run.mjsnew file mode 100644index 00000000..8a045a6c--- /dev/null+++ b/scripts/select-release-run.mjs@@ -0,0 +1,43 @@+import { execFileSync } from "node:child_process";+import { appendFile } from "node:fs/promises";+import { pathToFileURL } from "node:url";++/** Publication consumes CI's existing result; it never reconstructs an unverified candidate. */+export function selectReleaseRun(runs, { repository, commit }) {+ const run = runs.find((candidate) => candidate.repository?.full_name === repository+ && candidate.head_repository?.full_name === repository+ && candidate.path?.split("@")[0] === ".github/workflows/ci.yml"+ && candidate.head_branch === "main"+ && ["push", "workflow_dispatch"].includes(candidate.event)+ && candidate.status === "completed" && candidate.conclusion === "success"+ && (commit === undefined || candidate.head_sha === commit));+ if (run === undefined) {+ throw new Error("No successful main CI candidate matches this request. Run CI on the intended commit first.");+ }+ return run;+}++async function main() {+ const repository = process.env.GITHUB_REPOSITORY;+ if (!repository) throw new Error("GITHUB_REPOSITORY is required.");+ const release = process.env.GITHUB_EVENT_NAME === "release";+ if (release && process.env.RELEASE_PRERELEASE === "true") throw new Error("Only stable releases are supported.");+ const requested = process.env.CANDIDATE_RUN?.trim();+ if (!release && !/^\d+$/.test(requested ?? "")) throw new Error("Select an explicit successful CI run ID.");+ const api = (path) => JSON.parse(execFileSync("gh", ["api", path], { encoding: "utf8" }));+ const commit = release ? process.env.GITHUB_SHA : undefined;+ if (release && !commit) throw new Error("Release commit is required.");+ const runs = release+ ? api(`repos/${repository}/actions/workflows/ci.yml/runs?head_sha=${commit}&branch=main&status=success&per_page=100`).workflow_runs+ : [api(`repos/${repository}/actions/runs/${requested}`)];+ const run = selectReleaseRun(runs, { repository, commit });+ execFileSync("git", ["merge-base", "--is-ancestor", run.head_sha, "origin/main"]);+ const artifacts = api(`repos/${repository}/actions/runs/${run.id}/artifacts?per_page=100`).artifacts;+ if (!artifacts.some((artifact) => artifact.name === "npm-package" && !artifact.expired)) {+ throw new Error("The tested npm-package artifact is missing or expired. Run CI again; publication does not rebuild it.");+ }+ console.log(`Using tested candidate from ${run.html_url} (${run.head_sha}).`);+ await appendFile(process.env.GITHUB_OUTPUT, `run_id=${run.id}\n`);+}++if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) await main();diff --git a/scripts/test/select-release-run.test.mjs b/scripts/test/select-release-run.test.mjsnew file mode 100644index 00000000..a18dc704--- /dev/null+++ b/scripts/test/select-release-run.test.mjs@@ -0,0 +1,41 @@+import assert from "node:assert/strict";+import test from "node:test";+import { selectReleaseRun } from "../select-release-run.mjs";++const repository = "hypit-ai/hypit";+const passed = {+ id: 42,+ repository: { full_name: repository },+ head_repository: { full_name: repository },+ path: ".github/workflows/ci.yml",+ head_branch: "main",+ head_sha: "tested-commit",+ event: "push",+ status: "completed",+ conclusion: "success",+};++test("a Release selects the successful CI for its exact commit", () => {+ const later = { ...passed, id: 43, head_sha: "later-commit" };+ assert.equal(selectReleaseRun([later, passed], { repository, commit: "tested-commit" }), passed);+ assert.throws(() => selectReleaseRun([later], { repository, commit: "tested-commit" }), /No successful/);+});++test("an explicit successful main CI can be published after main advances", () => {+ const manual = { ...passed, event: "workflow_dispatch" };+ assert.equal(selectReleaseRun([manual], { repository }), manual);+});++test("publication does not accept partial checks, PRs or another workflow's artifacts", () => {+ for (const difference of [+ { status: "in_progress" },+ { conclusion: "failure" },+ { event: "pull_request" },+ { head_branch: "feature" },+ { path: ".github/workflows/npm-package.yml" },+ { head_repository: { full_name: "someone/fork" } },+ { repository: { full_name: "someone/fork" } },+ ]) {+ assert.throws(() => selectReleaseRun([{ ...passed, ...difference }], { repository }), /No successful/);+ }+});