Skip to content

Commit ff53cf4

Browse files
authored
chore: add ci-cd workflow for pre-commit checks (#29)
1 parent 46c4ddb commit ff53cf4

File tree

6 files changed

+68
-59
lines changed

6 files changed

+68
-59
lines changed

.github/workflows/lint.yml

Lines changed: 0 additions & 53 deletions
This file was deleted.

.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

README.md

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

6666
| Name |
6767
|------|
68-
| [aws_appautoscaling_policy](https://registry.terraform.io/providers/hashicorp/aws/2.58/docs/resources/appautoscaling_policy) |
69-
| [aws_appautoscaling_target](https://registry.terraform.io/providers/hashicorp/aws/2.58/docs/resources/appautoscaling_target) |
70-
| [aws_dynamodb_table](https://registry.terraform.io/providers/hashicorp/aws/2.58/docs/resources/dynamodb_table) |
68+
| [aws_appautoscaling_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appautoscaling_policy) |
69+
| [aws_appautoscaling_target](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appautoscaling_target) |
70+
| [aws_dynamodb_table](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/dynamodb_table) |
7171

7272
## Inputs
7373

examples/autoscaling/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Note that this example may create resources which can cost money (AWS Elastic IP
4040

4141
| Name |
4242
|------|
43-
| [random_pet](https://registry.terraform.io/providers/hashicorp/random/2.0/docs/resources/pet) |
43+
| [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) |
4444

4545
## Inputs
4646

examples/basic/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Note that this example may create resources which can cost money (AWS Elastic IP
4040

4141
| Name |
4242
|------|
43-
| [random_pet](https://registry.terraform.io/providers/hashicorp/random/2.0/docs/resources/pet) |
43+
| [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) |
4444

4545
## Inputs
4646

examples/global-tables/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Note that this example may create resources which can cost money (AWS Elastic IP
3939

4040
| Name |
4141
|------|
42-
| [random_pet](https://registry.terraform.io/providers/hashicorp/random/2.0/docs/resources/pet) |
42+
| [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) |
4343

4444
## Inputs
4545

0 commit comments

Comments
 (0)