|
| 1 | +name: pre-commit |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - master |
| 8 | + |
| 9 | +env: |
| 10 | + TERRAFORM_DOCS_VERSION: v0.16.0 |
| 11 | + |
| 12 | +jobs: |
| 13 | + collectInputs: |
| 14 | + name: Collect workflow inputs |
| 15 | + runs-on: ubuntu-latest |
| 16 | + outputs: |
| 17 | + directories: ${{ steps.dirs.outputs.directories }} |
| 18 | + steps: |
| 19 | + - name: Checkout |
| 20 | + uses: actions/checkout@v2 |
| 21 | + |
| 22 | + - name: Get root directories |
| 23 | + id: dirs |
| 24 | + uses: clowdhaus/terraform-composite-actions/directories@v1.3.0 |
| 25 | + |
| 26 | + preCommitMinVersions: |
| 27 | + name: Min TF pre-commit |
| 28 | + needs: collectInputs |
| 29 | + runs-on: ubuntu-latest |
| 30 | + strategy: |
| 31 | + matrix: |
| 32 | + directory: ${{ fromJson(needs.collectInputs.outputs.directories) }} |
| 33 | + steps: |
| 34 | + - name: Checkout |
| 35 | + uses: actions/checkout@v2 |
| 36 | + |
| 37 | + - name: Terraform min/max versions |
| 38 | + id: minMax |
| 39 | + uses: clowdhaus/terraform-min-max@v1.0.3 |
| 40 | + with: |
| 41 | + directory: ${{ matrix.directory }} |
| 42 | + |
| 43 | + - name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }} |
| 44 | + # Run only validate pre-commit check on min version supported |
| 45 | + if: ${{ matrix.directory != '.' }} |
| 46 | + uses: clowdhaus/terraform-composite-actions/pre-commit@v1.3.0 |
| 47 | + with: |
| 48 | + terraform-version: ${{ steps.minMax.outputs.minVersion }} |
| 49 | + args: 'terraform_validate --color=always --show-diff-on-failure --files ${{ matrix.directory }}/*' |
| 50 | + |
| 51 | + - name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }} |
| 52 | + # Run only validate pre-commit check on min version supported |
| 53 | + if: ${{ matrix.directory == '.' }} |
| 54 | + uses: clowdhaus/terraform-composite-actions/pre-commit@v1.3.0 |
| 55 | + with: |
| 56 | + terraform-version: ${{ steps.minMax.outputs.minVersion }} |
| 57 | + args: 'terraform_validate --color=always --show-diff-on-failure --files $(ls *.tf)' |
| 58 | + |
| 59 | + preCommitMaxVersion: |
| 60 | + name: Max TF pre-commit |
| 61 | + runs-on: ubuntu-latest |
| 62 | + needs: collectInputs |
| 63 | + steps: |
| 64 | + - name: Checkout |
| 65 | + uses: actions/checkout@v2 |
| 66 | + with: |
| 67 | + ref: ${{ github.event.pull_request.head.ref }} |
| 68 | + repository: ${{github.event.pull_request.head.repo.full_name}} |
| 69 | + |
| 70 | + - name: Terraform min/max versions |
| 71 | + id: minMax |
| 72 | + uses: clowdhaus/terraform-min-max@v1.0.3 |
| 73 | + |
| 74 | + - name: Pre-commit Terraform ${{ steps.minMax.outputs.maxVersion }} |
| 75 | + uses: clowdhaus/terraform-composite-actions/pre-commit@v1.3.0 |
| 76 | + with: |
| 77 | + terraform-version: ${{ steps.minMax.outputs.maxVersion }} |
| 78 | + terraform-docs-version: ${{ env.TERRAFORM_DOCS_VERSION }} |
0 commit comments