From cbe6afda4d3606bebd2bd72bb83f97c47c150606 Mon Sep 17 00:00:00 2001 From: Igor Rodionov Date: Fri, 12 Jul 2024 16:30:29 +0200 Subject: [PATCH] [terraform-ci] Added bats (#124) * Added bats --- .github/workflows/ci-terraform.yml | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/.github/workflows/ci-terraform.yml b/.github/workflows/ci-terraform.yml index 5cb2939..bca355a 100644 --- a/.github/workflows/ci-terraform.yml +++ b/.github/workflows/ci-terraform.yml @@ -61,6 +61,44 @@ jobs: shell: bash run: git diff --exit-code + bats: + runs-on: ubuntu-latest + container: cloudposse/test-harness:latest + env: + MAKE_INCLUDES: Makefile + TF_PLUGIN_CACHE_DIR: /tmp + BATS_MODULE_TESTS: input-descriptions module-pinning provider-pinning output-descriptions + BATS_EXAMPLES_TESTS: input-descriptions lint output-descriptions + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Run tests on modified modules + shell: bash -x -e -o pipefail {0} + run: | + # when running in test-harness, need to mark the directory safe for git operations + make git-safe-directory + MODIFIED_MODULES=($(find . -type f -name "*.tf" | xargs -I{} dirname {} | sort | uniq | grep -v ^./.git/ || true)) + pass=true + for relative_dir in "${MODIFIED_MODULES[@]}"; do + dir=$(realpath $relative_dir) + printf "\n\nBegin testing in $dir\n" + ( + status=pass + cd $dir + [[ $relative_dir =~ ./examples/.* ]] && tests=$BATS_EXAMPLES_TESTS || tests=$BATS_MODULE_TESTS + for test in $tests; do + printf "\n\nRunning ${test} in $dir\n" + bats -t /test/terraform/${test}.bats || status=fail + done + [[ $status == "pass" ]] + ) || pass=false + printf "\n\nEnd of testing in $dir\n\n\n" + done + [[ $pass == "true" ]] + lint-find-dirs: name: Find modules runs-on: ${{ fromJSON(inputs.runs-on) }}