Skip to content

Commit 93985fd

Browse files
Merge pull request #11 from infraspecdev/precommit-config
add pre-commit workflow
2 parents 1101308 + a33d81f commit 93985fd

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

.github/workflows/pre-commit.yaml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Pre-Commit
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
env:
9+
TERRAFORM_DOCS_VERSION: v0.16.0
10+
TFLINT_VERSION: v0.44.1
11+
12+
jobs:
13+
collectInputs:
14+
name: Collect workflow inputs
15+
runs-on: ubuntu-latest
16+
outputs:
17+
directories: ${{ steps.dirs.outputs.directories }}
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v3
21+
22+
- name: Get root directories
23+
id: dirs
24+
uses: clowdhaus/terraform-composite-actions/directories@v1.8.3
25+
26+
preCommitMinVersions:
27+
name: Min TF pre-commit
28+
needs: collectInputs
29+
runs-on: ubuntu-latest
30+
strategy:
31+
matrix:
32+
directory: ${{ fromJson(needs.collectInputs.outputs.directories) }}
33+
steps:
34+
- name: Checkout
35+
uses: actions/checkout@v3
36+
37+
- name: Terraform min/max versions
38+
id: minMax
39+
uses: clowdhaus/terraform-min-max@v1.2.4
40+
with:
41+
directory: ${{ matrix.directory }}
42+
43+
- name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
44+
# Run only validate pre-commit check on min version supported
45+
if: ${{ matrix.directory != '.' }}
46+
uses: clowdhaus/terraform-composite-actions/pre-commit@v1.8.3
47+
with:
48+
terraform-version: ${{ steps.minMax.outputs.minVersion }}
49+
tflint-version: ${{ env.TFLINT_VERSION }}
50+
args: 'terraform_validate --color=always --show-diff-on-failure --files ${{ matrix.directory }}/*'
51+
52+
- name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
53+
# Run only validate pre-commit check on min version supported
54+
if: ${{ matrix.directory == '.' }}
55+
uses: clowdhaus/terraform-composite-actions/pre-commit@v1.8.3
56+
with:
57+
terraform-version: ${{ steps.minMax.outputs.minVersion }}
58+
tflint-version: ${{ env.TFLINT_VERSION }}
59+
args: 'terraform_validate --color=always --show-diff-on-failure --files $(ls *.tf)'
60+
61+
preCommitMaxVersion:
62+
name: Max TF pre-commit
63+
runs-on: ubuntu-latest
64+
needs: collectInputs
65+
steps:
66+
- name: Checkout
67+
uses: actions/checkout@v3
68+
with:
69+
ref: ${{ github.event.pull_request.head.ref }}
70+
repository: ${{github.event.pull_request.head.repo.full_name}}
71+
72+
- name: Terraform min/max versions
73+
id: minMax
74+
uses: clowdhaus/terraform-min-max@v1.2.4
75+
76+
- name: Pre-commit Terraform ${{ steps.minMax.outputs.maxVersion }}
77+
uses: clowdhaus/terraform-composite-actions/pre-commit@v1.8.3
78+
with:
79+
terraform-version: ${{ steps.minMax.outputs.maxVersion }}
80+
tflint-version: ${{ env.TFLINT_VERSION }}
81+
terraform-docs-version: ${{ env.TERRAFORM_DOCS_VERSION }}
82+
install-hcledit: true

0 commit comments

Comments
 (0)