-
Notifications
You must be signed in to change notification settings - Fork 424
123 lines (109 loc) · 4.41 KB
/
pr-reviewer-COS.yml
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
name: PR Reviewer
on: workflow_call
jobs:
review:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Print PR details
run: |
echo "The PR ID is ${{ github.event.pull_request.id }}"
echo "The PR number is ${{ github.event.pull_request.number }}"
echo "The PR title is ${{ github.event.pull_request.title }}"
echo "The PR branch is ${{ github.event.pull_request.head.ref }}"
- run: npm install cos-nodejs-sdk-v5
- name: Download build dist
uses: actions/download-artifact@v4
with:
name: build-dist
path: dist
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: build-examples
path: examples
- name: Upload to COS
uses: actions/github-script@v7
with:
script: |
const COS = require('cos-nodejs-sdk-v5');
const fs = require('fs');
const path = require('path');
const cos = new COS({
SecretId: '${{ secrets.COS_SECRETID }}',
SecretKey: '${{ secrets.COS_SECRETKEY }}',
});
const uploadDirectory = (directoryPath, keyPrefix) => {
const uploadPromises = [];
const files = fs.readdirSync(directoryPath);
files.forEach(file => {
const filePath = path.join(directoryPath, file);
const key = `${keyPrefix}/${file}`;
if (fs.lstatSync(filePath).isDirectory()) {
uploadPromises.push(uploadDirectory(filePath, key));
} else {
uploadPromises.push(uploadFile(filePath, key));
}
});
return Promise.all(uploadPromises);
};
const uploadFile = (filePath, key) => {
return new Promise((resolve, reject) => {
cos.uploadFile({
Bucket: 'cherrymd-1301618266',
Region: 'ap-singapore',
Key: key,
FilePath: filePath,
SliceSize: 1024 * 1024 * 5, /* 触发分块上传的阈值,超过5MB使用分块上传,非必须 */
ContentDisposition: 'inline',
CacheControl: 'no-cache',
Headers: {
'Cache-control': 'no-cache',
'Content-Disposition': 'inline',
},
}, function(err, data) {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
};
(async () => {
try {
await uploadDirectory('dist', 'pr${{ github.event.pull_request.number }}/dist');
await uploadDirectory('examples', 'pr${{ github.event.pull_request.number }}/examples');
console.log('Upload success');
} catch (err) {
console.error('Upload failed:', err);
}
})();
- name: Add Comment
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const prNumber = ${{ github.event.pull_request.number }};
const baseUrl = `https://cherrymd.com/pr${prNumber}/examples`;
const response = await github.request('POST /repos/{owner}/{repo}/issues/{issue_number}/comments', {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `
### 【预览链接】
- [full model](${baseUrl}/index.html)
- [basic](${baseUrl}/basic.html)
- [mobile](${baseUrl}/h5.html)
- [multiple instances](${baseUrl}/multiple.html)
- [editor without toolbar](${baseUrl}/notoolbar.html)
- [pure preview](${baseUrl}/preview_only.html)
- [XSS](${baseUrl}/xss.html)(Not allowed by default)
- [img wysiwyg](${baseUrl}/img.html)
- [table wysiwyg](${baseUrl}/table.html)
- [headers with auto num](${baseUrl}/head_num.html)
- [流式输入模式(AI chart场景)](${baseUrl}/ai_chat.html)
- [VIM 编辑模式](${baseUrl}/vim.html)
`
});