|
| 1 | +# Copyright 2025 Cloudera, Inc. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +name: Check Terraform module documentation |
| 16 | + |
| 17 | +on: |
| 18 | + pull_request: |
| 19 | + push: |
| 20 | + branches: [main] |
| 21 | + |
| 22 | +env: |
| 23 | + TERRAFORM_DOCS_VERSION: v0.20.0 |
| 24 | + |
| 25 | +jobs: |
| 26 | + check-tf-fmt: |
| 27 | + runs-on: ubuntu-latest |
| 28 | + steps: |
| 29 | + - name: Checkout |
| 30 | + uses: actions/checkout@v3 |
| 31 | + |
| 32 | + - name: Find the modules |
| 33 | + id: find_modules |
| 34 | + run: | |
| 35 | + echo "MODULES=$(find modules/ -maxdepth 1 -type d -name 'terraform-*' | paste -sd,)" >> "$GITHUB_ENV" |
| 36 | +
|
| 37 | + - name: Print list of modules |
| 38 | + run: | |
| 39 | + echo "Terraform modules found: $MODULES" |
| 40 | +
|
| 41 | + - name: Install the terraform-docs utility |
| 42 | + run: | |
| 43 | + curl -sSLo ./terraform-docs.tar.gz https://terraform-docs.io/dl/${TERRAFORM_DOCS_VERSION}/terraform-docs-${TERRAFORM_DOCS_VERSION}-linux-amd64.tar.gz |
| 44 | + tar -xzf terraform-docs.tar.gz |
| 45 | + chmod +x terraform-docs |
| 46 | + sudo mv terraform-docs /usr/local/bin/ |
| 47 | + |
| 48 | + - name: Validate terraform module docs with terraform-docs |
| 49 | + run: | |
| 50 | + FAILED_MODULES=() |
| 51 | + for module in $(echo "$MODULES" | tr ',' '\n'); do |
| 52 | + echo "Checking $module" |
| 53 | + if ! terraform-docs --output-check "$module"; then |
| 54 | + echo "❌ terraform-docs check failed for $module" |
| 55 | + FAILED_MODULES+=("$module") |
| 56 | + else |
| 57 | + echo "✅ $module passed terraform-docs check" |
| 58 | + fi |
| 59 | + done |
| 60 | +
|
| 61 | + if [ ${#FAILED_MODULES[@]} -ne 0 ]; then |
| 62 | + echo "The following modules failed terraform-docs check:" |
| 63 | + for failed in "${FAILED_MODULES[@]}"; do |
| 64 | + echo " - $failed" |
| 65 | + done |
| 66 | + exit 1 |
| 67 | + fi |
0 commit comments