Skip to content

Commit 0994b9b

Browse files
committed
upgrading to 1.0.1
1 parent b1cc843 commit 0994b9b

File tree

1 file changed

+106
-22
lines changed

1 file changed

+106
-22
lines changed

.github/workflows/pre-commit.yml

Lines changed: 106 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,117 @@
1-
name: Security Scans
1+
name: Pre-Commit
22

33
on:
4+
pull_request:
45
push:
56
branches:
6-
- develop
77
- main
8-
paths-ignore:
9-
- 'README.md'
10-
- 'LICENSE'
11-
- '.gitignore'
12-
- '**.md'
13-
pull_request:
14-
paths-ignore:
15-
- 'README.md'
16-
- 'LICENSE'
17-
- '.gitignore'
18-
- '**.md'
8+
- develop
199

2010
jobs:
21-
scans:
22-
name: Security Scans
11+
# Min Terraform version(s)
12+
getDirectories:
13+
name: Get root directories
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v2
18+
19+
- name: Install Python
20+
uses: actions/setup-python@v2
21+
22+
- name: Build matrix
23+
id: matrix
24+
run: |
25+
DIRS=$(python -c "import json; import glob; print(json.dumps([x.replace('/versions.tf', '') for x in glob.glob('./**/versions.tf', recursive=True)]))")
26+
echo "::set-output name=directories::$DIRS"
27+
outputs:
28+
directories: ${{ steps.matrix.outputs.directories }}
29+
30+
preCommitMinVersions:
31+
name: Min TF validate
32+
needs: getDirectories
2333
runs-on: ubuntu-latest
34+
strategy:
35+
matrix:
36+
directory: ${{ fromJson(needs.getDirectories.outputs.directories) }}
2437
steps:
25-
- uses: actions/checkout@v2
38+
- name: Checkout
39+
uses: actions/checkout@v2
2640

27-
- name: Checkov Scan
28-
id: checkov
29-
uses: bridgecrewio/checkov-action@master
41+
- name: Install Python
42+
uses: actions/setup-python@v2
43+
44+
- name: Terraform min/max versions
45+
id: minMax
46+
uses: clowdhaus/terraform-min-max@v1.0.1
3047
with:
31-
directory: "."
32-
framework: terraform # optional: run only on a specific infrastructure {cloudformation,terraform,kubernetes,all}
33-
output_format: json # optional: the output format, one of: cli, json, junitxml, github_failed_only
48+
directory: ${{ matrix.directory }}
49+
50+
- name: Install Terraform v${{ steps.minMax.outputs.minVersion }}
51+
uses: hashicorp/setup-terraform@v1
52+
with:
53+
terraform_version: ${{ steps.minMax.outputs.minVersion }}
54+
55+
- name: Install pre-commit dependencies
56+
run: pip install pre-commit
57+
58+
# - name: Execute pre-commit
59+
# # Run only validate pre-commit check on min version supported
60+
# if: ${{ matrix.directory != '.' }}
61+
# run:
62+
# pre-commit run terraform_validate --color=always --show-diff-on-failure --files ${{ matrix.directory }}/*
63+
#
64+
# - name: Execute pre-commit
65+
# # Run only validate pre-commit check on min version supported
66+
# if: ${{ matrix.directory == '.' }}
67+
# run:
68+
# pre-commit run terraform_validate --color=always --show-diff-on-failure --files $(ls *.tf)
69+
70+
71+
# Max Terraform version
72+
getBaseVersion:
73+
name: Module max TF version
74+
runs-on: ubuntu-latest
75+
steps:
76+
- name: Checkout
77+
uses: actions/checkout@v2
78+
79+
- name: Terraform min/max versions
80+
id: minMax
81+
uses: clowdhaus/terraform-min-max@v1.0.1
82+
outputs:
83+
minVersion: ${{ steps.minMax.outputs.minVersion }}
84+
maxVersion: ${{ steps.minMax.outputs.maxVersion }}
85+
86+
preCommitMaxVersion:
87+
name: Max TF pre-commit
88+
runs-on: ubuntu-latest
89+
needs: getBaseVersion
90+
strategy:
91+
fail-fast: false
92+
matrix:
93+
version:
94+
- ${{ needs.getBaseVersion.outputs.maxVersion }}
95+
steps:
96+
- name: Checkout
97+
uses: actions/checkout@v2
98+
99+
- name: Install Python
100+
uses: actions/setup-python@v2
101+
102+
- name: Install Terraform v${{ matrix.version }}
103+
uses: hashicorp/setup-terraform@v1
104+
with:
105+
terraform_version: ${{ matrix.version }}
106+
107+
- name: Install pre-commit dependencies
108+
run: |
109+
pip install pre-commit
110+
pip install checkov
111+
curl -L "$(curl -s https://api.github.com/repos/terraform-docs/terraform-docs/releases/latest | grep -o -E "https://.+?-v0.12.1-linux-amd64" | head -n1)" > terraform-docs && chmod +x terraform-docs && sudo mv terraform-docs /usr/bin/
112+
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 && rm tflint.zip && sudo mv tflint /usr/bin/
113+
114+
- name: Execute pre-commit
115+
# Run all pre-commit checks on max version supported
116+
if: ${{ matrix.version == needs.getBaseVersion.outputs.maxVersion }}
117+
run: pre-commit run --color=always --show-diff-on-failure --all-files

0 commit comments

Comments
 (0)