Skip to content

Commit 87c930b

Browse files
author
weilei
committed
chore(ci): 更新 Vercel 部署工作流,添加缓存和评论部署 URL 功能
1 parent 7b9f1e6 commit 87c930b

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

.github/workflows/deploy.yml

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,38 @@ jobs:
4242
uses: actions/setup-node@v3
4343
with:
4444
node-version: '16'
45+
cache: 'npm'
46+
cache-dependency-path: 'docs/package-lock.json'
4547

4648
- name: Install dependencies
4749
working-directory: docs
48-
run: npm install
50+
run: npm ci
4951

5052
- name: Build documentation
5153
working-directory: docs
5254
run: npm run build
5355

5456
- name: Deploy to Vercel
55-
uses: amondnet/vercel-action@v20
57+
id: deploy-docs
58+
uses: amondnet/vercel-action@v25
5659
with:
5760
vercel-token: ${{ secrets.VERCEL_TOKEN }}
5861
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
5962
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID_DOCS }}
60-
vercel-args: ${{ github.event_name == 'push' && '--prod --cwd ./docs' || '--cwd ./docs' }}
63+
working-directory: ./docs
64+
vercel-args: ${{ github.event_name == 'push' && '--prod' || '' }}
65+
66+
- name: Comment deployment URL
67+
if: github.event_name == 'pull_request'
68+
uses: actions/github-script@v6
69+
with:
70+
script: |
71+
github.rest.issues.createComment({
72+
issue_number: context.issue.number,
73+
owner: context.repo.owner,
74+
repo: context.repo.repo,
75+
body: '📖 文档预览: ${{ steps.deploy-docs.outputs.preview-url }}'
76+
})
6177
6278
deploy-examples:
6379
name: 部署示例项目
@@ -72,19 +88,35 @@ jobs:
7288
uses: actions/setup-node@v3
7389
with:
7490
node-version: '16'
91+
cache: 'npm'
92+
cache-dependency-path: 'examples/package-lock.json'
7593

7694
- name: Install dependencies
7795
working-directory: examples
78-
run: npm install
96+
run: npm ci
7997

8098
- name: Build
8199
working-directory: examples
82100
run: npm run build
83101

84102
- name: Deploy to Vercel
85-
uses: amondnet/vercel-action@v20
103+
id: deploy-examples
104+
uses: amondnet/vercel-action@v25
86105
with:
87106
vercel-token: ${{ secrets.VERCEL_TOKEN }}
88107
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
89108
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID_EXAMPLES }}
90-
vercel-args: '--prod --cwd ./examples'
109+
working-directory: ./examples
110+
vercel-args: ${{ github.event_name == 'push' && '--prod' || '' }}
111+
112+
- name: Comment deployment URL
113+
if: github.event_name == 'pull_request'
114+
uses: actions/github-script@v6
115+
with:
116+
script: |
117+
github.rest.issues.createComment({
118+
issue_number: context.issue.number,
119+
owner: context.repo.owner,
120+
repo: context.repo.repo,
121+
body: '🚀 示例预览: ${{ steps.deploy-examples.outputs.preview-url }}'
122+
})

0 commit comments

Comments
 (0)