1+ name : Test deployment
2+
3+ on :
4+ pull_request :
5+ branches :
6+ - main
7+ paths :
8+ - ' docs/**'
9+ - ' .github/workflows/test-deploy.yml'
10+ workflow_dispatch : # 允许手动触发
11+
12+ jobs :
13+ test-deploy :
14+ name : Test deployment
15+ runs-on : ubuntu-latest
16+ timeout-minutes : 20
17+
18+ steps :
19+ - name : Checkout repository
20+ uses : actions/checkout@v4
21+ with :
22+ fetch-depth : 0
23+
24+ - name : Setup
25+ uses : ./.github/actions/setup
26+
27+ - name : Type check
28+ working-directory : docs
29+ run : yarn typecheck
30+
31+ - name : Lint check
32+ working-directory : docs
33+ run : |
34+ if yarn lint 2>/dev/null; then
35+ echo "✅ Lint check passed"
36+ else
37+ echo "⚠️ No lint script found, skipping lint check"
38+ fi
39+
40+ - name : Test build website
41+ working-directory : docs
42+ run : yarn build
43+ env :
44+ NODE_ENV : production
45+
46+ - name : Verify build output
47+ id : verify-build
48+ run : |
49+ if [ ! -d "docs/build" ]; then
50+ echo "❌ Build directory not found"
51+ exit 1
52+ fi
53+
54+ # 检查关键文件是否存在
55+ if [ ! -f "docs/build/index.html" ]; then
56+ echo "❌ index.html not found in build output"
57+ exit 1
58+ fi
59+
60+ echo "✅ Build completed successfully"
61+ echo "📁 Build directory contents:"
62+ ls -la docs/build/
63+
64+ # 检查构建大小
65+ BUILD_SIZE=$(du -sh docs/build | cut -f1)
66+ echo "build-size=$BUILD_SIZE" >> $GITHUB_OUTPUT
67+ echo "📊 Build size: $BUILD_SIZE"
68+
69+ - name : Test serve locally
70+ working-directory : docs
71+ run : |
72+ # 启动本地服务器进行测试
73+ timeout 30s yarn serve --port 3000 &
74+ SERVER_PID=$!
75+
76+ # 等待服务器启动
77+ sleep 10
78+
79+ # 测试服务器是否响应
80+ if curl -f http://localhost:3000 > /dev/null 2>&1; then
81+ echo "✅ Local server test passed"
82+ else
83+ echo "❌ Local server test failed"
84+ exit 1
85+ fi
86+
87+ # 清理进程
88+ kill $SERVER_PID 2>/dev/null || true
89+
90+ - name : Comment on PR
91+ if : github.event_name == 'pull_request'
92+ uses : actions/github-script@v7
93+ with :
94+ script : |
95+ const buildSize = '${{ steps.verify-build.outputs.build-size }}' || 'Unknown';
96+
97+ github.rest.issues.createComment({
98+ issue_number: context.issue.number,
99+ owner: context.repo.owner,
100+ repo: context.repo.repo,
101+ body: `🧪 **Test deployment completed successfully!**
102+
103+ ✅ **Type check**: Passed
104+ ✅ **Build**: Successful
105+ ✅ **Local server test**: Passed
106+ 📊 **Build size**: ${buildSize}
107+
108+ The documentation build is ready for deployment. 🚀`
109+ })
110+
111+ - name : Upload build artifacts for inspection
112+ uses : actions/upload-artifact@v4
113+ if : always()
114+ with :
115+ name : test-build-artifacts
116+ path : docs/build/
117+ retention-days : 7
118+ if-no-files-found : error
0 commit comments