forked from PancakeCN/travellings
-
Notifications
You must be signed in to change notification settings - Fork 0
270 lines (231 loc) · 8.91 KB
/
issue-open.yml
File metadata and controls
270 lines (231 loc) · 8.91 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# Issue 创建时自动标记“待处理”标签
name: 【Open】Label and move to project on issue open
on:
issues:
types: [opened]
jobs:
label-issue:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Label issue
uses: andymckay/labeler@master
with:
add-labels: "待处理"
repo-token: ${{ secrets.GITHUB_TOKEN }}
auto-check-assistant:
strategy:
fail-fast: false
max-parallel: 3
defaults:
run:
shell: bash
working-directory: ./travellings-bot
runs-on: ubuntu-latest
outputs:
result: ${{ steps.gen_output.outputs.result }}
permissions:
issues: read
steps:
- name: Checkout travellings-link/travellings-bot repository
uses: actions/checkout@v4
with:
repository: 'travellings-link/travellings-bot'
path: './travellings-bot'
- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: latest
run_install: false
- name: Install Node.js
uses: actions/setup-node@v4
# - name: ls
# run: ls
# 如果不先安装这个,下面安装会报错
- name: Install simple-git-hooks
run: pnpm add simple-git-hooks
- name: Install package with pnpm
run: pnpm install --lockfile pnpm-lock.yaml --config.node-linker=isolated
- name: Read Issue Content
uses: actions/github-script@v4
with:
script: |
async function getWebsiteURL(context, github) {
const issue = context.issue;
const issueResponse = await github.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number
});
const issueBody = issueResponse.data.body;
const lines = issueBody.split('\n');
let websiteUrl = '';
// 新申请拿到网址
for (let i = 0; i < lines.length; i++) {
if (lines[i].trim() === '### 网站网址') {
websiteUrl = lines[i + 2].trim();
break;
}
}
// 申请更改的拿到网址
if (websiteUrl === '') {
for (let i = 0; i < lines.length; i++) {
if (lines[i].trim() === '### 新网址(不更改网址请留空)') {
websiteUrl = lines[i + 2].trim();
break;
}
}
}
// 申请更改类,但是不改网址的
if (websiteUrl === '_No response_') {
for (let i = 0; i < lines.length; i++) {
if (lines[i].trim() === '### 原网址') {
websiteUrl = lines[i + 2].trim();
break;
}
}
}
// 还是没拿到网址啥的就退出
if (websiteUrl === '_No response_' | websiteUrl === '' ) {
// core.setFailed('未能获取到有效的网址');
return;
}
return websiteUrl;
}
const websiteUrl = await getWebsiteURL(context, github);
const fs = require('fs');
if (websiteUrl === undefined){
console.log('未能获取到有效的网址');
fs.writeFileSync('./travellings-bot/url.txt', "");
return;
}
console.log('Website URL:', websiteUrl);
fs.writeFileSync('./travellings-bot/url.txt', websiteUrl);
# - name: ls
# run: ls
- name: Install Chrome
run: npx puppeteer browsers install chrome
- name: Run pnpm cli with websiteUrl
run: |
websiteUrl=$(head -n 1 url.txt)
if [ -z "$websiteUrl" ]; then
echo "Website URL is empty, skipping pnpm run cli."
exit 0
fi
pnpm run cli ${websiteUrl}
# - name: ls
# run: ls
- name: Comment on issue
uses: actions/github-script@v4
with:
script: |
const fs = require('fs');
if (!fs.existsSync('./travellings-bot/results.json')) {
console.log('results.json file does not exist, skipping comment.');
core.exportVariable('last_result', "null");
return;
}
const json_result = JSON.parse(fs.readFileSync('./travellings-bot/results.json', { encoding: 'utf8' }));
console.log(JSON.stringify(json_result, null, 2));
core.exportVariable('last_result', json_result);
- name: Generate output
id: gen_output
run: |
echo ${last_result}
echo "result=${last_result}" >> "$GITHUB_OUTPUT"
comment-auto-check-assistant-result:
runs-on: ubuntu-latest
needs: [auto-check-assistant]
steps:
- name: Comment on issue
uses: actions/github-script@v4
env:
RESULT: ${{ needs.auto-check-assistant.outputs.result }}
with:
script: |
async function getWebsiteURL(context, github) {
const issue = context.issue;
const issueResponse = await github.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number
});
const issueBody = issueResponse.data.body;
const lines = issueBody.split('\n');
let websiteUrl = '';
// 新申请拿到网址
for (let i = 0; i < lines.length; i++) {
if (lines[i].trim() === '### 网站网址') {
websiteUrl = lines[i + 2].trim();
break;
}
}
// 申请更改的拿到网址
if (websiteUrl === '') {
for (let i = 0; i < lines.length; i++) {
if (lines[i].trim() === '### 新网址(不更改网址请留空)') {
websiteUrl = lines[i + 2].trim();
break;
}
}
}
// 申请更改类,但是不改网址的
if (websiteUrl === '_No response_') {
for (let i = 0; i < lines.length; i++) {
if (lines[i].trim() === '### 原网址') {
websiteUrl = lines[i + 2].trim();
break;
}
}
}
// 还是没拿到网址啥的就退出
if (websiteUrl === '_No response_' | websiteUrl === '' ) {
// core.setFailed('未能获取到有效的网址');
return;
}
return websiteUrl;
}
const websiteUrl = await getWebsiteURL(context, github);
if (websiteUrl === undefined){
console.log('未能获取到有效的网址');
// 此时 process.env.RESULT 为 null
const issue = context.issue;
const label = context.payload.label;
github.issues.createComment({
issue_number: issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "站点信息自动检查失败❌\n未能获取到有效的网址"
});
return;
}
let json_result = JSON.parse(process.env.RESULT)["results"][websiteUrl];
// console.log(json_result);
function replaceNodeValue(json_result){
for (const key in json_result) {
if (typeof json_result[key] === 'object') {
replaceNodeValue(json_result[key]);
} else if (json_result[key] === "RUN") {
json_result[key] = '✅RUN';
} else if (key === "status") {
json_result[key] = '❌' + json_result[key];
}
}
}
replaceNodeValue(json_result);
let result = `站点信息自动检查完毕🎉
自动检查结果:
- HTTP 请求检查:${json_result["axiosCheck"]["status"]}${json_result["axiosCheck"]["status"] === '✅RUN' ? '' : '、失败原因:' + json_result["axiosCheck"]["failedReason"] }
- 浏览器模拟检查:${json_result["browserCheck"]["status"]}
<details><summary>原始返回值 点击查看详情</summary>
${JSON.stringify(json_result, null, 2)}
</details>`;
const issue = context.issue;
const label = context.payload.label;
github.issues.createComment({
issue_number: issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: result
});