Terrafrom Integration Checks #4791
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/[email protected] | |
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/[email protected] | |
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} |