forked from Tencent/Hippy
-
Notifications
You must be signed in to change notification settings - Fork 0
143 lines (133 loc) · 5.13 KB
/
gh_action_approve_checks.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
name: '[gh] action approve checks'
on:
pull_request_target:
branches:
- master
- main
- v3.0-dev
- v3.0
types:
- labeled
jobs:
call_approval_checks_run:
if: github.event.label.name == 'action(approve-checks)' && github.repository == 'Tencent/Hippy'
uses: ./.github/workflows/reuse_approve_checks_run.yml
with:
pull_request_number: ${{ github.event.pull_request.number }}
pull_request_head_sha: ${{ github.event.pull_request.head.sha }}
approve_checks_action:
needs: call_approval_checks_run
runs-on: ubuntu-latest
steps:
- name: Token
uses: navikt/github-app-token-generator@v1
id: get-token
with:
private-key: ${{ secrets.ACTION_PRIVATE_KEY }}
app-id: ${{ secrets.ACTION_APP_ID }}
- name: Action
uses: actions/[email protected]
env:
COMMENT_MESSAGE: |
:lock: The current `approve-checks` action execution requires privilege escalation.
Please wait for approval of admin team member ...
@${{ github.event.sender.login }}
WECHAT_WORK_MESSAGE: |
[${{ github.event.sender.login }}](https://github.com/${{ github.event.sender.login }}) requested privilege escalation action on [#${{ github.event.pull_request.number }}](${{ github.event.pull_request.html_url }}) pull request.
> ${{ github.event.pull_request.title }}
> [${{ github.event.pull_request.html_url }}](${{ github.event.pull_request.html_url }})
PRIVILEGE_ESCALATION: ${{ needs.call_approval_checks_run.outputs.included_risk_files }}
with:
github-token: ${{ steps.get-token.outputs.token }}
script: |
const { pull_request } = context.payload;
const { issues } = github.rest;
const p = [];
if (process.env.PRIVILEGE_ESCALATION == 'true') {
p.push(issues.createComment({
issue_number: pull_request.number,
body: process.env.COMMENT_MESSAGE,
...context.repo
}));
p.push(github.request("POST ${{ secrets.WECHAT_WORK_BOT_WEBHOOK }}", {
headers: {
"content-type": "application/json"
},
data: {
chatid: "${{ secrets.WECHAT_WORK_ADMIN_CHAT_ID }}",
msgtype: "markdown",
markdown: {
content: process.env.WECHAT_WORK_MESSAGE,
attachments: [{
callback_id: "approve",
actions: [{
name: "approve_btn",
text: "Mark as Approved",
type: "button",
value: "Mark as Approved",
replace_text: "Already approved",
border_color: "2c974b",
text_color: "2c974b"
}, {
name: "reject_btn",
text: "Mark as Rejected",
type: "button",
value: "Mark as Rejected",
replace_text: "Already Rejected",
border_color: "cf222e",
text_color: "cf222e"
}, {
name: "ignored_btn",
text: "Mark as Ignored",
type: "button",
value: "Mark as Ignored",
replace_text: "Already Ignored",
border_color: "6e7781",
text_color: "6e7781"
}]
}]
}
}
}));
} else {
p.push(issues.removeLabel({
issue_number: pull_request.number,
name: 'action(approve-checks)',
...context.repo,
}).catch(e => {
console.error('issues.removeLabel', e);
}));
}
await Promise.all(p);
call_approval_checks_run_privileged:
needs: [ call_approval_checks_run, approve_checks_action ]
if: needs.call_approval_checks_run.outputs.included_risk_files == 'true'
uses: ./.github/workflows/reuse_approve_checks_run.yml
with:
pull_request_number: ${{ github.event.pull_request.number }}
pull_request_head_sha: ${{ github.event.pull_request.head.sha }}
requied_privilege_escalation: true
approve_checks_action_privileged:
needs: call_approval_checks_run_privileged
runs-on: ubuntu-latest
steps:
- name: Token
uses: navikt/github-app-token-generator@v1
id: get-token
with:
private-key: ${{ secrets.ACTION_PRIVATE_KEY }}
app-id: ${{ secrets.ACTION_APP_ID }}
- name: Action
uses: actions/[email protected]
with:
github-token: ${{ steps.get-token.outputs.token }}
script: |
const { pull_request } = context.payload;
const { issues } = github.rest;
await issues.removeLabel({
issue_number: pull_request.number,
name: 'action(approve-checks)',
...context.repo,
}).catch(e => {
console.error('issues.removeLabel', e);
});