-
Notifications
You must be signed in to change notification settings - Fork 257
186 lines (161 loc) · 5.74 KB
/
Check_PR_Update.yml
File metadata and controls
186 lines (161 loc) · 5.74 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
name: Test deployment
permissions:
contents: read
statuses: write
on:
pull_request:
paths-ignore:
- "ISSUE_TEMPLATE/**"
- ".github/**.md"
- ".gitignore"
- "demo/**"
- "docker/**"
- "HOW_TO.md"
- "TASK.md"
- "SECURITY.md"
- "README.md"
- "README_zh-CN.md"
# Review gh actions docs if you want to further define triggers, paths, etc
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on
# 添加push事件,确保翻译后的提交也会触发检查
push:
# 只在PR分支上触发,避免在主分支上重复运行
branches-ignore:
- main
- master
- docusaurus-version
paths-ignore:
- "ISSUE_TEMPLATE/**"
- ".github/**.md"
- ".gitignore"
- "demo/**"
- "docker/**"
- "HOW_TO.md"
- "TASK.md"
- "SECURITY.md"
- "README.md"
- "README_zh-CN.md"
# 添加workflow_dispatch,允许从其他工作流触发
workflow_dispatch:
inputs:
pr_number:
description: 'PR number to test'
required: true
type: string
ref:
description: 'Branch or commit to test'
required: true
type: string
head_repo:
description: 'Head repo full_name (owner/repo)'
required: false
type: string
trigger_source:
description: 'What triggered this test'
required: false
type: string
default: 'manual'
env:
NODE_OPTIONS: --max-old-space-size=6144
DOCUSAURUS_IGNORE_SSG_WARNINGS: "true"
jobs:
test-deploy:
name: Test deployment
runs-on: ubuntu-latest
steps:
- name: Get PR info (for workflow_dispatch)
if: github.event_name == 'workflow_dispatch'
id: pr-info
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const pr_number = '${{ inputs.pr_number }}';
const inputRef = '${{ inputs.ref }}';
const inputHeadRepo = '${{ inputs.head_repo }}';
try {
const { data: pr } = await github.rest.pulls.get({
owner, repo, pull_number: parseInt(pr_number)
});
core.setOutput('sha', pr.head.sha);
core.setOutput('ref', pr.head.ref);
core.setOutput('head-repo', pr.head.repo.full_name);
core.info(`PR #${pr_number}: head=${pr.head.repo.full_name} ref=${pr.head.ref} sha=${pr.head.sha}`);
} catch (error) {
core.warning('Failed to get PR via API, fallback to inputs: ' + error.message);
core.setOutput('sha', inputRef); // 只是占位;稍后 checkout 后我们不会用它
core.setOutput('ref', inputRef);
core.setOutput('head-repo', inputHeadRepo || '');
}
- uses: actions/checkout@v4
with:
repository: ${{ github.event_name == 'workflow_dispatch' && steps.pr-info.outputs['head-repo'] || github.repository }}
ref: ${{ steps.pr-info.outputs.ref || github.ref }}
- uses: actions/setup-node@v3
with:
node-version: 20
cache: yarn
- name: Add extra swap (4G)
run: |
set -euxo pipefail
echo "== Before =="
sudo swapon --show || true
free -h
SWAP=/mnt/ci.swap
# 如果之前同名 swap 存在,先关闭并删除(保证重跑也不会炸)
if [ -f "$SWAP" ]; then
sudo swapoff "$SWAP" || true
sudo rm -f "$SWAP"
fi
# 创建 4G swap(fallocate 不可用就用 dd 兜底)
sudo fallocate -l 4G "$SWAP" || sudo dd if=/dev/zero of="$SWAP" bs=1M count=6144 status=progress
sudo chmod 600 "$SWAP"
sudo mkswap "$SWAP"
sudo swapon "$SWAP"
echo "== After =="
sudo swapon --show || true
free -h
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Create shared symlinks
run: |
set -euxo pipefail
ROOT_ASSETS="$GITHUB_WORKSPACE/assets"
for site in sites/en sites/zh-CN sites/ja sites/es; do
rm -rf "$site/assets"
ln -s "$ROOT_ASSETS" "$site/assets"
done
- name: Test build website
run: yarn build
# 报告状态到PR(不添加评论)
- name: Report status to PR
if: always()
continue-on-error: true
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const success = '${{ job.status }}' === 'success';
let sha;
if (context.eventName === 'pull_request') {
sha = context.payload.pull_request.head.sha;
} else if (context.eventName === 'workflow_dispatch') {
sha = '${{ steps.pr-info.outputs.sha }}' || '${{ inputs.ref }}';
} else {
sha = context.sha;
}
const statusContext = 'Test deployment (required)';
try {
await github.rest.repos.createCommitStatus({
owner,
repo,
sha,
state: success ? 'success' : 'failure',
target_url: `https://github.com/${owner}/${repo}/actions/runs/${{ github.run_id }}`,
description: success ? '✅ Build succeeded' : '❌ Build failed',
context: statusContext
});
core.info(`Status reported on ${sha}: ${statusContext} = ${success ? 'success' : 'failure'}`);
} catch (error) {
core.warning('Failed to report status: ' + error.message);
}