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
32 changes: 17 additions & 15 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,23 @@ jobs:
if: steps.detect.outputs.changed != 'true'
run: echo "本次推送未改动 cli/package.json,无需发包。"

- name: 校验 NPM_TOKEN 已配置
# ── 前置快速检查(在耗时的安装依赖之前,30 秒内完成判定)──
# 幂等检查提前:版本已发布过 → 后面的安装/构建/测试全部跳过,绿色空转退出
- name: 幂等检查(版本是否已发布过)
id: should
if: steps.detect.outputs.changed == 'true'
run: |
VERSION="${{ steps.detect.outputs.version }}"
if npm view "verify-article-structure@$VERSION" version --registry=https://registry.npmjs.org/ >/dev/null 2>&1; then
echo "::notice::v$VERSION 已存在于公网 npm,跳过发包与打 tag"
echo "should=false" >> "$GITHUB_OUTPUT"
else
echo "v$VERSION 未发布过 → 开始发包"
echo "should=true" >> "$GITHUB_OUTPUT"
fi

- name: 校验 NPM_TOKEN 已配置
if: steps.detect.outputs.changed == 'true' && steps.should.outputs.should == 'true'
env:
HAS_TOKEN: ${{ secrets.NPM_TOKEN != '' }}
run: |
Expand All @@ -82,23 +97,10 @@ jobs:
fi

- name: 安装依赖
if: steps.detect.outputs.changed == 'true'
if: steps.detect.outputs.changed == 'true' && steps.should.outputs.should == 'true'
working-directory: cli
run: pnpm install --frozen-lockfile

- name: 幂等检查(版本是否已发布过)
id: should
if: steps.detect.outputs.changed == 'true'
run: |
VERSION="${{ steps.detect.outputs.version }}"
if npm view "verify-article-structure@$VERSION" version --registry=https://registry.npmjs.org/ >/dev/null 2>&1; then
echo "::notice::v$VERSION 已存在于公网 npm,跳过发包与打 tag"
echo "should=false" >> "$GITHUB_OUTPUT"
else
echo "v$VERSION 未发布过 → 开始发包"
echo "should=true" >> "$GITHUB_OUTPUT"
fi

- name: 发布(prepublishOnly 自动执行 build + 全量测试)
if: steps.should.outputs.should == 'true'
working-directory: cli
Expand Down
60 changes: 60 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: CI 全量测试

# 触发条件:
# 1. PR 到 main → 合并前跑全量验证(typecheck + build + vitest/puppeteer 全量测试)
# 2. push 到 main → 合并后立即验证 main 健康(发包 workflow 的测试步骤会被幂等检查跳过,
# 依赖升级等未 bump 版本的合并不跑测试,这里兜底)
#
# 背景:PR #63(mp-darkmode 2.0 alpha 升级)因无 PR CI,带着一个失败用例进了 main
# (#4.1.1 低对比度检测失效)。本 workflow 补上这道闸门。

on:
pull_request:
branches: [main]
push:
branches: [main]

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
with:
version: 8

- uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
cache-dependency-path: cli/pnpm-lock.yaml

# Puppeteer 的 Chrome 缓存(首跑约 4-6 分钟,命中后秒级)
# key 里的版本号与 cli/package.json 的 puppeteer 版本对应,升级 puppeteer 时换 key
- name: 缓存 Puppeteer Chrome
uses: actions/cache@v4
with:
path: ~/.cache/puppeteer
key: puppeteer-${{ runner.os }}-chrome-118

- name: 安装依赖
working-directory: cli
run: pnpm install --frozen-lockfile

- name: TypeScript 类型检查
working-directory: cli
run: pnpm exec tsc --noEmit

- name: 构建
working-directory: cli
run: pnpm build

- name: 全量测试(vitest + puppeteer 真实浏览器)
working-directory: cli
run: pnpm test
Loading