-
Notifications
You must be signed in to change notification settings - Fork 1
132 lines (109 loc) · 3.42 KB
/
ci-cd.yml
File metadata and controls
132 lines (109 loc) · 3.42 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
name: CI/CD Pipeline
on:
push:
branches: [ master, main ]
pull_request:
branches: [ master, main ]
jobs:
# 代码质量检查
quality:
name: 代码质量检查
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v3
- name: 设置 Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
- name: 安装依赖
run: npm ci
- name: 运行安全性测试
run: |
echo "运行安全性测试..."
node tests/security.test.js
- name: 检查 HTML 语法
run: |
echo "检查 HTML 文件..."
find . -name "*.html" -type f | while read file; do
echo "检查: $file"
# 这里可以添加 HTML 验证工具
done
# 性能测试
lighthouse:
name: Lighthouse 性能测试
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v3
- name: 运行 Lighthouse CI
uses: treosh/lighthouse-ci-action@v9
with:
uploadArtifacts: true
temporaryPublicStorage: true
urls: |
https://jacksoncode.github.io/
https://jacksoncode.github.io/nav.html
https://jacksoncode.github.io/blog.html
budgetPath: ./.github/lighthouse-budget.json
configPath: ./.github/lighthouse-config.json
# 链接检查
link-checker:
name: 链接有效性检查
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v3
- name: 链接检查
uses: lycheeverse/lychee-action@v1
with:
args: --verbose --no-progress --exclude "https://fonts.googleapis.com" --exclude "https://cdnjs.cloudflare.com"
fail: true
# 部署到 GitHub Pages
deploy:
name: 部署到 GitHub Pages
needs: [quality, lighthouse, link-checker]
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v3
- name: 设置 Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
- name: 安装依赖
run: npm ci
- name: 运行构建
run: npm run build || echo "无需构建步骤"
- name: 部署到 GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: .
force_orphan: true
commit_message: '自动部署: ${{ github.event.head_commit.message }}'
# 性能报告
report:
name: 生成性能报告
needs: [lighthouse]
runs-on: ubuntu-latest
if: always()
steps:
- name: 检出代码
uses: actions/checkout@v3
- name: 创建性能报告
run: |
echo "📊 性能测试报告" > performance-report.md
echo "" >> performance-report.md
echo "## Lighthouse 测试结果" >> performance-report.md
echo "" >> performance-report.md
echo "测试时间: $(date)" >> performance-report.md
echo "" >> performance-report.md
echo "详细结果请查看 Artifacts" >> performance-report.md
- name: 上传报告
uses: actions/upload-artifact@v3
with:
name: performance-report
path: performance-report.md