-
Notifications
You must be signed in to change notification settings - Fork 560
155 lines (150 loc) · 5.92 KB
/
pull_requests.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
144
145
146
147
148
149
150
151
152
153
154
155
name: Pull Request Checks
on:
pull_request:
branches:
- master
jobs:
title:
runs-on: ubuntu-latest
name: Pull Request Title
steps:
- uses: jitterbit/get-changed-files@v1
id: files
with:
format: 'json'
- name: Checking the title info
run: |
exitCode=0
prTitle="${{ github.event.pull_request.title }}"
echo -e "PR Title: \033[1m${prTitle}\033[0m"
if [[ ${prTitle} == *"…" ]]; then
echo -e "\nERROR: The PR title should not omit important infos about added or modified files. \033[1mxxx... is not recommended.\033[0m"
exitCode=1
fi
docsOnly=true
testcaseOnly=true
docsChanged=false
testcaseChanged=false
readarray -t added_files <<<"$(jq -r '.[]' <<<'${{ steps.files.outputs.added }}')"
for added_file in ${added_files[@]}; do
if [[ ${added_file} == *?_test.go ]]; then
testcaseChanged=true
continue
fi
if [[ ${added_file} == "website/docs"* ]]; then
testcaseOnly=false
docsChanged=true
continue
fi
if [[ ${added_file} == "alicloud/resource_alicloud"* ]]; then
docsOnly=false
testcaseOnly=false
prefix="alicloud/resource_"
suffix=".go"
resourceName=${added_file}
resourceName=${resourceName#"$prefix"}
resourceName=${resourceName%"$suffix"}
titleStr="New Resource: ${resourceName}"
if [[ ${prTitle} != *"${titleStr}"* ]]; then
echo -e "\nERROR: The PR title should contains new resource info \033[1m${titleStr}\033[0m"
exitCode=1
fi
continue
fi
if [[ ${added_file} == "alicloud/data_source_alicloud"* ]]; then
docsOnly=false
testcaseOnly=false
prefix="alicloud/data_source_"
suffix=".go"
resourceName=${added_file}
resourceName=${resourceName#"$prefix"}
resourceName=${resourceName%"$suffix"}
titleStr="New Data Source: ${resourceName}"
if [[ ${prTitle} != *"${titleStr}"* ]]; then
echo -e "\nERROR: The PR title should contains new datasource info \033[1m${titleStr}\033[0m"
exitCode=1
fi
continue
fi
done
readarray -t modified_files <<<"$(jq -r '.[]' <<<'${{ steps.files.outputs.modified }}')"
for modified_file in ${modified_files[@]}; do
if [[ ${modified_file} == *?_test.go ]]; then
testcaseChanged=true
continue
fi
if [[ ${modified_file} == "website/docs"* ]]; then
testcaseOnly=false
docsChanged=true
continue
fi
if [[ ${modified_file} == "alicloud/resource_alicloud"* ]]; then
docsOnly=false
testcaseOnly=false
prefix="alicloud/resource_"
suffix=".go"
resourceName=${modified_file}
resourceName=${resourceName#"$prefix"}
resourceName=${resourceName%"$suffix"}
titleStr="resource/${resourceName}: "
if [[ ${prTitle} != *"${titleStr}"* ]]; then
echo -e "\nERROR: The PR title should contains modified info like \033[1m${titleStr}xxx\033[0m"
exitCode=1
fi
fi
if [[ ${modified_file} == "alicloud/data_source_alicloud"* ]]; then
docsOnly=false
testcaseOnly=false
prefix="alicloud/data_source_"
suffix=".go"
resourceName=${modified_file}
resourceName=${resourceName#"$prefix"}
resourceName=${resourceName%"$suffix"}
titleStr="data-source/${resourceName}: "
if [[ ${prTitle} != *"${titleStr}"* ]]; then
echo -e "\nERROR: The PR title should contains modified info like \033[1m${titleStr}xxx\033[0m"
exitCode=1
fi
fi
done
if [[ ${docsChanged} == true && ${docsOnly} == true ]]; then
titleStr="docs: "
if [[ ${prTitle} != "${titleStr}"* ]]; then
echo -e "\nERROR: The PR title should contains docs modified info like \033[1m${titleStr}xxx\033[0m"
exitCode=1
fi
elif [[ ${testcaseChanged} == true && ${testcaseOnly} == true ]]; then
titleStr="testcase: "
if [[ ${prTitle} != *"${titleStr}"* ]]; then
echo -e "\nERROR: The PR title should contains testcase modified info like \033[1m${titleStr}xxx\033[0m"
exitCode=1
fi
fi
exit ${exitCode}
commits:
runs-on: ubuntu-latest
name: Pull Request Max Commits
steps:
- name: Checking the max commits number
run: |
commitNum=${{ github.event.pull_request.commits }}
if [[ ${commitNum} -gt 1 ]]; then
echo -e "\nERROR: The PR has ${commitNum} commits, and please rebase it to 1.\n"
exit 1
fi
labeler:
runs-on: ubuntu-latest
name: Label the PR size
steps:
- uses: codelytv/pr-size-labeler@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
xs_max_size: '30'
s_max_size: '60'
m_max_size: '150'
l_max_size: '1500'
fail_if_xl: 'false'
message_if_xl: >
'This PR exceeds the recommended size of 1500 lines.
Please make sure you are NOT addressing multiple issues with one PR.
Note this PR might be rejected due to its size.’