Skip to content

Commit 2d20356

Browse files
authored
chore: Fixed GH actions to be the same as in other terraform-aws-modules (#217)
1 parent f26887f commit 2d20356

File tree

2 files changed

+62
-17
lines changed

2 files changed

+62
-17
lines changed

.github/workflows/pre-commit.yml

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,52 +7,96 @@ on:
77
- master
88

99
jobs:
10-
getBaseVersion:
11-
name: Get min/max versions
10+
# Min Terraform version(s)
11+
getDirectories:
12+
name: Get root directories
1213
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v2
17+
- name: Install Python
18+
uses: actions/setup-python@v2
19+
- name: Build matrix
20+
id: matrix
21+
run: |
22+
DIRS=$(python -c "import json; import glob; import re; print(json.dumps([x.replace('/versions.tf', '') for x in glob.glob('./**/versions.tf', recursive=True) if not re.match(r'^.+/_', x)]))")
23+
echo "::set-output name=directories::$DIRS"
24+
outputs:
25+
directories: ${{ steps.matrix.outputs.directories }}
1326

27+
preCommitMinVersions:
28+
name: Min TF validate
29+
needs: getDirectories
30+
runs-on: ubuntu-latest
31+
strategy:
32+
matrix:
33+
directory: ${{ fromJson(needs.getDirectories.outputs.directories) }}
1434
steps:
1535
- name: Checkout
1636
uses: actions/checkout@v2
37+
- name: Install Python
38+
uses: actions/setup-python@v2
39+
- name: Terraform min/max versions
40+
id: minMax
41+
uses: clowdhaus/terraform-min-max@v1.0.2
42+
with:
43+
directory: ${{ matrix.directory }}
44+
- name: Install Terraform v${{ steps.minMax.outputs.minVersion }}
45+
uses: hashicorp/setup-terraform@v1
46+
with:
47+
terraform_version: ${{ steps.minMax.outputs.minVersion }}
48+
- name: Install pre-commit dependencies
49+
run: pip install pre-commit
50+
- name: Execute pre-commit
51+
# Run only validate pre-commit check on min version supported
52+
if: ${{ matrix.directory != '.' }}
53+
run: pre-commit run terraform_validate --color=always --show-diff-on-failure --files ${{ matrix.directory }}/*
54+
- name: Execute pre-commit
55+
# Run only validate pre-commit check on min version supported
56+
if: ${{ matrix.directory == '.' }}
57+
run: pre-commit run terraform_validate --color=always --show-diff-on-failure --files $(ls *.tf)
1758

59+
# Max Terraform version
60+
getBaseVersion:
61+
name: Module max TF version
62+
runs-on: ubuntu-latest
63+
steps:
64+
- name: Checkout
65+
uses: actions/checkout@v2
1866
- name: Terraform min/max versions
1967
id: minMax
20-
uses: clowdhaus/terraform-min-max@v1.0.1
68+
uses: clowdhaus/terraform-min-max@v1.0.2
2169
outputs:
2270
minVersion: ${{ steps.minMax.outputs.minVersion }}
2371
maxVersion: ${{ steps.minMax.outputs.maxVersion }}
2472

25-
preCommit:
26-
name: Pre-commit check
73+
preCommitMaxVersion:
74+
name: Max TF pre-commit
2775
runs-on: ubuntu-latest
2876
needs: getBaseVersion
2977
strategy:
3078
fail-fast: false
3179
matrix:
3280
version:
33-
- ${{ needs.getBaseVersion.outputs.minVersion }}
3481
- ${{ needs.getBaseVersion.outputs.maxVersion }}
35-
3682
steps:
3783
- name: Checkout
3884
uses: actions/checkout@v2
39-
4085
- name: Install Python
4186
uses: actions/setup-python@v2
42-
4387
- name: Install Terraform v${{ matrix.version }}
4488
uses: hashicorp/setup-terraform@v1
4589
with:
4690
terraform_version: ${{ matrix.version }}
47-
4891
- name: Install pre-commit dependencies
4992
run: |
5093
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-
55-
- name: Execute pre-commit
94+
curl -Lo ./terraform-docs.tar.gz https://github.com/terraform-docs/terraform-docs/releases/download/v0.13.0/terraform-docs-v0.13.0-$(uname)-amd64.tar.gz && tar -xzf terraform-docs.tar.gz && chmod +x terraform-docs && sudo mv terraform-docs /usr/bin/
95+
- name: Execute pre-commit (terraform_fmt)
96+
# Run all pre-commit checks on max version supported
97+
if: ${{ matrix.version == needs.getBaseVersion.outputs.maxVersion }}
98+
run: pre-commit run terraform_fmt --color=always --show-diff-on-failure --all-files
99+
- name: Execute pre-commit (terraform_docs)
56100
# Run all pre-commit checks on max version supported
57101
if: ${{ matrix.version == needs.getBaseVersion.outputs.maxVersion }}
58-
run: pre-commit run --color=always --show-diff-on-failure --all-files
102+
run: pre-commit run terraform_docs --color=always --show-diff-on-failure --all-files

.pre-commit-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ repos:
33
rev: v1.50.0
44
hooks:
55
- id: terraform_fmt
6+
- id: terraform_validate
67
- id: terraform_docs
78
- repo: git://github.com/pre-commit/pre-commit-hooks
8-
rev: v3.4.0
9+
rev: v4.0.1
910
hooks:
1011
- id: check-merge-conflict

0 commit comments

Comments
 (0)