@@ -2,98 +2,77 @@ name: Pre-Commit
2
2
3
3
on :
4
4
pull_request :
5
- push :
6
5
branches :
6
+ - main
7
7
- master
8
8
9
+ env :
10
+ TERRAFORM_DOCS_VERSION : v0.16.0
11
+
9
12
jobs :
10
- # Min Terraform version(s)
11
- getDirectories :
12
- name : Get root directories
13
+ collectInputs :
14
+ name : Collect workflow inputs
13
15
runs-on : ubuntu-latest
16
+ outputs :
17
+ directories : ${{ steps.dirs.outputs.directories }}
14
18
steps :
15
19
- name : Checkout
16
20
uses : actions/checkout@v2
17
- - name : Install Python
18
- uses : actions/setup-python@v2
19
- - name : Build matrix
20
- id : matrix
21
- run : |
22
- DIRS=$(python -c "import json; import glob; print(json.dumps([x.replace('/versions.tf', '') for x in glob.glob('./**/versions.tf', recursive=True)]))")
23
- echo "::set-output name=directories::$DIRS"
24
- outputs :
25
- directories : ${{ steps.matrix.outputs.directories }}
21
+
22
+ - name : Get root directories
23
+ id : dirs
24
+ uses :
clowdhaus/terraform-composite-actions/[email protected]
26
25
27
26
preCommitMinVersions :
28
- name : Min TF validate
29
- needs : getDirectories
27
+ name : Min TF pre-commit
28
+ needs : collectInputs
30
29
runs-on : ubuntu-latest
31
30
strategy :
32
31
matrix :
33
- directory : ${{ fromJson(needs.getDirectories .outputs.directories) }}
32
+ directory : ${{ fromJson(needs.collectInputs .outputs.directories) }}
34
33
steps :
35
34
- name : Checkout
36
35
uses : actions/checkout@v2
37
- - name : Install Python
38
- uses : actions/setup-python@v2
36
+
39
37
- name : Terraform min/max versions
40
38
id : minMax
41
- uses :
clowdhaus/[email protected] .2
39
+ uses :
clowdhaus/[email protected] .3
42
40
with :
43
41
directory : ${{ matrix.directory }}
44
- - name : Install Terraform v${{ steps.minMax.outputs.minVersion }}
45
- uses : hashicorp/setup-terraform@v1
46
- with :
47
- terraform_version : ${{ steps.minMax.outputs.minVersion }}
48
- - name : Install pre-commit dependencies
49
- run : pip install pre-commit
50
- - name : Execute pre-commit
42
+
43
+ - name : Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
51
44
# Run only validate pre-commit check on min version supported
52
45
if : ${{ matrix.directory != '.' }}
53
- run : pre-commit run terraform_validate --color=always --show-diff-on-failure --files ${{ matrix.directory }}/*
54
- - name : Execute pre-commit
46
+ uses :
clowdhaus/terraform-composite-actions/[email protected]
47
+ with :
48
+ terraform-version : ${{ steps.minMax.outputs.minVersion }}
49
+ args : ' terraform_validate --color=always --show-diff-on-failure --files ${{ matrix.directory }}/*'
50
+
51
+ - name : Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
55
52
# Run only validate pre-commit check on min version supported
56
53
if : ${{ matrix.directory == '.' }}
57
- run : pre-commit run terraform_validate --color=always --show-diff-on-failure --files $(ls *.tf)
54
+ uses :
clowdhaus/terraform-composite-actions/[email protected]
55
+ with :
56
+ terraform-version : ${{ steps.minMax.outputs.minVersion }}
57
+ args : ' terraform_validate --color=always --show-diff-on-failure --files $(ls *.tf)'
58
58
59
- # Max Terraform version
60
- getBaseVersion :
61
- name : Module max TF version
59
+ preCommitMaxVersion :
60
+ name : Max TF pre-commit
62
61
runs-on : ubuntu-latest
62
+ needs : collectInputs
63
63
steps :
64
64
- name : Checkout
65
65
uses : actions/checkout@v2
66
+ with :
67
+ ref : ${{ github.event.pull_request.head.ref }}
68
+ repository : ${{github.event.pull_request.head.repo.full_name}}
69
+
66
70
- name : Terraform min/max versions
67
71
id : minMax
68
-
69
- outputs :
70
- minVersion : ${{ steps.minMax.outputs.minVersion }}
71
- maxVersion : ${{ steps.minMax.outputs.maxVersion }}
72
+
72
73
73
- preCommitMaxVersion :
74
- name : Max TF pre-commit
75
- runs-on : ubuntu-latest
76
- needs : getBaseVersion
77
- strategy :
78
- fail-fast : false
79
- matrix :
80
- version :
81
- - ${{ needs.getBaseVersion.outputs.maxVersion }}
82
- steps :
83
- - name : Checkout
84
- uses : actions/checkout@v2
85
- - name : Install Python
86
- uses : actions/setup-python@v2
87
- - name : Install Terraform v${{ matrix.version }}
88
- uses : hashicorp/setup-terraform@v1
74
+ - name : Pre-commit Terraform ${{ steps.minMax.outputs.maxVersion }}
75
+ uses :
clowdhaus/terraform-composite-actions/[email protected]
89
76
with :
90
- terraform_version : ${{ matrix.version }}
91
- - name : Install pre-commit dependencies
92
- run : |
93
- pip install pre-commit
94
- curl -Lo ./terraform-docs.tar.gz https://github.com/terraform-docs/terraform-docs/releases/download/v0.13.0/terraform-docs-v0.13.0-$(uname)-amd64.tar.gz && tar -xzf terraform-docs.tar.gz terraform-docs && chmod +x terraform-docs && sudo mv terraform-docs /usr/bin/
95
- curl -L "$(curl -s https://api.github.com/repos/terraform-linters/tflint/releases/latest | grep -o -E "https://.+?_linux_amd64.zip")" > tflint.zip && unzip tflint.zip tflint && rm tflint.zip && sudo mv tflint /usr/bin/
96
- - name : Execute pre-commit
97
- # Run all pre-commit checks on max version supported
98
- if : ${{ matrix.version == needs.getBaseVersion.outputs.maxVersion }}
99
- run : pre-commit run --color=always --show-diff-on-failure --all-files
77
+ terraform-version : ${{ steps.minMax.outputs.maxVersion }}
78
+ terraform-docs-version : ${{ env.TERRAFORM_DOCS_VERSION }}
0 commit comments