-
Notifications
You must be signed in to change notification settings - Fork 553
153 lines (148 loc) · 6.25 KB
/
acctest-terraform-integration.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
name: Terrafrom Integration Checks
on:
pull_request_review:
types: [edited, submitted]
paths:
- alicloud/*.go
jobs:
IntegrationTest:
if: github.event.review.state == 'approved' || github.event.review.body == 'approved'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.20.x'
- uses: ReeganExE/github-action-job-id@v1.0
with:
expose-name: true
- uses: jwalton/gh-find-current-pr@v1
id: findPr
with:
# Can be "open", "closed", or "all". Defaults to "open".
state: open
- uses: actions/checkout@v3
with:
# Checkout as many commits as needed for the diff
fetch-depth: 2
- name: Integration Test Check
run: |
# diffFiles=$(git diff --name-only HEAD^ HEAD | grep "^alicloud/" | grep ".go$" | grep -v "_test.go$")
diffFiles=$(git diff --name-only HEAD^ HEAD)
noNeedRun=true
for fileName in ${diffFiles[@]};
do
if [[ ${fileName} == "alicloud/resource_alicloud"* || ${fileName} == "alicloud/data_source_alicloud"* ]];then
if [[ ${fileName} != *?_test.go ]]; then
fileName=(${fileName//\.go/_test\.go })
# echo -e "\033[33m[SKIPPED]\033[0m skipping the file $fileName, continue..."
# continue
fi
echo -e "\n\033[37mchecking diff file $fileName ... \033[0m"
noNeedRun=false
# fileName=(${fileName//\.go/_test\.go })
if [[ $(grep -c "func TestAcc.*" ${fileName}) -lt 1 ]]; then
echo -e "\033[33m[WARNING]\033[0m missing the acceptance test cases in the file $fileName, continue..."
continue
fi
checkFuncs=$(grep "func TestAcc.*" ${fileName})
echo -e "found the test funcs:\n${checkFuncs}\n"
funcs=(${checkFuncs//"(t *testing.T) {"/ })
for func in ${funcs[@]};
do
if [[ ${func} != "TestAcc"* ]]; then
continue
fi
DiffFuncNames=$DiffFuncNames";"${func}
done
fi
done
if [[ "${noNeedRun}" = "false" && ${DiffFuncNames} == "" ]]; then
echo -e "\n\033[33m[WARNING]\033[0m missing integration test cases, please add them. \033[0m"
exit 1
fi
if [[ "${noNeedRun}" = "true" ]]; then
echo -e "\n\033[33m[WARNING]\033[0m the pr is no need to run integration test. \033[0m"
exit 0
fi
IN=$GH_JOB_IntegrationTest_HTML_URL
arrIN=(${IN//actions/ })
ossObjectPath="github-actions"${arrIN[1]}
go run scripts/integration_check.go ${ossObjectPath}
DocsExampleTest:
if: github.event.review.state == 'approved' || github.event.review.body == 'approved'
runs-on: ubuntu-latest
needs: IntegrationTest
steps:
- uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.20.x'
- uses: ReeganExE/github-action-job-id@v1.0
with:
expose-name: true
- uses: jwalton/gh-find-current-pr@v1
id: findPr
with:
# Can be "open", "closed", or "all". Defaults to "open".
state: open
- uses: actions/checkout@v3
with:
# Checkout as many commits as needed for the diff
fetch-depth: 2
- name: Docs Example Test Check
run: |
diffFiles=$(git diff --name-only HEAD^ HEAD)
noNeedRun=true
exampleCount=0
if [[ ${#diffFiles[@]} -eq 0 ]]; then
echo -e "\033[33m[WARNING]\033[0m the pr ${prNum} does not change provider code and there is no need to check."
exit 0
fi
for fileName in ${diffFiles[@]}; do
if [[ ${fileName} == *?_test.go ]]; then
echo -e "\033[33m[SKIPPED]\033[0m skipping the file $fileName, continue..."
continue
fi
if [[ ${fileName} == "alicloud/resource_alicloud"* || ${fileName} == "alicloud/data_source_alicloud"* || ${fileName} == "website/docs/r/"* || ${fileName} == "website/docs/d/"* ]]; then
echo ${fileName}
docsPathKey="website/docs/r"
if [[ $fileName =~ "data_source_" || $fileName =~ "website/docs/d/" ]]; then
docsPathKey="website/docs/d"
fi
if [[ ${fileName} == *".go" ]]; then
fileName=(${fileName/_test./.})
fileName=(${fileName/.go/.html.markdown})
fileName=(${fileName#*resource_alicloud_})
fileName=(${fileName#*data_source_alicloud_})
fi
if [[ ${fileName} == *?.html.markdown ]]; then
fileName=(${fileName#*r/})
fileName=(${fileName#*d/})
fi
resourceName=${fileName%%.html.markdown}
docsDir="${docsPathKey}/${resourceName}.html.markdown"
noNeedRun=false
if [[ $(grep -c '```terraform' "${docsDir}") -lt 1 ]]; then
echo -e "\033[33m[WARNING]\033[0m missing docs examples in the ${docsDir}, please adding them. \033[0m"
exit 1
fi
diffExampleCount=$(grep -c '```terraform' "${docsDir}")
echo -e "found the example count:${diffExampleCount}"
exampleCount=$(( $exampleCount + $diffExampleCount ))
fi
done
if [[ "${noNeedRun}" = "false" && ${exampleCount} == "0" ]]; then
echo -e "\033[31mthe pr ${prNum} missing docs example, please adding them. \033[0m"
exit 1
fi
if [[ "${noNeedRun}" = "true" ]]; then
echo -e "\n\033[33m[WARNING]\033[0m the pr is no need to run example.\033[0m"
exit 0
fi
IN=$GH_JOB_DocsExampleTest_HTML_URL
arrIN=(${IN//actions/ })
ossObjectPath="github-actions"${arrIN[1]}
go run scripts/docs_example_check.go ${ossObjectPath}