diff --git a/.github/workflows/lth.yml b/.github/workflows/lth.yml index 342f39f4..8b37fb38 100644 --- a/.github/workflows/lth.yml +++ b/.github/workflows/lth.yml @@ -1,11 +1,16 @@ name: Liquibase Test Harness - on: + workflow_dispatch: pull_request: push: branches: - main +# static value to the workflow group to ensure only one run of the workflow can be in progress at a time. +concurrency: + group: liquibase-test-harness + cancel-in-progress: false + jobs: liquibase-test-harness: name: Liquibase Test Harness @@ -72,4 +77,16 @@ jobs: - name: Stop test database if: always() # Always destroy, even if the previous steps fail working-directory: src/test/terraform - run: terraform destroy -auto-approve + run: | + set -e + TERRAFORM_OUTPUT=$(terraform show -json) + if [ -z "$TERRAFORM_OUTPUT" ]; then + echo "Terraform output is empty. Skipping removal." + else + SCHEMA_EXISTS=$(echo $TERRAFORM_OUTPUT | jq -r '.values.root_module.resources[] | select(.address == "databricks_schema.test_harness") | .values.name') + if [ "$SCHEMA_EXISTS" == "liquibase_harness_test_ds" ]; then + terraform destroy -auto-approve + else + echo "Schema does not exist. Skipping removal." + fi + fi \ No newline at end of file