Skip to content

Schema-DSL Compat

Schema-DSL Compat #18

# ─────────────────────────────────────────────────────────────
# schema-dsl 兼容性测试
#
# 当 schema-dsl 仓库发布新版本或 CI 通过后,通过 repository_dispatch
# 事件触发此 workflow,验证 vext 框架与最新 schema-dsl 的兼容性。
#
# 触发方式:
# 1. schema-dsl CI 通过后自动触发(repository_dispatch)
# 2. 手动触发(workflow_dispatch)
# 3. 定时触发(每周一 UTC 03:00)
#
# @see schema-dsl/.github/workflows/ci.yml — 上游触发源
# @see CHANGELOG.md — CI-001
# ─────────────────────────────────────────────────────────────
name: Schema-DSL Compat
on:
# schema-dsl CI 通过后通过 GitHub API 触发
repository_dispatch:
types: [schema-dsl-updated]
# 手动触发(可指定 schema-dsl 版本)
workflow_dispatch:
inputs:
schema_dsl_version:
description: "schema-dsl version to test (e.g. 1.2.5, latest)"
required: false
default: "latest"
# 定时触发 — 每周一 UTC 03:00(北京时间 11:00)
schedule:
- cron: "0 3 * * 1"
concurrency:
group: schema-dsl-compat-${{ github.ref }}
cancel-in-progress: true
env:
NODE_ENV: test
jobs:
# ────────────────────────────────────────────────────────────
# 1. 兼容性测试(使用最新 schema-dsl)
# ────────────────────────────────────────────────────────────
compat-test:
name: Schema-DSL Compat (Node ${{ matrix.node-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: [20, 22]
steps:
- name: Checkout vext
uses: actions/checkout@v4
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- name: Install dependencies
run: npm ci
# 确定要测试的 schema-dsl 版本
- name: Resolve schema-dsl version
id: resolve-version
run: |
set -euo pipefail
if [ "${{ github.event_name }}" = "repository_dispatch" ]; then
# 从 dispatch payload 中获取版本
VERSION="${{ github.event.client_payload.version }}"
if [ -z "$VERSION" ] || [ "$VERSION" = "null" ]; then
VERSION="latest"
fi
elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
VERSION="${{ inputs.schema_dsl_version }}"
else
# schedule 触发 — 使用 latest
VERSION="latest"
fi
RESOLVED_VERSION="$(npm view "schema-dsl@$VERSION" version)"
echo "version=$RESOLVED_VERSION" >> "$GITHUB_OUTPUT"
echo "📦 Requested schema-dsl@$VERSION"
echo "📦 Resolved schema-dsl@$RESOLVED_VERSION"
echo "npm: $(npm --version)"
echo "node: $(node --version)"
# 升级 schema-dsl 到目标版本
- name: Upgrade schema-dsl
run: |
set -euo pipefail
VERSION="${{ steps.resolve-version.outputs.version }}"
echo "📦 Installing schema-dsl@$VERSION ..."
npm install "schema-dsl@$VERSION" --save --save-exact --no-audit --no-fund || {
echo "::warning::First schema-dsl install failed; verifying npm cache and retrying once"
npm cache verify
npm install "schema-dsl@$VERSION" --save --save-exact --no-audit --no-fund
}
echo ""
echo "✅ Installed version:"
node -e "console.log(require('schema-dsl/package.json').version)"
echo ""
echo "📦 Installed dependency tree:"
npm ls schema-dsl
# TypeScript 编译检查
- name: TypeScript type check
run: npx tsc --noEmit
# 构建验证
- name: Build
run: npm run build
# 单元测试(包含 OpenAPI schema-converter 测试)
- name: Unit tests
run: npx vitest run test/unit --reporter=verbose
# 集成测试(包含 OpenAPI pipeline 端到端测试)
- name: Integration tests
run: npx vitest run test/integration --reporter=verbose
# ────────────────────────────────────────────────────────────
# 2. 结果通知
# ────────────────────────────────────────────────────────────
compat-result:
name: Compat Result
runs-on: ubuntu-latest
needs: [compat-test]
if: always()
steps:
- name: Check result
run: |
echo "compat-test: ${{ needs.compat-test.result }}"
if [[ "${{ needs.compat-test.result }}" != "success" ]]; then
echo ""
echo "❌ Schema-DSL 兼容性测试失败!"
echo ""
echo "可能原因:"
echo " 1. schema-dsl 新版本引入了破坏性变更"
echo " 2. schema-dsl 的类型定义发生了不兼容修改"
echo " 3. toJsonSchema() / toSchema() 输出格式变更"
echo ""
echo "建议操作:"
echo " 1. 检查 schema-dsl CHANGELOG 了解变更内容"
echo " 2. 运行本地测试复现问题"
echo " 3. 更新 vext 的 schema-converter 适配新版本"
exit 1
fi
echo "✅ Schema-DSL 兼容性测试全部通过!"