|
7 | 7 | - master |
8 | 8 |
|
9 | 9 | jobs: |
10 | | - getBaseVersion: |
11 | | - name: Get min/max versions |
| 10 | + # Min Terraform version(s) |
| 11 | + getDirectories: |
| 12 | + name: Get root directories |
12 | 13 | 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 }} |
13 | 26 |
|
| 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) }} |
14 | 34 | steps: |
15 | 35 | - name: Checkout |
16 | 36 | 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) |
17 | 58 |
|
| 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 |
18 | 66 | - name: Terraform min/max versions |
19 | 67 | id: minMax |
20 | | - uses: clowdhaus/terraform-min-max@v1.0.1 |
| 68 | + uses: clowdhaus/terraform-min-max@v1.0.2 |
21 | 69 | outputs: |
22 | 70 | minVersion: ${{ steps.minMax.outputs.minVersion }} |
23 | 71 | maxVersion: ${{ steps.minMax.outputs.maxVersion }} |
24 | 72 |
|
25 | | - preCommit: |
26 | | - name: Pre-commit check |
| 73 | + preCommitMaxVersion: |
| 74 | + name: Max TF pre-commit |
27 | 75 | runs-on: ubuntu-latest |
28 | 76 | needs: getBaseVersion |
29 | 77 | strategy: |
30 | 78 | fail-fast: false |
31 | 79 | matrix: |
32 | 80 | version: |
33 | | - - ${{ needs.getBaseVersion.outputs.minVersion }} |
34 | 81 | - ${{ needs.getBaseVersion.outputs.maxVersion }} |
35 | | - |
36 | 82 | steps: |
37 | 83 | - name: Checkout |
38 | 84 | uses: actions/checkout@v2 |
39 | | - |
40 | 85 | - name: Install Python |
41 | 86 | uses: actions/setup-python@v2 |
42 | | - |
43 | 87 | - name: Install Terraform v${{ matrix.version }} |
44 | 88 | uses: hashicorp/setup-terraform@v1 |
45 | 89 | with: |
46 | 90 | terraform_version: ${{ matrix.version }} |
47 | | - |
48 | 91 | - name: Install pre-commit dependencies |
49 | 92 | run: | |
50 | 93 | 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) |
56 | 100 | # Run all pre-commit checks on max version supported |
57 | 101 | 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 |
0 commit comments