-
Notifications
You must be signed in to change notification settings - Fork 39
141 lines (127 loc) · 5.52 KB
/
entry_workflow.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
name: Trigger tests by `/run-ci` comment
on:
issue_comment:
types: [created]
pull_request:
types: [opened, synchronize]
jobs:
run-ci:
name: run-ci-from-pr-comment
# PullRequestEvent: https://docs.github.com/en/rest/overview/github-event-types?apiVersion=2022-11-28#pullrequestevent
if: github.event.issue.pull_request && startsWith(github.event.comment.body, '/run-ci')
runs-on: ubuntu-22.04
# When the permissions key is used, all unspecified permissions are set to no access, with the exception of the metadata scope, which always gets read access.
# See https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token
permissions:
contents: read
actions: write
pull-requests: write
steps:
- name: Query author repository permissions
uses: octokit/request-action@v2.x
id: user_permission
with:
route: GET /repos/${{ github.repository }}/collaborators/${{ github.event.sender.login }}/permission
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# The `actions:write` permission is required in this step.
- name: Dispatch CIs if the user does have correct permission
if: contains('admin write', fromJson(steps.user_permission.outputs.data).permission)
id: dispatch
uses: actions/github-script@v7
with:
script: |
const dispatch = {
comment_body: `${{ github.event.comment.body }}`,
repo: context.repo,
issue: context.issue,
};
const jsonDispatch = JSON.stringify(dispatch)
.replace(/\\b/g, "\\\\b")
.replace(/\\f/g, "\\\\f")
.replace(/\\n/g, "\\\\n")
.replace(/\\r/g, "\\\\r")
.replace(/\\t/g, "\\\\t");
// get pr comments body,not issue comments body
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});
let check_list = `
\### CI test list:
`;
const dispatchWorkflow = async (workflowId) => {
const resp = await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: workflowId,
ref: `main`,
inputs: {
dispatch: jsonDispatch,
}
});
core.info(`${JSON.stringify(resp, null, 2)}`);
check_list = `${check_list}\n - ${workflowId}`;
};
// check if OpenZeppelin tests is required
const OCT_match = pr.data.body.includes("[x] OpenZeppelin tests");
if (OCT_match) {
const workflowIds = [
"openzeppelin_test_1_5_and_12_15.yml",
"openzeppelin_test_6_10.yml",
"openzeppelin_test_11.yml",
"openzeppelin_test_16_19.yml",
];
await Promise.all(workflowIds.map(dispatchWorkflow));
}
// check v3 Core Tests exist or not
const v3_match = pr.data.body.includes("[x] v3 Core Tests");
if (v3_match) {
await dispatchWorkflow("v3_core_test.yml");
}
// check Unit Tests exist or not
const web3_match = pr.data.body.includes("[x] Web3 Compatible Tests");
if (web3_match) {
await dispatchWorkflow("web3_compatible.yml");
};
return check_list
- name: Escape check list
id: escape_multiple_lines_test_inputs
run: |
echo ${{ steps.dispatch.outputs.result}}
inputs=${{ steps.dispatch.outputs.result}}
echo "result=$inputs" >> $GITHUB_OUTPUT
# https://docs.github.com/en/rest/issues/comments?apiVersion=2022-11-28#create-an-issue-comment
# The `pull-requests: write` permission is required in the step.
- name: Post a coment about component information to PR
if: contains('admin write', fromJson(steps.user_permission.outputs.data).permission)
id: post_workflow_run_comment
uses: actions/github-script@v7
with:
script: |
console.log(`${{ steps.escape_multiple_lines_test_inputs.outputs.result }}`);
const dispatch = {
comment_body: `${{ github.event.comment.body }}`,
repo: context.repo,
issue: context.issue,
};
const pr = (
await github.rest.pulls.get({
owner: dispatch.repo.owner,
repo: dispatch.repo.repo,
pull_number: dispatch.issue.number,
})
).data.head;
let integrationTestInfo = `
\### CI tests run on commit:
- commit id: https://github.com/${{ github.repository }}/commit/${pr.sha}`;
integrationTestInfo = `${integrationTestInfo}`;
integrationTestInfo = `${integrationTestInfo}\n ${{ steps.escape_multiple_lines_test_inputs.outputs.result }}\n ### Please check ci test results later.`;
console.log(integrationTestInfo);
const comment = await github.rest.issues.createComment({
issue_number: dispatch.issue.number,
owner: dispatch.repo.owner,
repo: dispatch.repo.repo,
body: integrationTestInfo,
});