Skip to content

Commit 740a3ca

Browse files
authored
chore: add ci-cd workflow for pre-commit checks (#73)
1 parent b38f47d commit 740a3ca

File tree

5 files changed

+69
-7
lines changed

5 files changed

+69
-7
lines changed

.github/workflows/pre-commit.yml

Lines changed: 62 additions & 0 deletions
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

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: git://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.45.0
3+
rev: v1.46.0
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_validate

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ No Modules.
8484

8585
| Name |
8686
|------|
87-
| [aws_acm_certificate_validation](https://registry.terraform.io/providers/hashicorp/aws/2.53/docs/resources/acm_certificate_validation) |
88-
| [aws_acm_certificate](https://registry.terraform.io/providers/hashicorp/aws/2.53/docs/resources/acm_certificate) |
89-
| [aws_route53_record](https://registry.terraform.io/providers/hashicorp/aws/2.53/docs/resources/route53_record) |
87+
| [aws_acm_certificate](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/acm_certificate) |
88+
| [aws_acm_certificate_validation](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/acm_certificate_validation) |
89+
| [aws_route53_record](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) |
9090

9191
## Inputs
9292

examples/complete-dns-validation/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ Note that this example may create resources which cost money. Run `terraform des
4242

4343
| Name |
4444
|------|
45-
| [aws_route53_zone](https://registry.terraform.io/providers/hashicorp/aws/2.53/docs/data-sources/route53_zone) |
46-
| [aws_route53_zone](https://registry.terraform.io/providers/hashicorp/aws/2.53/docs/resources/route53_zone) |
45+
| [aws_route53_zone](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/route53_zone) |
46+
| [aws_route53_zone](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_zone) |
4747

4848
## Inputs
4949

examples/complete-email-validation/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Note that this example may create resources which cost money. Run `terraform des
5555

5656
| Name |
5757
|------|
58-
| [aws_route53_zone](https://registry.terraform.io/providers/hashicorp/aws/2.53/docs/resources/route53_zone) |
58+
| [aws_route53_zone](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_zone) |
5959

6060
## Inputs
6161

0 commit comments

Comments
 (0)