Skip to content

ci: workflow support for dependency preview and online docs - #268

Merged
hexqi merged 2 commits into
opentiny:developfrom
SonyLeo:feat/ci-optimize
Dec 25, 2025
Merged

ci: workflow support for dependency preview and online docs#268
hexqi merged 2 commits into
opentiny:developfrom
SonyLeo:feat/ci-optimize

Conversation

@SonyLeo

@SonyLeo SonyLeo commented Dec 23, 2025

Copy link
Copy Markdown
Collaborator

✨ PR 预览功能

每次提交 PR 时会自动:

  1. 📦 构建包和文档 - 自动编译代码和文档
  2. 🚀 发布预览包 - 通过 pkg.pr.new 生成可安装的预览包,无需发布到 NPM
  3. 🌐 部署文档预览 - 自动部署文档到 Surge,提供在线预览
  4. 💬 智能评论 - 在 PR 中自动显示预览链接和安装命令,每次新提交自动更新

📸 效果预览

PR 中会显示两条自动更新的评论:

完整预览

image

评论 1 - 构建状态和预览链接

构建中:

构建成功:

💡 点击图片可直接访问 Surge 部署的文档预览站点,地址格式为 preview-{PR编号}-tiny-robot.surge.sh

构建失败:

评论 2 - 包安装命令

## 📦 Package Preview

pnpm add https://pkg.pr.new/owner/repo@package-name@abc1234
pnpm add https://pkg.pr.new/owner/repo@package-kit@abc1234
pnpm add https://pkg.pr.new/owner/repo@package-svgs@abc1234

commit: abc1234

关键特性:

  • 每次新的 commit 推送后,安装链接会自动更新为最新的 commit hash
  • 评论会自动更新,不会产生多条评论
  • PR 关闭后,Surge 预览站点自动清除

自动跳过规则

以下情况会跳过构建和测试:

  • PR 标题包含 docs:chore: release
  • PR 标题以 vV 开头(版本发布)

🚀 仓库维护者必读:启用配置

⚠️ 重要提示:以下配置必须由远程仓库
的维护者
(拥有仓库 Settings 权限的人)完成,否则工作流将无法正常运行!

✅ 必需配置

1. 安装 pkg.pr.new GitHub App

操作步骤

  1. 访问 https://github.com/apps/pkg-pr-new
  2. 点击 InstallConfigure
  3. 选择要安装的仓库(可以选择所有仓库或特定仓库)
  4. 授权安装

验证方式

  • 进入仓库 SettingsIntegrationsGitHub Apps
  • 确认 pkg.pr.new 已安装

⚠️ 如果不安装此 App,包预览功能将完全无法工作,PR 中不会显示安装命令!


🔧 可选配置

2. 配置 Surge Token(用于文档预览)

谁来做:仓库管理员(拥有 Settings 权限)

操作步骤

步骤 A:获取 Surge Token

# 1. 安装 Surge CLI(如果还没安装)
npm install -g surge

# 2. 注册并获取 token
surge token

步骤 B:添加到 GitHub Secrets

  1. 进入仓库 SettingsSecrets and variablesActions
  2. 点击 New repository secret
  3. 名称填写:SURGE_TOKEN
  4. 值粘贴:你的 Surge token
  5. 点击 Add secret

验证方式

  • SettingsSecrets and variablesActions 中看到 SURGE_TOKEN

💡 如果不配置 Surge Token

  • 文档预览部署会失败(Actions 中会显示错误)
  • 包预览功能仍然可用
  • PR 评论中不会显示文档预览链接

🧪 验证配置

配置完成后,仓库维护者或任何贡献者都可以创建测试 PR 验证:

  1. 创建新分支并提交修改

    git checkout -b test/verify-workflows
    echo "test" >> README.md
    git add . && git commit -m "test: verify workflows"
    git push origin test/verify-workflows
  2. 在 GitHub 上创建 PR

  3. 检查以下内容:

    • Actions 标签页显示工作流正在运行
    • ✅ PR 中出现包预览评论(包含 pnpm add 命令)
    • ✅ PR 中出现文档预览评论(如果配置了 Surge Token)
    • ✅ 点击预览图片可以访问文档站点
  4. 如果一切正常,删除测试 PR


🌐 Surge 预览说明

预览站点特性

  • 域名格式preview-{PR编号}-tiny-robot.surge.sh
  • 自动部署:每次 PR 更新时自动重新部署
  • 访问方式:点击 PR 评论中的预览图片直接访问

预览状态说明

  1. 构建中 - 显示"🔨 Building packages...",此时站点可能还未部署或显示旧版本
  2. 构建成功 - 显示"✅ Preview build completed successfully!",可点击图片访问最新版本
  3. 构建失败 - 显示"❌ Build failed",需要查看 Actions 日志排查问题

常见场景

  • 首次部署:PR 创建后约 2-3 分钟完成首次部署
  • 更新部署:新 commit 推送后约 1-2 分钟完成更新
  • 并发处理:新的构建会自动取消旧的构建,确保资源高效利用

Summary by CodeRabbit

  • Chores
    • Reworked CI to introduce dedicated build, E2E test, and preview workflows for faster, modular pipelines.
    • Added a PR orchestration workflow to run build, preview, and E2E jobs with smarter concurrency and conditional skips.
    • Improved artifact handling and preview deployments with automated PR comments and teardown on close.
    • Removed legacy end-to-end workflow to consolidate testing.

✏️ Tip: You can customize this high-level summary in your review settings.

…itions- Restructure workflows- Enhance E2E tests with workflow_run trigger- Add pkg.pr.new publishing with custom comments- Streamline PR build and deploy workflows- Add build status comments to PRs- Improve deployment handling
@coderabbitai

coderabbitai Bot commented Dec 23, 2025

Copy link
Copy Markdown

Walkthrough

Refactors CI by removing a single E2E workflow and introducing modular, reusable GitHub Actions workflows for build, E2E tests, preview/deploy, orchestration, and PR cleanup (Surge teardown and PR comment management).

Changes

Cohort / File(s) Summary
Removed Workflow
.github/workflows/e2e-tests.yml
Deleted legacy monolithic E2E workflow (checkout, pnpm/Node setup, build, Playwright install, test run, artifact upload).
Build
.github/workflows/pr-ci-build.yml
New callable build workflow: checkout, pnpm/Node v20 setup, pnpm store/cache, install (--no-frozen-lockfile), build, upload artifacts (packages/components/dist, packages/kit/dist, packages/svgs/dist).
E2E Test
.github/workflows/pr-ci-e2e-test.yml
New callable E2E workflow: checkout, pnpm/Node v20, cache pnpm store, install, download artifacts into packages, install Playwright browsers, run tests, upload Playwright report (13-day retention).
Preview / Deploy
.github/workflows/pr-ci-preview.yml
New callable preview workflow: checkout, pnpm/Node v20, cache, install, download artifacts, build docs, publish packages to pkg-pr-new (output.json), deploy docs to Surge (PR-specific domain), post/update PR comments with preview links and status.
Orchestrator (PR CI)
.github/workflows/pr-ci.yml
New orchestrator: triggers on push/PR, concurrency cancel, runs build (calls pr-ci-build.yml, supports skip-playground), then preview and e2e-test via workflow_call; preview runs only for PRs and depends on build.
PR Cleanup
.github/workflows/pr-cleanup.yml
New cleanup workflow on PR close: teardown Surge deployment for PR subdomain, post cleanup status comment using maintain-one-comment action.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant GitHub as GitHub Events
    participant Orchestrator as .github/workflows/pr-ci.yml
    participant BuildWF as pr-ci-build.yml
    participant ArtifactStore as Actions Artifacts
    participant E2EWF as pr-ci-e2e-test.yml
    participant PreviewWF as pr-ci-preview.yml
    participant Surge as Surge (deploy/teardown)
    participant Playwright as Playwright Test Runner

    Note over GitHub,Orchestrator: PR opened / push triggers CI
    GitHub ->> Orchestrator: trigger pr-ci.yml
    Orchestrator ->> BuildWF: workflow_call (skip-playground?)
    BuildWF ->> ArtifactStore: upload build-${github.sha}.zip
    BuildWF -->> Orchestrator: success

    par Parallel flows
        Orchestrator ->> E2EWF: workflow_call (provides artifact)
        E2EWF ->> ArtifactStore: download build artifact
        E2EWF ->> Playwright: install browsers & run tests
        Playwright -->> E2EWF: test report
        E2EWF ->> ArtifactStore: upload report (retain 13d)
    and
        Orchestrator ->> PreviewWF: workflow_call (pr-number)
        PreviewWF ->> ArtifactStore: download build artifact
        PreviewWF ->> Surge: deploy docs to PR subdomain
        Surge -->> PreviewWF: deployed URL
        PreviewWF ->> GitHub: post/update PR comment with preview links
    end

    Note over GitHub,Surge: On PR close
    GitHub ->> Surge: pr-cleanup.yml -> surge teardown (PR domain) 
    Surge -->> GitHub: teardown result (comment posted)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 I hopped through CI wires, tidy and spry,

Built the bits, pushed previews up high,
Tests danced with Playwright under moonbeam,
Surge swept the meadow, cleaned every stream,
A tiny rabbit cheers — pipelines gleam!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title 'ci: workflow support for dependency preview and online docs' accurately summarizes the main change—adding GitHub Actions workflows for PR preview functionality including package previews and documentation deployment.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@SonyLeo
SonyLeo marked this pull request as ready for review December 23, 2025 08:59
@SonyLeo SonyLeo changed the title feat: Pipeline support for dependency preview and online docs feat: workflow support for dependency preview and online docs Dec 23, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

🧹 Nitpick comments (6)
.github/workflows/pr-ci-build.yml (2)

6-9: Unused workflow input parameter.

The skip-playground input is declared but never referenced in the workflow steps. If playground builds should be conditionally skipped, add a corresponding conditional to the build step. Otherwise, remove this unused parameter.


39-40: Consider using frozen lockfile for build consistency.

Using --no-frozen-lockfile allows dependency versions to drift between CI runs, potentially causing inconsistent builds. For production CI pipelines, consider using the default frozen lockfile behavior to ensure reproducible builds.

If lockfile updates are intentional (e.g., for dependency updates), this flag is acceptable, but be aware of potential version drift.

.github/workflows/pr-ci-preview.yml (2)

35-36: Consider using frozen lockfile for build consistency.

Using --no-frozen-lockfile allows dependency versions to drift between CI runs. For reproducible builds, consider using the default frozen lockfile behavior unless lockfile updates are intentionally required.


71-116: Consider extracting complex inline JavaScript to a separate action.

The inline JavaScript for managing PR comments spans 45 lines and could be difficult to maintain and test. For improved modularity and reusability, consider extracting this logic to a separate composite action or JavaScript file.

That said, for a single-use case, inline scripts are acceptable, so this is an optional improvement.

.github/workflows/pr-ci-e2e-test.yml (1)

35-36: Consider using frozen lockfile for build consistency.

Using --no-frozen-lockfile allows dependency versions to drift between CI runs. For reproducible test environments, consider using the default frozen lockfile behavior.

.github/workflows/pr-ci.yml (1)

27-29: Passing unused workflow input.

The skip-playground: true input is passed to the build workflow, but as noted in the review of pr-ci-build.yml, this parameter is not used. Either implement the skip logic in the build workflow or remove this parameter.

📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b775495 and b004883.

📒 Files selected for processing (6)
  • .github/workflows/e2e-tests.yml
  • .github/workflows/pr-ci-build.yml
  • .github/workflows/pr-ci-e2e-test.yml
  • .github/workflows/pr-ci-preview.yml
  • .github/workflows/pr-ci.yml
  • .github/workflows/pr-cleanup.yml
💤 Files with no reviewable changes (1)
  • .github/workflows/e2e-tests.yml
🧰 Additional context used
🪛 actionlint (1.7.9)
.github/workflows/pr-ci-build.yml

32-32: the runner of "actions/cache@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

.github/workflows/pr-ci-preview.yml

28-28: the runner of "actions/cache@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

.github/workflows/pr-ci-e2e-test.yml

28-28: the runner of "actions/cache@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🔇 Additional comments (2)
.github/workflows/pr-ci-e2e-test.yml (1)

6-58: LGTM on workflow structure!

The E2E test workflow is well-structured with appropriate timeouts, artifact handling, and test report retention. The use of if: always() for test report uploads ensures reports are available even when tests fail.

.github/workflows/pr-ci.yml (1)

9-12: LGTM on concurrency configuration!

The concurrency setup correctly uses PR number for pull requests and git ref for push events, with cancel-in-progress: true to avoid duplicate workflow runs. This is a best practice for CI efficiency.

Comment thread .github/workflows/pr-ci-build.yml
Comment thread .github/workflows/pr-ci-e2e-test.yml
Comment thread .github/workflows/pr-ci-preview.yml
Comment thread .github/workflows/pr-ci-preview.yml
Comment thread .github/workflows/pr-ci.yml
Comment thread .github/workflows/pr-cleanup.yml

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
.github/workflows/pr-ci-preview.yml (1)

123-131: SURGE_TOKEN handling still not addressed (see previous review).

Per the PR objectives, SURGE_TOKEN should be optional—package previews should work even without it. Currently, if SURGE_TOKEN is not configured, the entire workflow fails, preventing package preview comments from being posted.

🔎 Proposed fix to make Surge deployment optional
       - name: Deploy Site to Surge
         id: deploy
+        if: ${{ secrets.SURGE_TOKEN != '' }}
         run: |
           DEPLOY_DOMAIN=preview-${{ inputs.pr-number }}-tiny-robot.surge.sh
           echo "Deploying to: https://$DEPLOY_DOMAIN"
           npx surge --project ./docs/dist --domain $DEPLOY_DOMAIN --token $SURGE_TOKEN
           echo "url=https://$DEPLOY_DOMAIN" >> $GITHUB_OUTPUT
         env:
           SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }}
+        continue-on-error: true

Note: Secret values cannot be directly checked in if conditions. An alternative approach is to use an environment variable check:

       - name: Deploy Site to Surge
         id: deploy
+        if: env.HAS_SURGE_TOKEN == 'true'
         run: |
           DEPLOY_DOMAIN=preview-${{ inputs.pr-number }}-tiny-robot.surge.sh
           echo "Deploying to: https://$DEPLOY_DOMAIN"
           npx surge --project ./docs/dist --domain $DEPLOY_DOMAIN --token $SURGE_TOKEN
           echo "url=https://$DEPLOY_DOMAIN" >> $GITHUB_OUTPUT
         env:
           SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }}
+          HAS_SURGE_TOKEN: ${{ secrets.SURGE_TOKEN != '' }}
🧹 Nitpick comments (3)
.github/workflows/pr-ci.yml (1)

18-29: Skip conditions may trigger false positives for certain PR titles.

The startsWith checks for 'v' and 'V' (lines 23-24) could unintentionally skip builds for PRs with titles like "Various improvements" or "Validate input". Consider using a more specific pattern like checking for a version format (e.g., v1. or matching vX.Y.Z).

🔎 Suggested refinement
         contains(github.event.pull_request.title, 'docs:') ||
         contains(github.event.pull_request.title, 'chore: release') ||
-        startsWith(github.event.pull_request.title, 'v') ||
-        startsWith(github.event.pull_request.title, 'V')
+        startsWith(github.event.pull_request.title, 'v1') ||
+        startsWith(github.event.pull_request.title, 'v2') ||
+        startsWith(github.event.pull_request.title, 'V1') ||
+        startsWith(github.event.pull_request.title, 'V2')

Alternatively, use a regex in a separate job step if more precise version matching is needed.

.github/workflows/pr-ci-preview.yml (2)

40-41: Consider using --frozen-lockfile for reproducible CI builds.

Using --no-frozen-lockfile allows dependency resolution to differ from what's committed, which could lead to inconsistent preview builds. For CI environments, --frozen-lockfile is typically preferred to ensure reproducibility.

🔎 Proposed fix
       - name: Install dependencies
-        run: pnpm i --no-frozen-lockfile
+        run: pnpm i --frozen-lockfile

If there's a specific reason for using --no-frozen-lockfile (e.g., monorepo constraints), please document it in a comment.


52-63: Redundant github.event_name check.

Since this workflow is only called when github.event_name == 'pull_request' (enforced by the caller at line 34 of pr-ci.yml), the condition at line 53 is always true. The same applies to lines 77, 134, and 150. Consider removing these redundant checks for clarity, or keep them as defensive programming.

📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b004883 and 09651b1.

📒 Files selected for processing (4)
  • .github/workflows/pr-ci-build.yml
  • .github/workflows/pr-ci-e2e-test.yml
  • .github/workflows/pr-ci-preview.yml
  • .github/workflows/pr-ci.yml
🚧 Files skipped from review as they are similar to previous changes (2)
  • .github/workflows/pr-ci-build.yml
  • .github/workflows/pr-ci-e2e-test.yml
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: preview / preview
  • GitHub Check: e2e-test / e2e-test
🔇 Additional comments (4)
.github/workflows/pr-ci.yml (1)

31-43: LGTM!

The orchestration structure is well-designed with proper job dependencies. The pr-number input is now correctly passed to the preview workflow, addressing the previous review feedback.

.github/workflows/pr-ci-preview.yml (3)

1-9: LGTM!

The pr-number input parameter is correctly defined, addressing the previous review feedback about github.event.number not being available in workflow_call context.


32-38: LGTM!

Cache action upgraded to v4 as recommended in previous review.


76-121: LGTM!

The package preview comment logic correctly handles both creating new comments and updating existing ones. The use of context.payload.pull_request works correctly since the calling workflow is triggered by a pull_request event.

Comment thread .github/workflows/pr-ci-preview.yml

@hexqi hexqi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hexqi hexqi closed this Dec 25, 2025
@hexqi hexqi reopened this Dec 25, 2025
@SonyLeo SonyLeo closed this Dec 25, 2025
@SonyLeo SonyLeo reopened this Dec 25, 2025
@SonyLeo SonyLeo closed this Dec 25, 2025
@SonyLeo SonyLeo reopened this Dec 25, 2025
@hexqi hexqi changed the title feat: workflow support for dependency preview and online docs ci: workflow support for dependency preview and online docs Dec 25, 2025
@hexqi
hexqi merged commit 0b9fdb4 into opentiny:develop Dec 25, 2025
10 of 18 checks passed
gene9831 pushed a commit to gene9831/tiny-robot that referenced this pull request Dec 30, 2025
gene9831 pushed a commit to gene9831/tiny-robot that referenced this pull request Dec 30, 2025
gene9831 pushed a commit to gene9831/tiny-robot that referenced this pull request Dec 30, 2025
gene9831 pushed a commit to gene9831/tiny-robot that referenced this pull request Dec 30, 2025
@SonyLeo
SonyLeo deleted the feat/ci-optimize branch December 31, 2025 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants