-
Notifications
You must be signed in to change notification settings - Fork 56
126 lines (109 loc) · 4.09 KB
/
Copy pathdeploy.yml
File metadata and controls
126 lines (109 loc) · 4.09 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
name: Deploy Web3 Learning Platform
on:
push:
branches: [main]
pull_request:
branches: [main]
# 允许手动触发部署
workflow_dispatch:
jobs:
build-and-deploy:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout 📁
uses: actions/checkout@v6
- name: Setup Node.js 🟢
uses: actions/setup-node@v6
with:
node-version: '20'
cache: 'npm'
- name: Install Dependencies 📦
# On pull_request (incl. Dependabot): use `npm install` so transient
# lockfile drift doesn't block CI. On push to main / manual dispatch:
# use strict `npm ci` to guarantee reproducible production builds.
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
npm install --no-audit --no-fund
else
npm ci
fi
- name: Install Playwright Chromium 🎭
run: npx playwright install chromium
- name: Run Tests 🧪
run: npm test
- name: Check translation coverage
run: node scripts/check-translation-coverage.mjs
- name: Build Application 🔨
run: npm run build
env:
VITE_GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
VITE_SITE_BASE_URL: https://bhbtc.xyz
SITE_BASE_URL: https://bhbtc.xyz
VITE_BASE_PATH: /
VITE_GITHUB_USERNAME: ${{ vars.GITHUB_USERNAME || 'beihaili' }}
VITE_GITHUB_REPO: ${{ vars.GITHUB_REPO || 'Get-Started-with-Web3' }}
VITE_GITHUB_BRANCH: ${{ vars.GITHUB_BRANCH || 'main' }}
- name: Deploy to GitHub Pages 🚀
if: github.ref == 'refs/heads/main'
uses: peaceiris/actions-gh-pages@v4.1.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist
cname: bhbtc.xyz
- name: Upload PR build artifact 📦
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v7
with:
name: pr-${{ github.event.pull_request.number }}-dist
path: ./dist
if-no-files-found: error
retention-days: 7
- name: Comment PR with Preview Link 💬
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
uses: actions/github-script@v9
with:
script: |
const marker = '<!-- pr-preview-artifact-link -->';
const runUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`;
const body = [
marker,
'📦 **构建成功!** PR 构建产物已上传,可从 Actions run 页面下载 `dist` artifact 进行本地预览。',
'',
`- 🔎 [打开本次 Actions run / 下载构建产物](${runUrl})`,
'- 🚀 合并到 `main` 后会自动部署到生产环境。',
].join('\n');
const { owner, repo } = context.repo;
const issue_number = context.issue.number;
const comments = await github.rest.issues.listComments({
owner,
repo,
issue_number,
per_page: 100,
});
const previousComment = comments.data.find((comment) => (
comment.user?.type === 'Bot' && comment.body?.includes(marker)
));
if (previousComment) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id: previousComment.id,
body,
});
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body,
});
}
- name: Output deployment URL 🌐
if: github.ref == 'refs/heads/main'
run: |
echo "🚀 部署完成!"
echo "📍 网站地址: https://bhbtc.xyz/"
echo "⏰ 部署时间: $(date '+%Y-%m-%d %H:%M:%S')"