Skip to content

Commit 6711deb

Browse files
authored
chore: update CI workflow to use composite actions, update pre-commit versions (#242)
1 parent d6e8f8f commit 6711deb

File tree

8 files changed

+55
-72
lines changed

8 files changed

+55
-72
lines changed

.github/workflows/pre-commit.yml

Lines changed: 43 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,98 +2,79 @@ name: Pre-Commit
22

33
on:
44
pull_request:
5-
push:
65
branches:
6+
- main
77
- master
88

9+
env:
10+
TERRAFORM_DOCS_VERSION: v0.16.0
11+
912
jobs:
10-
# Min Terraform version(s)
11-
getDirectories:
12-
name: Get root directories
13+
collectInputs:
14+
name: Collect workflow inputs
1315
runs-on: ubuntu-latest
16+
outputs:
17+
directories: ${{ steps.dirs.outputs.directories }}
1418
steps:
1519
- name: Checkout
1620
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; print(json.dumps([x.replace('/versions.tf', '') for x in glob.glob('./**/versions.tf', recursive=True)]))")
23-
echo "::set-output name=directories::$DIRS"
24-
outputs:
25-
directories: ${{ steps.matrix.outputs.directories }}
21+
22+
- name: Get root directories
23+
id: dirs
24+
uses: clowdhaus/terraform-composite-actions/[email protected]
2625

2726
preCommitMinVersions:
28-
name: Min TF validate
29-
needs: getDirectories
27+
name: Min TF pre-commit
28+
needs: collectInputs
3029
runs-on: ubuntu-latest
3130
strategy:
3231
matrix:
33-
directory: ${{ fromJson(needs.getDirectories.outputs.directories) }}
32+
directory: ${{ fromJson(needs.collectInputs.outputs.directories) }}
3433
steps:
3534
- name: Checkout
3635
uses: actions/checkout@v2
37-
- name: Install Python
38-
uses: actions/setup-python@v2
36+
3937
- name: Terraform min/max versions
4038
id: minMax
41-
uses: clowdhaus/[email protected].2
39+
uses: clowdhaus/[email protected].3
4240
with:
4341
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
42+
43+
- name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
5144
# Run only validate pre-commit check on min version supported
5245
if: ${{ matrix.directory != '.' }}
53-
run: pre-commit run terraform_validate --color=always --show-diff-on-failure --files ${{ matrix.directory }}/*
54-
- name: Execute pre-commit
46+
uses: clowdhaus/terraform-composite-actions/[email protected]
47+
with:
48+
terraform-version: ${{ steps.minMax.outputs.minVersion }}
49+
terraform-docs-version: ${{ env.TERRAFORM_DOCS_VERSION }}
50+
args: 'terraform_validate --color=always --show-diff-on-failure --files ${{ matrix.directory }}/*'
51+
52+
- name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
5553
# Run only validate pre-commit check on min version supported
5654
if: ${{ matrix.directory == '.' }}
57-
run: pre-commit run terraform_validate --color=always --show-diff-on-failure --files $(ls *.tf)
55+
uses: clowdhaus/terraform-composite-actions/[email protected]
56+
with:
57+
terraform-version: ${{ steps.minMax.outputs.minVersion }}
58+
terraform-docs-version: ${{ env.TERRAFORM_DOCS_VERSION }}
59+
args: 'terraform_validate --color=always --show-diff-on-failure --files $(ls *.tf)'
5860

59-
# Max Terraform version
60-
getBaseVersion:
61-
name: Module max TF version
61+
preCommitMaxVersion:
62+
name: Max TF pre-commit
6263
runs-on: ubuntu-latest
64+
needs: collectInputs
6365
steps:
6466
- name: Checkout
6567
uses: actions/checkout@v2
68+
with:
69+
ref: ${{ github.event.pull_request.head.ref }}
70+
repository: ${{github.event.pull_request.head.repo.full_name}}
71+
6672
- name: Terraform min/max versions
6773
id: minMax
68-
uses: clowdhaus/[email protected]
69-
outputs:
70-
minVersion: ${{ steps.minMax.outputs.minVersion }}
71-
maxVersion: ${{ steps.minMax.outputs.maxVersion }}
74+
uses: clowdhaus/[email protected]
7275

73-
preCommitMaxVersion:
74-
name: Max TF pre-commit
75-
runs-on: ubuntu-latest
76-
needs: getBaseVersion
77-
strategy:
78-
fail-fast: false
79-
matrix:
80-
version:
81-
- ${{ needs.getBaseVersion.outputs.maxVersion }}
82-
steps:
83-
- name: Checkout
84-
uses: actions/checkout@v2
85-
- name: Install Python
86-
uses: actions/setup-python@v2
87-
- name: Install Terraform v${{ matrix.version }}
88-
uses: hashicorp/setup-terraform@v1
76+
- name: Pre-commit Terraform ${{ steps.minMax.outputs.maxVersion }}
77+
uses: clowdhaus/terraform-composite-actions/[email protected]
8978
with:
90-
terraform_version: ${{ matrix.version }}
91-
- name: Install pre-commit dependencies
92-
run: |
93-
pip install 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-
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/
96-
- name: Execute pre-commit
97-
# Run all pre-commit checks on max version supported
98-
if: ${{ matrix.version == needs.getBaseVersion.outputs.maxVersion }}
99-
run: pre-commit run --color=always --show-diff-on-failure --all-files
79+
terraform-version: ${{ steps.minMax.outputs.maxVersion }}
80+
terraform-docs-version: ${{ env.TERRAFORM_DOCS_VERSION }}

.pre-commit-config.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
repos:
22
- repo: git://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.50.0
3+
rev: v1.52.0
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_validate
77
- id: terraform_docs
8+
args:
9+
- '--args=--lockfile=false'
810
- id: terraform_tflint
911
args:
1012
- '--args=--only=terraform_deprecated_interpolation'
@@ -21,6 +23,6 @@ repos:
2123
- '--args=--only=terraform_standard_module_structure'
2224
- '--args=--only=terraform_workspace_remote'
2325
- repo: git://github.com/pre-commit/pre-commit-hooks
24-
rev: v3.4.0
26+
rev: v4.0.1
2527
hooks:
2628
- id: check-merge-conflict

examples/autoscaling/README.md

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

3333
| Name | Source | Version |
3434
|------|--------|---------|
35-
| <a name="module_aurora"></a> [aurora](#module\_aurora) | ../../ | |
36-
| <a name="module_disabled_aurora"></a> [disabled\_aurora](#module\_disabled\_aurora) | ../../ | |
35+
| <a name="module_aurora"></a> [aurora](#module\_aurora) | ../../ | n/a |
36+
| <a name="module_disabled_aurora"></a> [disabled\_aurora](#module\_disabled\_aurora) | ../../ | n/a |
3737
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
3838

3939
## Resources

examples/custom_instance_settings/README.md

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

3333
| Name | Source | Version |
3434
|------|--------|---------|
35-
| <a name="module_aurora"></a> [aurora](#module\_aurora) | ../../ | |
35+
| <a name="module_aurora"></a> [aurora](#module\_aurora) | ../../ | n/a |
3636
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
3737

3838
## Resources

examples/mysql/README.md

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

3535
| Name | Source | Version |
3636
|------|--------|---------|
37-
| <a name="module_aurora"></a> [aurora](#module\_aurora) | ../../ | |
37+
| <a name="module_aurora"></a> [aurora](#module\_aurora) | ../../ | n/a |
3838
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
3939

4040
## Resources

examples/postgresql/README.md

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

3535
| Name | Source | Version |
3636
|------|--------|---------|
37-
| <a name="module_aurora"></a> [aurora](#module\_aurora) | ../../ | |
37+
| <a name="module_aurora"></a> [aurora](#module\_aurora) | ../../ | n/a |
3838
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
3939

4040
## Resources

examples/s3_import/README.md

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

6464
| Name | Source | Version |
6565
|------|--------|---------|
66-
| <a name="module_aurora"></a> [aurora](#module\_aurora) | ../../ | |
66+
| <a name="module_aurora"></a> [aurora](#module\_aurora) | ../../ | n/a |
6767
| <a name="module_import_s3_bucket"></a> [import\_s3\_bucket](#module\_import\_s3\_bucket) | terraform-aws-modules/s3-bucket/aws | ~> 2.0 |
6868
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
6969

examples/serverless/README.md

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

3333
| Name | Source | Version |
3434
|------|--------|---------|
35-
| <a name="module_aurora_mysql"></a> [aurora\_mysql](#module\_aurora\_mysql) | ../../ | |
36-
| <a name="module_aurora_postgresql"></a> [aurora\_postgresql](#module\_aurora\_postgresql) | ../../ | |
35+
| <a name="module_aurora_mysql"></a> [aurora\_mysql](#module\_aurora\_mysql) | ../../ | n/a |
36+
| <a name="module_aurora_postgresql"></a> [aurora\_postgresql](#module\_aurora\_postgresql) | ../../ | n/a |
3737
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
3838

3939
## Resources

0 commit comments

Comments
 (0)