-
Notifications
You must be signed in to change notification settings - Fork 0
113 lines (95 loc) · 3.69 KB
/
pre-commit.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
name: Pre-Commit
on:
pull_request:
branches:
- main
- master
env:
TERRAFORM_DOCS_VERSION: v0.16.0
jobs:
collectInputs:
name: Collect workflow inputs
runs-on: ubuntu-latest
outputs:
directories: ${{ steps.dirs.outputs.directories }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get root directories
id: dirs
uses: clowdhaus/terraform-composite-actions/directories@v1.8.3
preCommitMinVersions:
name: Min TF pre-commit
needs: collectInputs
runs-on: ubuntu-latest
strategy:
matrix:
directory: ${{ fromJson(needs.collectInputs.outputs.directories) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Terraform min/max versions
id: minMax
uses: clowdhaus/terraform-min-max@v1.3.1
with:
directory: ${{ matrix.directory }}
- name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
# Run only validate pre-commit check on min version supported
if: ${{ matrix.directory != '.' }}
uses: clowdhaus/terraform-composite-actions/pre-commit@v1.8.3
with:
terraform-version: ${{ steps.minMax.outputs.minVersion }}
args: "terraform_validate --color=always --show-diff-on-failure --files ${{ matrix.directory }}/*"
- name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}
# Run only validate pre-commit check on min version supported
if: ${{ matrix.directory == '.' }}
uses: clowdhaus/terraform-composite-actions/pre-commit@v1.8.3
with:
terraform-version: ${{ steps.minMax.outputs.minVersion }}
args: "terraform_validate --color=always --show-diff-on-failure --files $(ls *.tf)"
preCommitMaxVersion:
name: Max TF pre-commit
runs-on: ubuntu-latest
needs: collectInputs
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{github.event.pull_request.head.repo.full_name}}
- name: Terraform min/max versions
id: minMax
uses: clowdhaus/terraform-min-max@v1.3.1
- name: Install pre-commit dependencies
shell: bash
run: |
pip install -q pre-commit
curl -sSLo ./terraform-docs.tar.gz https://github.com/terraform-docs/terraform-docs/releases/download/${{ env.TERRAFORM_DOCS_VERSION }}/terraform-docs-${{ env.TERRAFORM_DOCS_VERSION }}-$(uname)-amd64.tar.gz
sudo tar -xzf terraform-docs.tar.gz -C /usr/bin/ terraform-docs
rm terraform-docs.tar.gz 2> /dev/null
curl -L "$(curl -s https://api.github.com/repos/mvdan/sh/releases/latest | grep -o -E -m 1 "https://.+?linux_amd64")" > shfmt \
&& chmod +x shfmt && sudo mv shfmt /usr/bin/
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ steps.minMax.outputs.maxVersion }}
- name: terraform test ${{ steps.minMax.outputs.maxVersion }}
id: terraform_test
shell: bash
working-directory: tests
run: |
terraform init
terraform test
- name: Execute pre-commit ${{ steps.minMax.outputs.maxVersion }}
id: pre_commit
continue-on-error: true
shell: bash
run: pre-commit run --all-files --color always --show-diff-on-failure
- name: Commit pre-commit diff
if: ${{ steps.pre_commit.outcome == 'failure' }}
uses: stefanzweifel/git-auto-commit-action@v5.0.0
with:
commit_message: Update pre-commit diff
- name: Error Exit
if: ${{ steps.pre_commit.outcome == 'failure' }}
shell: bash
run: exit 1