Skip to content

Commit 0c6b1f4

Browse files
committed
chore: deploy workflow
1 parent 59e458c commit 0c6b1f4

File tree

2 files changed

+200
-0
lines changed

2 files changed

+200
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Deploy to GitHub Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'docs/**'
9+
- '.github/workflows/deploy.yml'
10+
workflow_dispatch: # 允许手动触发
11+
12+
jobs:
13+
build:
14+
name: Build Docusaurus
15+
runs-on: ubuntu-latest
16+
timeout-minutes: 15
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: Build website
32+
working-directory: docs
33+
run: yarn build
34+
env:
35+
NODE_ENV: production
36+
37+
- name: Verify build output
38+
run: |
39+
if [ ! -d "docs/build" ]; then
40+
echo "❌ Build directory not found"
41+
exit 1
42+
fi
43+
echo "✅ Build completed successfully"
44+
ls -la docs/build/
45+
46+
- name: Upload Build Artifact
47+
uses: actions/upload-pages-artifact@v3
48+
with:
49+
path: docs/build
50+
retention-days: 1
51+
52+
deploy:
53+
name: Deploy to GitHub Pages
54+
needs: build
55+
runs-on: ubuntu-latest
56+
timeout-minutes: 10
57+
58+
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
59+
permissions:
60+
pages: write # to deploy to Pages
61+
id-token: write # to verify the deployment originates from an appropriate source
62+
contents: read # to read repository contents
63+
64+
# Deploy to the github-pages environment
65+
environment:
66+
name: github-pages
67+
url: ${{ steps.deployment.outputs.page_url }}
68+
69+
steps:
70+
- name: Deploy to GitHub Pages
71+
id: deployment
72+
uses: actions/deploy-pages@v4
73+
74+
- name: Deployment status
75+
run: |
76+
if [ "${{ steps.deployment.outputs.page_url }}" != "" ]; then
77+
echo "✅ Deployment successful!"
78+
echo "🌐 Site URL: ${{ steps.deployment.outputs.page_url }}"
79+
else
80+
echo "❌ Deployment failed"
81+
exit 1
82+
fi

.github/workflows/test-deploy.yml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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

Comments
 (0)