Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 161 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
name: Publish CRYChart to npm

on:
release:
types: [published]

permissions: {}

concurrency:
group: publish-crysound-crychart
cancel-in-progress: false

defaults:
run:
shell: bash

env:
NPM_CONFIG_REGISTRY: https://registry.npmjs.org/

jobs:
prepare:
name: 验收发行包
if: github.repository == 'crysound/CRYChart' && github.event.release.prerelease == false
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
actions: read
outputs:
version: ${{ steps.release.outputs.version }}
integrity: ${{ steps.pack.outputs.integrity }}
steps:
- name: 检出发布提交
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
ref: ${{ github.sha }}
persist-credentials: false
- name: 安装 Node.js
uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
with:
node-version: '24'
package-manager-cache: false
- name: 核对标签与该提交的 CI
id: release
env:
GH_TOKEN: ${{ github.token }}
run: |
version=$(node -p 'require("./package.json").version')
if [[ ! "$version" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ||
"$GITHUB_REF" != "refs/tags/v$version" ||
"$(git rev-parse HEAD)" != "$GITHUB_SHA" ]]; then
echo "::error::The release tag must match the stable package version v$version and the checked-out commit."
exit 1
fi

passed=$(gh api --method GET "repos/$GITHUB_REPOSITORY/actions/workflows/ci.yml/runs" \
-f branch=main -f event=push -f head_sha="$GITHUB_SHA" -f status=success \
--jq '.total_count')
if [[ "$passed" -lt 1 ]]; then
echo "::error::CRYChart CI must pass on main for $GITHUB_SHA. Re-run after CI succeeds."
exit 1
fi
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: 安装锁定版本的依赖
run: npm ci
- name: 运行 npm 发布前检查
run: npm run prepublishOnly
- name: 打包并试装实际归档
id: pack
env:
VERSION: ${{ steps.release.outputs.version }}
run: |
release_dir="$RUNNER_TEMP/npm-release"
mkdir -p "$release_dir"
npm pack --pack-destination "$release_dir"
archive="$release_dir/crychart.tgz"
mv "$release_dir/crysound-crychart-$VERSION.tgz" "$archive"
integrity="sha512-$(openssl dgst -sha512 -binary "$archive" | openssl base64 -A)"

cd "$(mktemp -d)"
npm install --ignore-scripts --no-audit --no-fund --no-package-lock --no-save "$archive"
node --input-type=module <<'NODE'
import assert from 'node:assert/strict';
import { existsSync } from 'node:fs';
import { createRequire } from 'node:module';
import * as esm from '@crysound/crychart';
import * as themes from '@crysound/crychart/themes';
const cjs = createRequire(import.meta.url)('@crysound/crychart');
for (const entry of [esm, cjs]) {
assert.equal(entry.version, process.env.VERSION);
assert.equal(typeof entry.cryChart, 'function');
}
assert.ok(Object.keys(themes).length > 0);
for (const file of ['types/index.d.ts', 'types/themes.d.ts', 'crychart.global.js']) {
assert.ok(existsSync("node_modules/@crysound/crychart/dist/" + file), file);
}
NODE
echo "integrity=$integrity" >> "$GITHUB_OUTPUT"
- name: 保存待发布归档
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:
name: crychart-npm-package
path: ${{ runner.temp }}/npm-release/crychart.tgz
if-no-files-found: error
overwrite: true

publish:
name: 发布并核验 npm 包
needs: prepare
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
id-token: write
env:
VERSION: ${{ needs.prepare.outputs.version }}
EXPECTED_INTEGRITY: ${{ needs.prepare.outputs.integrity }}
steps:
- name: 安装支持 Trusted Publishing 的 Node.js 和 npm
uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
with:
node-version: '24'
registry-url: https://registry.npmjs.org/
package-manager-cache: false
- name: 下载已验收归档
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
with:
name: crychart-npm-package
path: ${{ runner.temp }}/npm-release
- name: 使用 Trusted Publishing 上传归档
run: |
archive="$RUNNER_TEMP/npm-release/crychart.tgz"
actual_integrity="sha512-$(openssl dgst -sha512 -binary "$archive" | openssl base64 -A)"
if [[ "$actual_integrity" != "$EXPECTED_INTEGRITY" ]]; then
echo "::error::The downloaded archive does not match the archive verified by the prepare job."
exit 1
fi

exists=$(npm view @crysound/crychart versions --json --prefer-online |
node -p 'JSON.parse(require("node:fs").readFileSync(0, "utf8")).includes(process.env.VERSION)')
if [[ "$exists" == true ]]; then
echo "@crysound/crychart@$VERSION already exists; checking the archive and latest tag without publishing again."
else
npm publish "$archive" --access public --tag latest
fi
- name: 核对 registry 版本、标签和归档
run: |
spec="@crysound/crychart@$VERSION"
for attempt in 1 2 3 4 5 6; do
if integrity=$(npm view "$spec" dist.integrity --prefer-online) &&
latest=$(npm view @crysound/crychart@latest version --prefer-online) &&
[[ "$integrity" == "$EXPECTED_INTEGRITY" && "$latest" == "$VERSION" ]]; then
registry_dir=$(mktemp -d)
npm pack "$spec" --ignore-scripts --prefer-online --pack-destination "$registry_dir"
cmp "$RUNNER_TEMP/npm-release/crychart.tgz" "$registry_dir/crysound-crychart-$VERSION.tgz"
echo "Verified $spec at npm latest ($integrity)."
exit 0
fi
if [[ "$attempt" -lt 6 ]]; then sleep 5; fi
done
echo "::error::npm did not return the expected archive and latest tag for $spec."
exit 1
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ CRYChart is a **frontend rendering library built by CRYSOUND for OpenTest**, wri

Designed for OpenTest's data visualization needs, CRYChart provides streaming data rendering, interactive axes, cursors, and 2D and 3D charts. It uses WebGL2 for rendering, with a Canvas fallback.

The first public npm release is `@crysound/crychart@1.0.1`. This source tree targets `1.0.2`, which includes the high precision waveform viewport fix merged after the `1.0.1` release build.
Version `1.0.2` fixes the viewport size limit for high precision waveform axes.

## Install in an application

```powershell
pnpm add --save-exact @crysound/crychart@1.0.1 --registry=https://registry.npmjs.org/
pnpm add --save-exact @crysound/crychart@1.0.2 --registry=https://registry.npmjs.org/
```

Commit the application's lockfile and use `pnpm install --frozen-lockfile` for repeatable installs. See the [npm usage guide](docs/npm-usage.md) for package entry points and migration from the old `crychart` name.
Expand Down
4 changes: 2 additions & 2 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ CRYChart 是 **CRYSOUND 为 OpenTest 定制的前端渲染库**,基于 TypeScr

CRYChart 面向 OpenTest 的数据可视化场景,提供流式数据绘制、交互坐标轴、游标、二维和三维图表。绘图使用 WebGL2,并提供 Canvas 回退。

首个 npm 公开版本为 `@crysound/crychart@1.0.1`。当前源码准备发布 `1.0.2`,包含 `1.0.1` 发行包构建后合入的高精度波形视口修复。
`1.0.2` 修复了高精度波形轴的视口跨度限制。

## 在应用中安装

```powershell
pnpm add --save-exact @crysound/crychart@1.0.1 --registry=https://registry.npmjs.org/
pnpm add --save-exact @crysound/crychart@1.0.2 --registry=https://registry.npmjs.org/
```

提交应用的锁文件,后续执行 `pnpm install --frozen-lockfile`。包入口和旧 `crychart` 包名的迁移方式见 [npm 使用说明](docs/npm-usage.md)。
Expand Down
22 changes: 21 additions & 1 deletion docs/delivery.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,27 @@ npm run test:gallery

npm 包仅包含运行库、类型、中英文许可证、README 和 `docs/npm-usage.md`。完整使用手册、历史性能数据、功能报告、OpenTest 合同和修复记录保留在仓库。历史包位于 `version/v1.0/`,其旧版本号与验收结果不代表新发行版。

## 公开发布
## 通过 GitHub Actions 发布

首次发布前,先把 `.github/workflows/publish.yml` 合入 `main`。使用有包管理权限的 npm 账号,打开 `@crysound/crychart` 的 **Settings → Trusted publishing**,选择 **GitHub Actions**,填入:

| 字段 | 值 |
| --- | --- |
| Organization or user | `crysound` |
| Repository | `CRYChart` |
| Workflow filename | `publish.yml` |
| Environment name | 留空 |
| Allowed actions | 启用 `npm publish` |

保存后在两天内完成首次成功发布。无需添加 npm token 到 GitHub Secrets。参见 [npm Trusted Publishing](https://docs.npmjs.com/trusted-publishers/)。

1. 合入发版改动,确认 `package.json` 的版本与安装说明一致。等发版提交在 `main` 上的 **CRYChart CI** 通过。
2. 在 [GitHub Releases](https://github.com/crysound/CRYChart/releases) 创建正式 Release。将版本标签(例如 `v1.0.2`)指向该提交,填写发版说明,点击 **Publish release**。
3. 在 [GitHub Actions](https://github.com/crysound/CRYChart/actions/workflows/publish.yml) 查看结果。流程会验收实际归档、发布到 npm 的 `latest`,再从 registry 下载归档并核对内容。

若任务失败,先查 npm 上的目标版本,再修正配置并重跑失败任务。若版本已经存在,流程只核对归档和 `latest`,不会覆盖内容。若要修正已发布的包,使用新版本号。

## 手动发布

使用具备 `crysound` 组织发布权限的账号在本机登录。以下示例使用当前源码版本 `1.0.2`。先验收该版本的归档,再发布:

Expand Down
2 changes: 1 addition & 1 deletion docs/npm-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
在应用目录安装固定版本:

```powershell
pnpm add --save-exact @crysound/crychart@1.0.1 --registry=https://registry.npmjs.org/
pnpm add --save-exact @crysound/crychart@1.0.2 --registry=https://registry.npmjs.org/
```

ES 模块和 TypeScript 使用相同入口:
Expand Down
Loading