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
40 changes: 40 additions & 0 deletions .github/workflows/build-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Build PR (No Secrets)
on:
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 10

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install Dependencies
run: pnpm install
working-directory: ./www

- name: Setup Cloudflare Environment
run: echo "CF_PAGES=1" >> $GITHUB_ENV

- name: Build Docs
run: pnpm run docs:build
working-directory: ./www

# 关键:打包完成后,把 dist 文件夹上传暂存
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: pr-dist-folder
path: www/.vitepress/dist/
retention-days: 1 # 只保存1天,省空间
30 changes: 30 additions & 0 deletions .github/workflows/deploy-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Deploy PR Preview (Has Secrets)
on:
workflow_run:
workflows: ["Build PR (No Secrets)"] # 必须和第一棒的 name 保持完全一致
types:
- completed

jobs:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This job uses repository secrets but does not declare explicit permissions. Relying on repository defaults can grant broader GITHUB_TOKEN scope than needed. Add least-privilege permissions (for example actions: read, contents: read, and only additional scopes strictly required by the deploy step).

deploy:
runs-on: ubuntu-latest
# 确保第一棒成功了,这棒才跑
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
# 关键:用特殊的权限下载第一棒暂存的包裹
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: pr-dist-folder
path: dist # 下载到当前环境的 dist 目录
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}

# 直接拿下载好的静态文件去发布,不用再 install 和 build 了
- name: Deploy to Cloudflare Pages
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: 'neocode-docs'
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

workflow_run jobs run in the default-branch context. Without an explicit branch input here, this deployment can be attributed to the wrong branch (potentially main) instead of the PR branch, which risks promoting PR artifacts as production deployments. Please set branch explicitly (for example from github.event.workflow_run.head_branch) and keep preview deployments isolated from production branch semantics.

directory: 'dist' # 直接推送刚才下载的 dist 目录
7 changes: 4 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ on:
push:
branches:
- main
pull_request: # 组员提 PR 也会触发预览!

jobs:
deploy:
Expand All @@ -25,11 +24,13 @@ jobs:
node-version: 20

- name: Install Dependencies
run: CF_PAGES=1 pnpm install
run: pnpm install
working-directory: ./www # 假设你的目录叫 www



- name: Build Docs
run: pnpm run docs:build
run: CF_PAGES=1 pnpm run docs:build
working-directory: ./www

# 魔法时刻:强推到 Cloudflare Pages
Expand Down
1 change: 1 addition & 0 deletions www/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading