-
Notifications
You must be signed in to change notification settings - Fork 7
fix: 解决提交pr也触发cloudflare推送,但没有Token触发失败的问题! #445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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天,省空间 |
| 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: | ||
| 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' | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| directory: 'dist' # 直接推送刚才下载的 dist 目录 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
There was a problem hiding this comment.
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 broaderGITHUB_TOKENscope than needed. Add least-privilege permissions (for exampleactions: read,contents: read, and only additional scopes strictly required by the deploy step).