From 6e391adfdf1d0e6e8af8fda95ec29e1a1de21f17 Mon Sep 17 00:00:00 2001 From: Helena Solberg Kallekleiv <110530547+helenakallekleiv@users.noreply.github.com> Date: Fri, 22 Mar 2024 14:29:20 +0100 Subject: [PATCH] ci: use reusable test workflow --- .github/workflows/terraform-test.yml | 108 --------------------------- .github/workflows/test.yml | 2 +- 2 files changed, 1 insertion(+), 109 deletions(-) delete mode 100644 .github/workflows/terraform-test.yml diff --git a/.github/workflows/terraform-test.yml b/.github/workflows/terraform-test.yml deleted file mode 100644 index 595f7df..0000000 --- a/.github/workflows/terraform-test.yml +++ /dev/null @@ -1,108 +0,0 @@ -on: - workflow_call: - inputs: - test-filter: - description: Limit the Terraform Test operation to the specified test files. - type: string - required: false - -jobs: - terraform-test: - name: Terraform Test - runs-on: ubuntu-latest - env: - TF_IN_AUTOMATION: true - TF_TEST_RESULTS_FILE: tftest - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Setup Terraform - uses: hashicorp/setup-terraform@v3 - with: - terraform_version: latest - terraform_wrapper: false - - - name: Terraform Format - id: fmt - run: terraform fmt -check - - - name: Terraform Init - id: init - run: terraform init - - - name: Terraform Validate - id: validate - run: terraform validate - - - name: Terraform Test - id: test - # Ensure that the outcome of this step is "failure" when "terraform test" returns a non-zero exit code - shell: bash -o pipefail {0} - env: - TF_TEST_FILTER: ${{ inputs.test-filter }} - run: terraform test -filter="$TF_TEST_FILTER" -json | tee "$TF_TEST_RESULTS_FILE" - - - name: Create job summary - if: success() || failure() - shell: bash {0} - env: - TF_FMT_OUTCOME: ${{ steps.fmt.outcome }} - TF_INIT_OUTCOME: ${{ steps.init.outcome }} - TF_VALIDATE_OUTCOME: ${{ steps.validate.outcome }} - TF_TEST_OUTCOME: ${{ steps.test.outcome }} - run: | - tftest_results=$(cat "$TF_TEST_RESULTS_FILE") - readarray -t tftest_array <<< "$tftest_results" - - table_rows=("| Path | Run | Status | Error message |") - table_rows+=("| --- | --- | --- | --- |") - - for tftest_json in "${tftest_array[@]}"; do - type=$(echo "$tftest_json" | jq -r .type) - - if [[ "$type" != "test_run" ]]; then - continue - fi - - test_run=$(echo "$tftest_json" | jq .test_run) - progress=$(echo "$test_run" | jq -r .progress) - - if [[ "$progress" != "complete" ]]; then - continue - fi - - path=$(echo "$test_run" | jq -r .path) - run=$(echo "$test_run" | jq -r .run) - status=$(echo "$test_run" | jq -r .status) - error_message=$(echo "$test_run" | jq -r .error_message) - status_emoji="heavy_minus_sign" # neutral/unknown by default - - if [[ "$status" == "pass" ]]; then - status_emoji="heavy_check_mark" - fi - - error_message="" - if [[ "$status" == "fail" ]]; then - status_emoji="x" - error_message=$(echo "$tftest_results" | jq -r '. | select(."@level"=="error") | .diagnostic.detail | tostring') - fi - - table_rows+=("| \`$path\` | \`$run\` | :$status_emoji:**\`$status\`** | $error_message |") - done - - table=$(printf "%s\n" "${table_rows[@]}") - - echo "#### Terraform Format and Style ๐Ÿ–Œ\`$TF_FMT_OUTCOME\` - #### Terraform Initialization โš™\`$TF_INIT_OUTCOME\` - #### Terraform Validation ๐Ÿค–\`$TF_VALIDATE_OUTCOME\` - #### Terraform Test ๐Ÿงช\`$TF_TEST_OUTCOME\` - -
Show Tests - - $table - -
- - *Pusher: @$GITHUB_ACTOR, Action: \`$GITHUB_EVENT_NAME\`, Workflow: \`$GITHUB_WORKFLOW\`*" >> "$GITHUB_STEP_SUMMARY" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 089448f..3fbbdb8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,6 +6,6 @@ on: jobs: test: name: Unit Tests - uses: ./.github/workflows/terraform-test.yml + uses: equinor/terraform-baseline/.github/workflows/terraform-test.yml@main with: test-filter: tests/unit.tftest.hcl