Skip to content

Commit 400f451

Browse files
authored
chore: add ci-cd workflow for pre-commit checks (#34)
1 parent 291dad9 commit 400f451

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

.github/workflows/pre-commit.yml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Pre-Commit
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
getBaseVersion:
11+
name: Get min/max versions
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v2
17+
18+
- name: Terraform min/max versions
19+
id: minMax
20+
uses: clowdhaus/terraform-min-max@v1.0.1
21+
outputs:
22+
minVersion: ${{ steps.minMax.outputs.minVersion }}
23+
maxVersion: ${{ steps.minMax.outputs.maxVersion }}
24+
25+
preCommit:
26+
name: Pre-commit check
27+
runs-on: ubuntu-latest
28+
needs: getBaseVersion
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
version:
33+
- ${{ needs.getBaseVersion.outputs.minVersion }}
34+
- ${{ needs.getBaseVersion.outputs.maxVersion }}
35+
36+
steps:
37+
- name: Checkout
38+
uses: actions/checkout@v2
39+
40+
- name: Install Python
41+
uses: actions/setup-python@v2
42+
43+
- name: Install Terraform v${{ matrix.version }}
44+
uses: hashicorp/setup-terraform@v1
45+
with:
46+
terraform_version: ${{ matrix.version }}
47+
48+
- name: Install pre-commit dependencies
49+
run: |
50+
pip install pre-commit
51+
curl -L "$(curl -s https://api.github.com/repos/terraform-docs/terraform-docs/releases/latest | grep -o -E "https://.+?-linux-amd64" | head -n1)" > terraform-docs && chmod +x terraform-docs && sudo mv terraform-docs /usr/bin/
52+
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/
53+
54+
- name: Execute pre-commit
55+
# Run only validate pre-commit check on min version supported
56+
if: ${{ matrix.version == needs.getBaseVersion.outputs.minVersion }}
57+
run: pre-commit run --color=always --show-diff-on-failure --all-files terraform_validate
58+
59+
- name: Execute pre-commit
60+
# Run all pre-commit checks on max version supported
61+
if: ${{ matrix.version == needs.getBaseVersion.outputs.maxVersion }}
62+
run: pre-commit run --color=always --show-diff-on-failure --all-files

0 commit comments

Comments
 (0)