Skip to content

Commit 3374836

Browse files
authored
chore: add ci-cd workflow for pre-commit checks (#128)
1 parent df3d1d0 commit 3374836

File tree

4 files changed

+72
-10
lines changed

4 files changed

+72
-10
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/[email protected]
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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ To run the tests:
104104

105105
| Name |
106106
|------|
107-
| [aws_cloudwatch_log_group](https://registry.terraform.io/providers/hashicorp/aws/2.35/docs/resources/cloudwatch_log_group) |
108-
| [aws_iam_policy_document](https://registry.terraform.io/providers/hashicorp/aws/2.35/docs/data-sources/iam_policy_document) |
109-
| [aws_sns_topic_subscription](https://registry.terraform.io/providers/hashicorp/aws/2.35/docs/resources/sns_topic_subscription) |
110-
| [aws_sns_topic](https://registry.terraform.io/providers/hashicorp/aws/2.35/docs/data-sources/sns_topic) |
111-
| [aws_sns_topic](https://registry.terraform.io/providers/hashicorp/aws/2.35/docs/resources/sns_topic) |
107+
| [aws_cloudwatch_log_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_group) |
108+
| [aws_iam_policy_document](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) |
109+
| [aws_sns_topic](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/sns_topic) |
110+
| [aws_sns_topic](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic) |
111+
| [aws_sns_topic_subscription](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic_subscription) |
112112

113113
## Inputs
114114

examples/cloudwatch-alerts-to-slack/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ Note that this example may create resources which can cost money. Run `terraform
8282

8383
| Name |
8484
|------|
85-
| [aws_cloudwatch_metric_alarm](https://registry.terraform.io/providers/hashicorp/aws/2.35/docs/resources/cloudwatch_metric_alarm) |
86-
| [aws_kms_ciphertext](https://registry.terraform.io/providers/hashicorp/aws/2.35/docs/resources/kms_ciphertext) |
87-
| [aws_kms_key](https://registry.terraform.io/providers/hashicorp/aws/2.35/docs/resources/kms_key) |
88-
| [random_pet](https://registry.terraform.io/providers/hashicorp/random/2/docs/resources/pet) |
85+
| [aws_cloudwatch_metric_alarm](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_metric_alarm) |
86+
| [aws_kms_ciphertext](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_ciphertext) |
87+
| [aws_kms_key](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) |
88+
| [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) |
8989

9090
## Inputs
9191

examples/notify-slack-simple/README.md

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

4343
| Name |
4444
|------|
45-
| [aws_sns_topic](https://registry.terraform.io/providers/hashicorp/aws/2.35/docs/resources/sns_topic) |
45+
| [aws_sns_topic](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic) |
4646

4747
## Inputs
4848

0 commit comments

Comments
 (0)