Skip to content

Conversation

@wuyiping0628
Copy link
Collaborator

@wuyiping0628 wuyiping0628 commented Dec 17, 2025

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • Chores
    • Added an automated documentation build workflow that runs on pull requests and dev-branch pushes, builds the main docs, and updates PR status checks with success or failure.
    • The workflow handles private submodule access and dependency setup so docs are built reliably during CI.

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

@coderabbitai
Copy link

coderabbitai bot commented Dec 17, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Adds a GitHub Actions workflow that runs on pull requests and pushes to the dev branch to fetch and sync submodules, build the main module documentation with pnpm, and update the pull request status based on the build result.

Changes

Cohort / File(s) Summary
GitHub Actions Workflow
\.github/workflows/auto-build-main-module-docs\.yml
New workflow triggered on PRs and pushes to dev; sets up SSH and submodule access, checks out main repo and submodule, fetches PR head in submodule, pins pnpm v9, installs deps, builds docs (VitePress-like), and updates PR status on success/failure

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant PR as Pull Request
  participant GH as GitHub Actions
  participant SSH as SSH Agent
  participant Sub as Submodule Repo (tiny-vue)
  participant Main as Main Repo
  participant PNPM as pnpm (v9)
  participant CI as Docs Build
  participant API as GitHub API (status)

  PR->>GH: trigger (PR opened/updated or push to dev)
  GH->>SSH: start agent & add private key
  GH->>Main: checkout main repo, init submodules
  GH->>Sub: checkout/fetch PR head branch in submodule
  Sub-->>Main: update submodule ref in docs/
  GH->>PNPM: setup pnpm v9
  GH->>PNPM: install dependencies (from docs/)
  GH->>CI: run docs build command
  alt build success
    CI-->>API: report success
    API-->>PR: update PR status (success)
  else build failure
    CI-->>API: report failure
    API-->>PR: update PR status (failure)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Verify SSH/key handling and security posture for submodule access
  • Check correctness of git commands that fetch PR head in the submodule and update main repo refs
  • Validate pnpm v9 setup, install steps, and build commands (VitePress assumptions)
  • Confirm PR status update logic and error handling paths

Poem

🐇 I hopped through branches, keys held tight,
Pulled tiny-vue into the light,
Pinned pnpm, built docs with a cheer,
I left a status so reviewers see clear —
A rabbit's nod: the pipeline's here! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Title check ⚠️ Warning The title contains a typo ('auot' instead of 'auto') and a [wip] prefix indicating work-in-progress status, which is unconventional for a PR title. While it does relate to the main change (adding a workflow for building docs), the presentation is unprofessional. Remove the [wip] prefix and fix the typo: change to 'feat: add auto build main module docs workflow' or similar clear, professional title.
✅ Passed checks (2 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.

📜 Recent review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5c0b64f and 9151f9b.

📒 Files selected for processing (1)
  • .github/workflows/auto-build-main-module-docs.yml (1 hunks)

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.

@wuyiping0628 wuyiping0628 added the enhancement New feature or request (功能增强) label Dec 17, 2025
@wuyiping0628 wuyiping0628 changed the title Wyp/build docs 1217 feat: add auot build main module docs yml Dec 17, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
.github/workflows/auto-build-main-module-docs.yml (1)

63-72: Quote the shell variable and consider using gh CLI for actual PR status updates.

  1. The shell comparison should quote the outcome variable:
-        if [ ${{ steps.build.outcome }} == 'success' ]; then
+        if [ "${{ steps.build.outcome }}" == 'success' ]; then
  1. The step name "Update PR status" is misleading—it only echoes to logs. If you want to actually comment on the PR, use the GitHub CLI:
    - name: Update PR status
      if: always() && github.event_name == 'pull_request'
      env:
        GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      run: |
        if [ "${{ steps.build.outcome }}" == 'success' ]; then
          gh pr comment ${{ github.event.pull_request.number }} --body "✅ 主仓库构建成功"
        else
          gh pr comment ${{ github.event.pull_request.number }} --body "❌ 主仓库构建失败"
          exit 1
        fi
📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f018f4f and a698cec.

📒 Files selected for processing (1)
  • .github/workflows/auto-build-main-module-docs.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.9)
.github/workflows/auto-build-main-module-docs.yml

27-27: "github.head_ref" is potentially untrusted. avoid using it directly in inline scripts. instead, pass it through an environment variable. see https://docs.github.com/en/actions/reference/security/secure-use#good-practices-for-mitigating-script-injection-attacks for more details

(expression)

🔇 Additional comments (2)
.github/workflows/auto-build-main-module-docs.yml (2)

9-15: LGTM!

Job permissions are appropriately scoped with minimal required access.


17-24: SSH agent set up but main repo cloned via HTTPS.

The SSH agent is configured with SUBMODULE_SSH_KEY, but line 29 clones the docs repo via HTTPS. If submodules require SSH authentication, this may cause issues during git submodule update.

Consider cloning via SSH if the submodules require it:

-        git clone https://github.com/opentiny/docs.git docs
+        git clone git@github.com:opentiny/docs.git docs

Comment on lines 50 to 61
- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: 9

- name: Run main repo build
id: build
working-directory: ./docs
run: |
pnpm i
# 如果使用VitePress
pnpm build
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Missing Node.js setup step.

The workflow sets up pnpm but doesn't explicitly set up Node.js. Add actions/setup-node before pnpm setup for reliable builds and to enable pnpm caching:

+    - name: Setup Node.js
+      uses: actions/setup-node@v4
+      with:
+        node-version: '20'
+
     - name: Setup pnpm
       uses: pnpm/action-setup@v3
       with:
         version: 9
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: 9
- name: Run main repo build
id: build
working-directory: ./docs
run: |
pnpm i
# 如果使用VitePress
pnpm build
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: 9
- name: Run main repo build
id: build
working-directory: ./docs
run: |
pnpm i
# 如果使用VitePress
pnpm build
🤖 Prompt for AI Agents
.github/workflows/auto-build-main-module-docs.yml lines 50-61: the workflow
configures pnpm but never installs Node.js, which can cause inconsistent builds
and prevents enabling pnpm caching; add a step before the "Setup pnpm" step to
run actions/setup-node@v3 with a sensible node-version (or reference your
project’s engines field) and enable the pnpm cache (e.g., set cache: "pnpm" and
cache-dependency-path to your pnpm lockfile) so Node is present and pnpm caching
works reliably.

@wuyiping0628 wuyiping0628 changed the title feat: add auot build main module docs yml feat: add auot build main module docs yml Dec 17, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

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 (2)
.github/workflows/auto-build-main-module-docs.yml (2)

3-7: Critical: pull_request_target with PR code checkout exposes secrets.

Using pull_request_target runs the workflow with write permissions and access to secrets in the context of the base branch. Combined with checking out the PR code (line 21), this allows a malicious PR to exfiltrate secrets (SUBMODULE_SSH_KEY_PRIVATE, PAT_TOKEN) and execute arbitrary code with elevated permissions.

Additionally, github.head_ref is empty on push events, causing the git operations at lines 39-41 to fail.

Apply this diff to use the safer pull_request trigger:

 on:
-  pull_request_target:
+  pull_request:
     branches: [dev]
-  push:
-    branches: [dev]

If you need write permissions for PR comments, add them explicitly and avoid checking out untrusted PR code in the same job that has access to secrets.


26-48: Script injection vulnerability remains unaddressed.

Despite being marked as addressed in previous reviews, line 39 still uses github.head_ref directly in the shell script, which is user-controlled input (the PR branch name). An attacker could craft a malicious branch name like main; rm -rf / to inject arbitrary commands.

Additionally, line 40 uses the unquoted variable $BRANCH_NAME, which can cause issues with special characters.

Apply this diff to pass the branch name through an environment variable:

     - name: Checkout main repository
+      env:
+        BRANCH_NAME: ${{ github.head_ref }}
       run: |
         # 克隆主仓库
         git clone https://github.com/opentiny/docs.git docs
         cd docs
         
         # 更新子模块到PR分支的版本
         git submodule sync --recursive
         git submodule update --init --recursive

         
         # 获取PR分支的最新提交
         cd ./tiny-vue
-        BRANCH_NAME="${{ github.head_ref }}"
-        git fetch origin $BRANCH_NAME
-        git checkout $BRANCH_NAME
+        git fetch origin "$BRANCH_NAME"
+        git checkout "$BRANCH_NAME"

See GitHub's security hardening guide for details.

🧹 Nitpick comments (1)
.github/workflows/auto-build-main-module-docs.yml (1)

50-53: Add Node.js setup for reliability and caching.

While pnpm/action-setup may include a Node.js runtime, explicitly setting up Node.js ensures consistent versions and enables dependency caching for faster builds.

Apply this diff to add Node.js setup:

+    - name: Setup Node.js
+      uses: actions/setup-node@v4
+      with:
+        node-version: '20'
+        cache: 'pnpm'
+        cache-dependency-path: docs/pnpm-lock.yaml
+
     - name: Setup pnpm
       uses: pnpm/action-setup@v3
       with:
         version: 9
📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a698cec and 5c0b64f.

📒 Files selected for processing (1)
  • .github/workflows/auto-build-main-module-docs.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.9)
.github/workflows/auto-build-main-module-docs.yml

27-27: "github.head_ref" is potentially untrusted. avoid using it directly in inline scripts. instead, pass it through an environment variable. see https://docs.github.com/en/actions/reference/security/secure-use#good-practices-for-mitigating-script-injection-attacks for more details

(expression)

🔇 Additional comments (2)
.github/workflows/auto-build-main-module-docs.yml (2)

12-14: Permissions are appropriate for the workflow's purpose.

The contents: read and pull-requests: write permissions are correctly scoped for building docs and updating PR status. However, these permissions become a security risk when combined with pull_request_target (see comment on lines 3-7).


55-61: Build step logic is sound.

The build commands are appropriate for a pnpm-based documentation build. The working-directory correctly points to the cloned docs repository.

Consider adding set -e at the start of the run block to ensure the step fails fast on errors:

       run: |
+        set -e
         pnpm i
         # 如果使用VitePress
         pnpm build

Comment on lines +63 to +72
- name: Update PR status
if: always()
run: |
# 检查构建是否成功
if [ ${{ steps.build.outcome }} == 'success' ]; then
echo "✅ 主仓库构建成功"
else
echo "❌ 主仓库构建失败"
exit 1
fi
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix comparison syntax and consider actual PR status update.

Line 67 has a syntax issue with the shell comparison. The ${{ }} expression should be quoted or use GitHub's built-in expression syntax.

Additionally, this step only echoes the status and exits—it doesn't actually update the PR with a comment or status check as the step name suggests.

Apply this diff to fix the comparison:

       run: |
         # 检查构建是否成功
-        if [ ${{ steps.build.outcome }} == 'success' ]; then
+        if [ "${{ steps.build.outcome }}" == "success" ]; then
           echo "✅ 主仓库构建成功"
         else
           echo "❌ 主仓库构建失败"
           exit 1
         fi

If you want to actually update the PR, add a step using actions/github-script or the GitHub CLI to post a comment:

    - name: Comment on PR
      if: always() && github.event_name == 'pull_request'
      uses: actions/github-script@v7
      with:
        script: |
          const outcome = '${{ steps.build.outcome }}';
          const message = outcome === 'success' 
            ? '✅ Main repo docs build succeeded'
            : '❌ Main repo docs build failed';
          github.rest.issues.createComment({
            issue_number: context.issue.number,
            owner: context.repo.owner,
            repo: context.repo.repo,
            body: message
          });
🤖 Prompt for AI Agents
.github/workflows/auto-build-main-module-docs.yml lines 63-72: the shell
comparison uses an unquoted GitHub expression which breaks the if check and the
step only echoes status instead of updating the PR; change the if to use a
proper GitHub expression (for example quote the expression or use github's if:
expression syntax) or quote the expanded variable when used in shell, and
replace the echo/exit block with a real PR update step — add a follow-up step
that runs on always() and uses actions/github-script or the GitHub CLI to post a
comment or create a status check on the pull request indicating success or
failure, passing the build outcome into that script.

@wuyiping0628 wuyiping0628 changed the title feat: add auot build main module docs yml [wip]feat: add auot build main module docs yml Dec 17, 2025
@github-actions github-actions bot removed the enhancement New feature or request (功能增强) label Dec 17, 2025
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.

1 participant