|
7 | 7 | - master
|
8 | 8 |
|
9 | 9 | jobs:
|
10 |
| - getBaseVersion: |
11 |
| - name: Get min/max versions |
12 |
| - runs-on: ubuntu-latest |
| 10 | +# Min Terraform version(s) |
| 11 | + getDirectories: |
| 12 | + name: Get root directories |
| 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; 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 }} |
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.1 |
| 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: |
| 54 | + pre-commit run terraform_validate --color=always --show-diff-on-failure --files ${{ matrix.directory }}/* |
| 55 | + - name: Execute pre-commit |
| 56 | + # Run only validate pre-commit check on min version supported |
| 57 | + if: ${{ matrix.directory == '.' }} |
| 58 | + run: |
| 59 | + pre-commit run terraform_validate --color=always --show-diff-on-failure --files $(ls *.tf) |
| 60 | + |
17 | 61 |
|
| 62 | +# Max Terraform version |
| 63 | + getBaseVersion: |
| 64 | + name: Module max TF version |
| 65 | + runs-on: ubuntu-latest |
| 66 | + steps: |
| 67 | + - name: Checkout |
| 68 | + uses: actions/checkout@v2 |
18 | 69 | - name: Terraform min/max versions
|
19 | 70 | id: minMax
|
20 | 71 | uses: clowdhaus/terraform-min-max@v1.0.1
|
21 | 72 | outputs:
|
22 | 73 | minVersion: ${{ steps.minMax.outputs.minVersion }}
|
23 | 74 | maxVersion: ${{ steps.minMax.outputs.maxVersion }}
|
24 | 75 |
|
25 |
| - preCommit: |
26 |
| - name: Pre-commit check |
| 76 | + preCommitMaxVersion: |
| 77 | + name: Max TF pre-commit |
27 | 78 | runs-on: ubuntu-latest
|
28 | 79 | needs: getBaseVersion
|
29 | 80 | strategy:
|
30 | 81 | fail-fast: false
|
31 | 82 | matrix:
|
32 | 83 | version:
|
33 |
| - - ${{ needs.getBaseVersion.outputs.minVersion }} |
34 | 84 | - ${{ needs.getBaseVersion.outputs.maxVersion }}
|
35 |
| - |
36 | 85 | steps:
|
37 | 86 | - name: Checkout
|
38 | 87 | uses: actions/checkout@v2
|
39 |
| - |
40 | 88 | - name: Install Python
|
41 | 89 | uses: actions/setup-python@v2
|
42 |
| - |
43 | 90 | - name: Install Terraform v${{ matrix.version }}
|
44 | 91 | uses: hashicorp/setup-terraform@v1
|
45 | 92 | with:
|
46 | 93 | terraform_version: ${{ matrix.version }}
|
47 |
| - |
48 | 94 | - name: Install pre-commit dependencies
|
49 | 95 | run: |
|
50 | 96 | pip install pre-commit
|
51 | 97 | 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 | 98 | 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 | 99 | - name: Execute pre-commit
|
60 | 100 | # Run all pre-commit checks on max version supported
|
61 | 101 | if: ${{ matrix.version == needs.getBaseVersion.outputs.maxVersion }}
|
|
0 commit comments