-
Notifications
You must be signed in to change notification settings - Fork 414
78 lines (67 loc) · 2.27 KB
/
pr-merge.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
name: PR Closed Or Merge
on:
pull_request_target:
types:
- closed
paths: # 这里是用来指定哪个文件更改,才会触发的
- 'src/**'
- 'package.json'
- 'types/**'
- 'examples/**'
jobs:
remove_assets:
# 不需要在fork仓库的pr中运行
if: github.repository == 'Tencent/cherry-markdown'
runs-on: ubuntu-latest
steps:
# 检出仓库代码
- name: Checkout repository
uses: actions/checkout@v2
# 安装 cos-nodejs-sdk-v5
- name: Install cos-nodejs-sdk-v5
run: npm install cos-nodejs-sdk-v5
# 删除对应的资源
- name: Delete Resources On COS
uses: actions/github-script@v7
with:
script: |
const COS = require('cos-nodejs-sdk-v5');
const cos = new COS({
SecretId: process.env.COS_SECRETID,
SecretKey: process.env.COS_SECRETKEY,
});
const bucket = 'cherrymd-1301618266';
const region = 'ap-singapore';
const prNumber = '${{ github.event.pull_request.number }}';
const prefix = `pr${prNumber}/`;
// List objects in the bucket with the specified prefix
cos.getBucket({
Bucket: bucket,
Region: region,
Prefix: prefix,
}, (err, data) => {
if (err) {
console.error('Error listing objects:', err);
return;
}
const objectsToDelete = data.Contents.map(item => ({ Key: item.Key }));
if (objectsToDelete.length === 0) {
console.log('No objects to delete.');
return;
}
// Delete the listed objects
cos.deleteMultipleObject({
Bucket: bucket,
Region: region,
Objects: objectsToDelete,
}, (err, data) => {
if (err) {
console.error('Error deleting objects:', err);
} else {
console.log('Successfully deleted objects:', data);
}
});
});
env:
COS_SECRETID: ${{ secrets.COS_SECRETID }}
COS_SECRETKEY: ${{ secrets.COS_SECRETKEY }}