-
Notifications
You must be signed in to change notification settings - Fork 0
194 lines (161 loc) · 5.49 KB
/
deploy.yml
File metadata and controls
194 lines (161 loc) · 5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
name: Deploy to Cloudflare Pages
on:
# 仅允许手动触发,不自动部署
workflow_dispatch:
inputs:
environment:
description: '部署环境'
required: true
default: 'production'
type: choice
options:
- production
- staging
# 保留 PR 预览功能
pull_request:
branches:
- main
# 取消正在运行的旧部署
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# ==========================================
# 代码质量检查
# ==========================================
quality-check:
name: Quality Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: TypeScript check
run: npx tsc --noEmit
- name: Run tests
run: npm test -- --run
- name: Check for console.log
run: |
if grep -r "console\." src/ --include="*.ts" --include="*.tsx" | grep -v "console.error"; then
echo "⚠️ Warning: Found console statements in source code"
fi
# ==========================================
# 安全检查
# ==========================================
security-check:
name: Security Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run security audit
run: npm audit --production --audit-level=high
continue-on-error: true
# ==========================================
# 构建和部署
# ==========================================
deploy:
name: Build and Deploy
runs-on: ubuntu-latest
needs: [quality-check, security-check]
# 仅在手动触发时部署
if: github.event_name == 'workflow_dispatch'
permissions:
contents: read
deployments: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build project
run: npm run build
env:
NODE_ENV: production
- name: Check build output
run: |
if [ ! -d "dist" ]; then
echo "❌ Build directory not found"
exit 1
fi
if [ ! -f "dist/index.html" ]; then
echo "❌ index.html not found in build output"
exit 1
fi
echo "✅ Build output validated"
echo "📦 Build size: $(du -sh dist | cut -f1)"
- name: Deploy to Cloudflare Pages
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy dist --project-name=perlou-httping
- name: Deployment summary
run: |
echo "## 🚀 Deployment Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "✅ Successfully deployed to Cloudflare Pages" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "🔗 **URL**: https://httping.pages.dev" >> $GITHUB_STEP_SUMMARY
echo "📦 **Build size**: $(du -sh dist | cut -f1)" >> $GITHUB_STEP_SUMMARY
echo "🕐 **Time**: $(date -u '+%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_STEP_SUMMARY
echo "📝 **Commit**: ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
# ==========================================
# PR 预览部署
# ==========================================
preview:
name: Preview Deployment
runs-on: ubuntu-latest
needs: [quality-check]
# 仅在 PR 时运行
if: github.event_name == 'pull_request'
permissions:
contents: read
deployments: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build project
run: npm run build
- name: Deploy preview
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy dist --project-name=perlou-httping --branch=preview-${{ github.event.pull_request.number }}
- name: Comment on PR
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `## 🔍 Preview Deployment\n\n✅ Preview deployed successfully!\n\n🔗 **Preview URL**: https://preview-${{ github.event.pull_request.number }}.httping.pages.dev\n\n📝 This preview will be updated on each commit to this PR.`
})