|
| 1 | +name: Pre-Commit |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - master |
| 8 | + |
| 9 | +env: |
| 10 | + TERRAFORM_DOCS_VERSION: v0.20.0 |
| 11 | + TFLINT_VERSION: v0.59.1 |
| 12 | + |
| 13 | +jobs: |
| 14 | + collectInputs: |
| 15 | + name: Collect workflow inputs |
| 16 | + runs-on: ubuntu-latest |
| 17 | + outputs: |
| 18 | + directories: ${{ steps.dirs.outputs.directories }} |
| 19 | + steps: |
| 20 | + - name: Checkout |
| 21 | + uses: actions/checkout@v5 |
| 22 | + |
| 23 | + - name: Get root directories |
| 24 | + id: dirs |
| 25 | + uses: clowdhaus/terraform-composite-actions/directories@v1.14.0 |
| 26 | + |
| 27 | + preCommitMinVersions: |
| 28 | + name: Min TF pre-commit |
| 29 | + needs: collectInputs |
| 30 | + runs-on: ubuntu-latest |
| 31 | + strategy: |
| 32 | + matrix: |
| 33 | + directory: ${{ fromJson(needs.collectInputs.outputs.directories) }} |
| 34 | + steps: |
| 35 | + - name: Install rmz |
| 36 | + uses: jaxxstorm/action-install-gh-release@v2.1.0 |
| 37 | + with: |
| 38 | + repo: SUPERCILEX/fuc |
| 39 | + asset-name: x86_64-unknown-linux-gnu-rmz |
| 40 | + rename-to: rmz |
| 41 | + chmod: 0755 |
| 42 | + extension-matching: disable |
| 43 | + |
| 44 | + # https://github.com/orgs/community/discussions/25678#discussioncomment-5242449 |
| 45 | + - name: Delete unnecessary files |
| 46 | + run: | |
| 47 | + formatByteCount() { echo $(numfmt --to=iec-i --suffix=B --padding=7 $1'000'); } |
| 48 | + getAvailableSpace() { echo $(df -a $1 | awk 'NR > 1 {avail+=$4} END {print avail}'); } |
| 49 | +
|
| 50 | + BEFORE=$(getAvailableSpace) |
| 51 | +
|
| 52 | + ln -s /opt/hostedtoolcache/SUPERCILEX/x86_64-unknown-linux-gnu-rmz/latest/linux-x64/rmz /usr/local/bin/rmz |
| 53 | + rmz -f /opt/hostedtoolcache/CodeQL & |
| 54 | + rmz -f /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk & |
| 55 | + rmz -f /opt/hostedtoolcache/PyPy & |
| 56 | + rmz -f /opt/hostedtoolcache/Ruby & |
| 57 | + rmz -f /opt/hostedtoolcache/go & |
| 58 | +
|
| 59 | + wait |
| 60 | +
|
| 61 | + AFTER=$(getAvailableSpace) |
| 62 | + SAVED=$((AFTER-BEFORE)) |
| 63 | + echo "=> Saved $(formatByteCount $SAVED)" |
| 64 | +
|
| 65 | + - name: Checkout |
| 66 | + uses: actions/checkout@v5 |
| 67 | + |
| 68 | + - name: Terraform min/max versions |
| 69 | + id: minMax |
| 70 | + uses: clowdhaus/terraform-min-max@v2.1.0 |
| 71 | + with: |
| 72 | + directory: ${{ matrix.directory }} |
| 73 | + |
| 74 | + - name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }} |
| 75 | + # Run only validate pre-commit check on min version supported |
| 76 | + if: ${{ matrix.directory != '.' }} |
| 77 | + uses: clowdhaus/terraform-composite-actions/pre-commit@v1.14.0 |
| 78 | + with: |
| 79 | + terraform-version: ${{ steps.minMax.outputs.minVersion }} |
| 80 | + tflint-version: ${{ env.TFLINT_VERSION }} |
| 81 | + args: 'terraform_validate --color=always --show-diff-on-failure --files ${{ matrix.directory }}/*' |
| 82 | + |
| 83 | + - name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }} |
| 84 | + # Run only validate pre-commit check on min version supported |
| 85 | + if: ${{ matrix.directory == '.' }} |
| 86 | + uses: clowdhaus/terraform-composite-actions/pre-commit@v1.14.0 |
| 87 | + with: |
| 88 | + terraform-version: ${{ steps.minMax.outputs.minVersion }} |
| 89 | + tflint-version: ${{ env.TFLINT_VERSION }} |
| 90 | + args: 'terraform_validate --color=always --show-diff-on-failure --files $(ls *.tf)' |
| 91 | + |
| 92 | + preCommitMaxVersion: |
| 93 | + name: Max TF pre-commit |
| 94 | + runs-on: ubuntu-latest |
| 95 | + needs: collectInputs |
| 96 | + steps: |
| 97 | + - name: Install rmz |
| 98 | + uses: jaxxstorm/action-install-gh-release@v2.1.0 |
| 99 | + with: |
| 100 | + repo: SUPERCILEX/fuc |
| 101 | + asset-name: x86_64-unknown-linux-gnu-rmz |
| 102 | + rename-to: rmz |
| 103 | + chmod: 0755 |
| 104 | + extension-matching: disable |
| 105 | + |
| 106 | + # https://github.com/orgs/community/discussions/25678#discussioncomment-5242449 |
| 107 | + - name: Delete unnecessary files |
| 108 | + run: | |
| 109 | + formatByteCount() { echo $(numfmt --to=iec-i --suffix=B --padding=7 $1'000'); } |
| 110 | + getAvailableSpace() { echo $(df -a $1 | awk 'NR > 1 {avail+=$4} END {print avail}'); } |
| 111 | +
|
| 112 | + BEFORE=$(getAvailableSpace) |
| 113 | +
|
| 114 | + ln -s /opt/hostedtoolcache/SUPERCILEX/x86_64-unknown-linux-gnu-rmz/latest/linux-x64/rmz /usr/local/bin/rmz |
| 115 | + rmz -f /opt/hostedtoolcache/CodeQL & |
| 116 | + rmz -f /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk & |
| 117 | + rmz -f /opt/hostedtoolcache/PyPy & |
| 118 | + rmz -f /opt/hostedtoolcache/Ruby & |
| 119 | + rmz -f /opt/hostedtoolcache/go & |
| 120 | + sudo rmz -f /usr/local/lib/android & |
| 121 | +
|
| 122 | + if [[ ${{ github.repository }} == terraform-aws-modules/terraform-aws-security-group ]]; then |
| 123 | + sudo rmz -f /usr/share/dotnet & |
| 124 | + sudo rmz -f /usr/local/.ghcup & |
| 125 | + sudo apt-get -qq remove -y 'azure-.*' |
| 126 | + sudo apt-get -qq remove -y 'cpp-.*' |
| 127 | + sudo apt-get -qq remove -y 'dotnet-runtime-.*' |
| 128 | + sudo apt-get -qq remove -y 'google-.*' |
| 129 | + sudo apt-get -qq remove -y 'libclang-.*' |
| 130 | + sudo apt-get -qq remove -y 'libllvm.*' |
| 131 | + sudo apt-get -qq remove -y 'llvm-.*' |
| 132 | + sudo apt-get -qq remove -y 'mysql-.*' |
| 133 | + sudo apt-get -qq remove -y 'postgresql-.*' |
| 134 | + sudo apt-get -qq remove -y 'php.*' |
| 135 | + sudo apt-get -qq remove -y 'temurin-.*' |
| 136 | + sudo apt-get -qq remove -y kubectl firefox mono-devel |
| 137 | + sudo apt-get -qq autoremove -y |
| 138 | + sudo apt-get -qq clean |
| 139 | + fi |
| 140 | +
|
| 141 | + wait |
| 142 | +
|
| 143 | + AFTER=$(getAvailableSpace) |
| 144 | + SAVED=$((AFTER-BEFORE)) |
| 145 | + echo "=> Saved $(formatByteCount $SAVED)" |
| 146 | +
|
| 147 | + - name: Checkout |
| 148 | + uses: actions/checkout@v5 |
| 149 | + with: |
| 150 | + ref: ${{ github.event.pull_request.head.ref }} |
| 151 | + repository: ${{github.event.pull_request.head.repo.full_name}} |
| 152 | + |
| 153 | + - name: Terraform min/max versions |
| 154 | + id: minMax |
| 155 | + uses: clowdhaus/terraform-min-max@v2.1.0 |
| 156 | + |
| 157 | + - name: Hide template dir |
| 158 | + # Special to this repo, we don't want to check this dir |
| 159 | + if: ${{ github.repository == 'terraform-aws-modules/terraform-aws-security-group' }} |
| 160 | + run: rm -rf modules/_templates |
| 161 | + |
| 162 | + - name: Pre-commit Terraform ${{ steps.minMax.outputs.maxVersion }} |
| 163 | + uses: clowdhaus/terraform-composite-actions/pre-commit@v1.14.0 |
| 164 | + with: |
| 165 | + terraform-version: ${{ steps.minMax.outputs.maxVersion }} |
| 166 | + tflint-version: ${{ env.TFLINT_VERSION }} |
| 167 | + terraform-docs-version: ${{ env.TERRAFORM_DOCS_VERSION }} |
| 168 | + install-hcledit: true |
0 commit comments