ci: workflow support for dependency preview and online docs - #268
Conversation
…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
WalkthroughRefactors 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
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)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 7
🧹 Nitpick comments (6)
.github/workflows/pr-ci-build.yml (2)
6-9: Unused workflow input parameter.The
skip-playgroundinput 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-lockfileallows 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-lockfileallows 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-lockfileallows 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: trueinput is passed to the build workflow, but as noted in the review ofpr-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
📒 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: trueto avoid duplicate workflow runs. This is a best practice for CI efficiency.
There was a problem hiding this comment.
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_TOKENshould be optional—package previews should work even without it. Currently, ifSURGE_TOKENis 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: trueNote: Secret values cannot be directly checked in
ifconditions. 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
startsWithchecks 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 matchingvX.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-lockfilefor reproducible CI builds.Using
--no-frozen-lockfileallows dependency resolution to differ from what's committed, which could lead to inconsistent preview builds. For CI environments,--frozen-lockfileis typically preferred to ensure reproducibility.🔎 Proposed fix
- name: Install dependencies - run: pnpm i --no-frozen-lockfile + run: pnpm i --frozen-lockfileIf there's a specific reason for using
--no-frozen-lockfile(e.g., monorepo constraints), please document it in a comment.
52-63: Redundantgithub.event_namecheck.Since this workflow is only called when
github.event_name == 'pull_request'(enforced by the caller at line 34 ofpr-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
📒 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-numberinput 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-numberinput parameter is correctly defined, addressing the previous review feedback aboutgithub.event.numbernot being available inworkflow_callcontext.
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_requestworks correctly since the calling workflow is triggered by a pull_request event.
✨ PR 预览功能
每次提交 PR 时会自动:
📸 效果预览
PR 中会显示两条自动更新的评论:
完整预览
评论 1 - 构建状态和预览链接
构建中:
构建成功:
构建失败:
评论 2 - 包安装命令
关键特性:
自动跳过规则
以下情况会跳过构建和测试:
docs:或chore: releasev或V开头(版本发布)🚀 仓库维护者必读:启用配置
✅ 必需配置
1. 安装 pkg.pr.new GitHub App
操作步骤:
Install或Configure验证方式:
Settings→Integrations→GitHub Appspkg.pr.new已安装🔧 可选配置
2. 配置 Surge Token(用于文档预览)
谁来做:仓库管理员(拥有 Settings 权限)
操作步骤:
步骤 A:获取 Surge Token
步骤 B:添加到 GitHub Secrets
Settings→Secrets and variables→ActionsNew repository secretSURGE_TOKENAdd secret验证方式:
Settings→Secrets and variables→Actions中看到SURGE_TOKEN🧪 验证配置
配置完成后,仓库维护者或任何贡献者都可以创建测试 PR 验证:
创建新分支并提交修改
在 GitHub 上创建 PR
检查以下内容:
Actions标签页显示工作流正在运行pnpm add命令)如果一切正常,删除测试 PR
🌐 Surge 预览说明
预览站点特性
preview-{PR编号}-tiny-robot.surge.sh预览状态说明
常见场景
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.