|
5 | 5 | - master |
6 | 6 | - main |
7 | 7 | types: [ 'opened', 'synchronize' ] |
8 | | - paths: |
9 | | - - '.github/**' |
10 | | - - '.github/workflows/**' |
11 | | - - '**/*.tf' |
12 | 8 |
|
13 | 9 | jobs: |
| 10 | + commitlint: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - uses: ahmadnassri/action-commit-lint@v2 |
| 14 | + |
| 15 | + changes-files: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + outputs: |
| 18 | + changed_files_list: ${{ steps.changed-files.outputs.all_changed_files }} |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v4 |
| 21 | + - name: Get changed files |
| 22 | + id: changed-files |
| 23 | + uses: tj-actions/changed-files@v34 |
| 24 | + with: |
| 25 | + separator: "," |
| 26 | + |
14 | 27 | terraform-fmt: |
15 | 28 | runs-on: ubuntu-latest |
| 29 | + needs: changes-files |
| 30 | + if: contains(needs.changes-files.outputs.changed_files_list, '.tf') |
16 | 31 | steps: |
17 | | - - name: checkout |
18 | | - uses: actions/checkout@v3 |
19 | | - - name: fmt-check |
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" |
27 | | - terraform fmt -diff -recursive -check |
28 | | - if [[ $? -ne 0 ]]; then |
29 | | - echo -e "\033[31m[ERROR]\033[0m: Some codes has not been formatted, and please running terraform fmt --recursive command before pushing." |
30 | | - exit 1 |
31 | | - fi |
| 32 | + - uses: actions/checkout@v4 |
| 33 | + - uses: hashicorp/setup-terraform@v3 |
| 34 | + - name: Terraform fmt |
| 35 | + id: fmt |
| 36 | + run: terraform fmt -check -recursive |
32 | 37 |
|
33 | 38 | terraform-validate: |
34 | 39 | runs-on: ubuntu-latest |
| 40 | + needs: changes-files |
| 41 | + if: contains(needs.changes-files.outputs.changed_files_list, '.tf') |
35 | 42 | steps: |
36 | 43 | - name: checkout |
37 | 44 | uses: actions/checkout@v3 |
| 45 | + - uses: hashicorp/setup-terraform@v3 |
38 | 46 | - name: validate-check |
39 | 47 | run: | |
40 | | - if [ ! -f /usr/local/bin/terraform ]; then |
41 | | - wget -q https://releases.hashicorp.com/terraform/1.6.0/terraform_1.6.0_linux_amd64.zip |
42 | | - unzip terraform_1.6.0_linux_amd64.zip -d /usr/local/bin/ |
43 | | - fi |
44 | 48 | exp="examples" |
45 | 49 | output_file="combined_output.txt" |
46 | 50 | if [[ -d "$exp" ]]; then |
|
63 | 67 | |
64 | 68 | tflint: |
65 | 69 | runs-on: ubuntu-latest |
| 70 | + needs: changes-files |
| 71 | + if: contains(needs.changes-files.outputs.changed_files_list, '.tf') |
66 | 72 | steps: |
67 | 73 | - name: checkout |
68 | 74 | uses: actions/checkout@v3 |
@@ -105,7 +111,6 @@ jobs: |
105 | 111 | fi |
106 | 112 | |
107 | 113 | e2e-check: |
108 | | - # if: github.event.review.state == 'approved' || github.event.review.body == 'approved' |
109 | 114 | needs: [terraform-fmt, terraform-validate, tflint] |
110 | 115 | runs-on: ubuntu-latest |
111 | 116 | name: 'e2e check' |
|
0 commit comments