From ab6e2068c4a7a8c3f38823430fffcc3a1b8c950d Mon Sep 17 00:00:00 2001 From: "Marcel S. Henselin" Date: Thu, 26 Mar 2026 13:36:38 +0100 Subject: [PATCH] chore: modify test action [skip ci] --- .github/actions/acc_test/action.yaml | 83 ++++++---------------------- .github/workflows/tf-acc-test.yaml | 4 +- 2 files changed, 21 insertions(+), 66 deletions(-) diff --git a/.github/actions/acc_test/action.yaml b/.github/actions/acc_test/action.yaml index 800293dc..b9cfb641 100644 --- a/.github/actions/acc_test/action.yaml +++ b/.github/actions/acc_test/action.yaml @@ -65,6 +65,11 @@ inputs: description: "testfile to run" default: '' +outputs: + result: + value: ${{ steps.testrun.result }} + description: "the output of the tests" + runs: using: "composite" steps: @@ -190,8 +195,8 @@ runs: ls -l stackit/"${{ inputs.service_account_json_file_path }}" echo "::endgroup::" - - name: Run acceptance test file - if: ${{ inputs.test_file != '' }} + - name: Run acceptance tests + id: testrun shell: bash run: | echo "::group::go test file" @@ -203,6 +208,8 @@ runs: export TF_LOG fi + testfile="${{ inputs.test_file }}" + echo "Running acceptance tests for the terraform provider" set +e cd stackit || exit 1 @@ -215,13 +222,14 @@ runs: TF_ACC_KEK_KEY_RING_ID=${TF_ACC_KEK_KEY_RING_ID} \ TF_ACC_KEK_KEY_VERSION=${TF_ACC_KEK_KEY_VERSION} \ TF_ACC_KEK_SERVICE_ACCOUNT=${TF_ACC_KEK_SERVICE_ACCOUNT} \ - go test -v ${{ inputs.test_file }} -timeout=${{ inputs.test_timeout_string }} | tee -a acc_test_run.log + go test -v ${testfile} -timeout=${{ inputs.test_timeout_string }} | tee -a acc_test_run.log set -e echo "::endgroup::" echo "::group::go test result" if [ $? -ne 0 ]; then echo "Test failed, see acc_test_run.log for details" - cat acc_test_run.log | grep -v "=== RUN" | grep -v "--- PASS" | grep -v "=== CONT" | grep -v "=== PAUSE" + res=$(cat acc_test_run.log | grep -v "=== RUN" | grep -v "--- PASS" | grep -v "=== CONT" | grep -v "=== PAUSE") + echo "result=${res}" >> "$GITHUB_OUTPUT" exit 1 fi echo "::endgroup::" @@ -234,64 +242,9 @@ runs: TF_ACC_KEK_KEY_VERSION: ${{ inputs.tf_acc_kek_key_version }} TF_ACC_KEK_SERVICE_ACCOUNT: ${{ inputs.tf_acc_kek_service_account }} -# does not work correctly -# - name: Run test action -# if: ${{ inputs.test_file == '' }} -# env: -# TF_ACC: 1 -# TF_ACC_PROJECT_ID: ${{ inputs.project_id }} -# TF_ACC_REGION: ${{ inputs.region }} -# TF_ACC_TEST_PROJECT_USER_EMAIL: ${{ inputs.project_user_email }} -# TF_ACC_KEK_KEY_ID: ${{ inputs.tf_acc_kek_key_id }} -# TF_ACC_KEK_KEY_RING_ID: ${{ inputs.tf_acc_kek_key_ring_id }} -# TF_ACC_KEK_KEY_VERSION: ${{ inputs.tf_acc_kek_key_version }} -# TF_ACC_KEK_SERVICE_ACCOUNT: ${{ inputs.tf_acc_kek_service_account }} -# TF_ACC_SERVICE_ACCOUNT_FILE: ${{ steps.service_account.outputs.safile }} -# uses: robherley/go-test-action@v0 -# with: -# testArguments: "./... -timeout ${{ inputs.test_timeout_string }}" -# moduleDirectory: "stackit" - - - name: Run all acceptance tests - if: ${{ inputs.test_file == '' }} - shell: bash - run: | - echo "::group::go test all" - set -e - set -o pipefail - - if [[ "${{ inputs.tf_debug }}" == "true" ]]; then - TF_LOG=INFO - export TF_LOG - fi - - echo "Running acceptance tests for the terraform provider" - cd stackit || exit 1 - set +e - TF_ACC=1 \ - TF_ACC_PROJECT_ID=${TF_ACC_PROJECT_ID} \ - TF_ACC_REGION=${TF_ACC_REGION} \ - TF_ACC_TEST_PROJECT_USER_EMAIL=${TF_ACC_TEST_PROJECT_USER_EMAIL} \ - TF_ACC_SERVICE_ACCOUNT_FILE="${PWD}/${{ inputs.service_account_json_file_path }}" \ - TF_ACC_KEK_KEY_ID=${TF_ACC_KEK_KEY_ID} \ - TF_ACC_KEK_KEY_RING_ID=${TF_ACC_KEK_KEY_RING_ID} \ - TF_ACC_KEK_KEY_VERSION=${TF_ACC_KEK_KEY_VERSION} \ - TF_ACC_KEK_SERVICE_ACCOUNT=${TF_ACC_KEK_SERVICE_ACCOUNT} \ - go test -v ./... -timeout=${{ inputs.test_timeout_string }} | tee -a acc_test_run.log - set -e - echo "::endgroup::" - echo "::group::go test result" - if [ $? -ne 0 ]; then - echo "Test failed, see acc_test_run.log for details" - cat acc_test_run.log | grep -v "=== RUN" | grep -v "--- PASS" | grep -v "=== CONT" | grep -v "=== PAUSE" - exit 1 - fi - echo "::endgroup::" - env: - TF_ACC_PROJECT_ID: ${{ inputs.project_id }} - TF_ACC_REGION: ${{ inputs.region }} - TF_ACC_TEST_PROJECT_USER_EMAIL: ${{ inputs.project_user_email }} - TF_ACC_KEK_KEY_ID: ${{ inputs.tf_acc_kek_key_id }} - TF_ACC_KEK_KEY_RING_ID: ${{ inputs.tf_acc_kek_key_ring_id }} - TF_ACC_KEK_KEY_VERSION: ${{ inputs.tf_acc_kek_key_version }} - TF_ACC_KEK_SERVICE_ACCOUNT: ${{ inputs.tf_acc_kek_service_account }} + - name: Upload test log artifact + if: always() + uses: actions/upload-artifact@v4 + with: + name: acc_test.log + path: "stackit/acc_test_run.log" diff --git a/.github/workflows/tf-acc-test.yaml b/.github/workflows/tf-acc-test.yaml index 85c78437..e6a2194e 100644 --- a/.github/workflows/tf-acc-test.yaml +++ b/.github/workflows/tf-acc-test.yaml @@ -43,6 +43,7 @@ jobs: - name: Run Test (workflow dispatch) if: ${{ github.event_name == 'workflow_dispatch' }} + id: manual_run uses: ./.github/actions/acc_test with: go-version: ${{ env.GO_VERSION }} @@ -59,6 +60,7 @@ jobs: - name: Run Test (automatic) if: ${{ github.event_name != 'workflow_dispatch' }} + id: automatic_run uses: ./.github/actions/acc_test with: go-version: ${{ env.GO_VERSION }} @@ -78,6 +80,6 @@ jobs: title: Terraform Acceptance Tests finished event_title: ${{ github.event.type }} event_author: ${{ github.event.actor.login }} - event_body: 'No event body.' + event_body: "${{ steps.automatic_run.outputs.result || steps.manual_run.outputs.result }}" event_number: ${{ github.event.id }} event_url: "https://tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/actions/runs/${{ github.run_id }}"