Skip to content

Commit d28cccf

Browse files
committed
ci: improves e2e test
1 parent 8a46bca commit d28cccf

File tree

2 files changed

+36
-28
lines changed

2 files changed

+36
-28
lines changed

.github/workflows/e2e.yml

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ on:
88
- 'quickstarts/**'
99

1010
jobs:
11-
e2e-check:
11+
e2e-check
12+
if: github.event.review.state == 'approved' || github.event.review.body == 'approved'
1213
runs-on: terraform-alicloud-landing
1314
environment:
1415
name: acctests
@@ -27,30 +28,5 @@ jobs:
2728
- name: test pr
2829
run: |
2930
bash scripts/terraform-install.sh
30-
echo "cat ~/.aliyun/config.json"
31-
cat ~/.aliyun/config.json
32-
echo "aaa: $ALICLOUD_ACCESS"
33-
echo $ALICLOUD_ACCESS
34-
export ALICLOUD_PROFILE=${{ secrets.PROFILENAME }}
35-
folders="${{ steps.changed-files.outputs.all_changed_files }}"
36-
for f in ${folders//,/ }
37-
do
38-
f=$(echo $f | xargs echo -n)
39-
echo "===> Terraform testing in" $f
40-
terraform -chdir=$f init -upgrade
41-
cp scripts/plan.tftest.hcl $f/
42-
terraform -chdir=$f test test -verbose
43-
if [[ $? -ne 0 ]]; then
44-
echo -e "\033[31m[ERROR]\033[0m: running terraform test for plan failed."
45-
#exit 1
46-
else
47-
rm -rf scripts/plan.tftest.hcl
48-
cp scripts/apply.tftest.hcl $f/
49-
terraform -chdir=$f test test
50-
if [[ $? -ne 0 ]]; then
51-
echo -e "\033[31m[ERROR]\033[0m: running terraform test for apply failed."
52-
#exit 1
53-
fi
54-
rm -rf scripts/apply.tftest.hcl
55-
fi
56-
done
31+
CHANGED_FOLDERS="${{ steps.changed-files.outputs.all_changed_files }}"
32+
bash scripts/terraform-validate.sh ${CHANGED_FOLDERS}

scripts/terraform-test.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
error=false
3+
4+
success=true
5+
folders=$1
6+
for f in ${folders//,/ }
7+
do
8+
f=$(echo $f | xargs echo -n)
9+
echo "===> Terraform testing in" $f
10+
terraform -chdir=$f init -upgrade
11+
source ~/.terraform_profile
12+
cp scripts/plan.tftest.hcl $f/
13+
terraform -chdir=$f test test -verbose
14+
if [[ $? -ne 0 ]]; then
15+
success=false
16+
echo -e "\033[31m[ERROR]\033[0m: running terraform test for plan failed."
17+
else
18+
rm -rf scripts/plan.tftest.hcl
19+
cp scripts/apply.tftest.hcl $f/
20+
terraform -chdir=$f test test
21+
if [[ $? -ne 0 ]]; then
22+
success=false
23+
echo -e "\033[31m[ERROR]\033[0m: running terraform test for apply failed."
24+
fi
25+
rm -rf scripts/apply.tftest.hcl
26+
fi
27+
done
28+
29+
if [[ $success ]]; then
30+
exit 1
31+
fi
32+
exit 0

0 commit comments

Comments
 (0)