Skip to content

Commit 0106d7e

Browse files
committed
CI: improve fmt and validate check
1 parent 1723754 commit 0106d7e

File tree

3 files changed

+25
-55
lines changed

3 files changed

+25
-55
lines changed

.github/workflows/e2e.yml

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,22 @@ jobs:
1414
terraform-fmt:
1515
runs-on: ubuntu-latest
1616
steps:
17-
- name: checkout
18-
uses: actions/checkout@v3
19-
- name: terraform-fmt
20-
run: |
21-
if [ ! -f /usr/local/bin/terraform ]; then
22-
wget -q https://releases.hashicorp.com/terraform/1.6.0/terraform_1.6.0_linux_amd64.zip
23-
unzip terraform_1.6.0_linux_amd64.zip -d /usr/local/bin/
24-
fi
25-
error=false
26-
echo "===> Terraform fmt -diff checking in quickstarts"
27-
(terraform -chdir=quickstarts fmt -check -recursive -list=false) || error=true
28-
terraform -chdir=quickstarts fmt -diff -recursive
29-
if ${error}; then
30-
echo -e "\033[31m[ERROR]\033[0m: Some quickstarts codes has not been formatted, and please running terraform fmt --recursive command before pushing."
31-
exit 1
32-
fi
17+
- uses: actions/checkout@v4
18+
19+
- uses: hashicorp/setup-terraform@v3
20+
21+
- name: Terraform fmt
22+
id: fmt
23+
run: terraform -chdir=quickstarts fmt -check -recursive
24+
3325

3426
terraform-validate:
3527
runs-on: ubuntu-latest
3628
steps:
37-
- name: checkout
38-
uses: actions/checkout@v3
29+
- uses: actions/checkout@v4
30+
31+
- uses: hashicorp/setup-terraform@v3
32+
3933
- name: Get changed files
4034
id: changed-files
4135
uses: tj-actions/changed-files@v34
@@ -46,19 +40,24 @@ jobs:
4640
dir_names_max_depth: 3
4741
- name: pr-check
4842
run: |
49-
if [ ! -f /usr/local/bin/terraform ]; then
50-
wget -q https://releases.hashicorp.com/terraform/1.6.0/terraform_1.6.0_linux_amd64.zip
51-
unzip terraform_1.6.0_linux_amd64.zip -d /usr/local/bin/
52-
fi
5343
CHANGED_FOLDERS="${{ steps.changed-files.outputs.all_changed_files }}"
54-
if [ -z "${{ github.event.number }}" ]; then
55-
CHANGED_FOLDERS=$(find ./quickstarts -maxdepth 2 -mindepth 2 -type d | tr '\n' ',')
56-
fi
5744
if [ -z "$CHANGED_FOLDERS" ]; then
5845
echo "No changed quickstarts found"
5946
exit 0
6047
fi
61-
bash scripts/terraform-validate.sh ${CHANGED_FOLDERS}
48+
49+
error=false
50+
for f in ${CHANGED_FOLDERS//,/ }
51+
do
52+
f=$(echo $f | xargs echo -n)
53+
echo "===> Terraform validating in" $f
54+
terraform -chdir=$f init -upgrade
55+
terraform -chdir=$f validate
56+
if [[ $? -ne 0 ]]; then
57+
echo -e "\033[31m[ERROR]\033[0m: Some quickstarts codes contain errors, and please running terraform validate command before pushing."
58+
exit 1
59+
fi
60+
done
6261
6362
6463
e2e-check:

scripts/terraform-install.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.

scripts/terraform-validate.sh

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)