Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DAT-19348 DevOps :: refactor databricks test-harness workflow to run terraform once #244

Merged
merged 5 commits into from
Feb 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 53 additions & 26 deletions .github/workflows/lth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ concurrency:
cancel-in-progress: false

jobs:
liquibase-test-harness:
name: Liquibase Test Harness
start-test-harness-infra:
name: Start Liquibase Test Harness infra
runs-on: ubuntu-22.04
permissions:
checks: write
Expand All @@ -24,14 +24,8 @@ jobs:
TF_VAR_DBX_TOKEN: ${{ secrets.TH_DATABRICKS_WORKSPACE_TOKEN }}
TF_VAR_TEST_CATALOG: main
TF_VAR_TEST_SCHEMA: liquibase_harness_test_ds
WORKSPACE_ID: ${{ secrets.TH_DATABRICKS_WORKSPACE_ID }}
LIQUIBOT_TOKEN: ${{ secrets.LIQUIBOT_PAT }}
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
strategy:
max-parallel: 1
matrix:
liquibase-support-level: [Foundational, Contributed, Advanced] # Define the different test levels to run
fail-fast: false # Set fail-fast to false to run all test levels even if some of them fail
outputs:
DATABRICKS_URL: ${{ steps.collect-databricks-config.outputs.DATABRICKS_URL }}

steps:
- name: Checkout code
Expand All @@ -50,11 +44,35 @@ jobs:
working-directory: src/test/terraform

- name: Collect Databricks Config
id: collect-databricks-config
working-directory: src/test/terraform
run: |
CLUSTER_ID=$(terraform output -raw endpoint_url)
DATABRICKS_HOST=${TF_VAR_DBX_HOST#https://}
echo "DATABRICKS_URL=jdbc:databricks://$DATABRICKS_HOST:443/default;transportMode=http;ssl=1;httpPath=/sql/1.0/warehouses/$CLUSTER_ID;AuthMech=3;ConnCatalog=$TF_VAR_TEST_CATALOG;ConnSchema=$TF_VAR_TEST_SCHEMA;EnableArrow=0" >> "$GITHUB_ENV"
echo "DATABRICKS_URL=jdbc:databricks://$DATABRICKS_HOST:443/default;transportMode=http;ssl=1;httpPath=/sql/1.0/warehouses/$CLUSTER_ID;AuthMech=3;ConnCatalog=$TF_VAR_TEST_CATALOG;ConnSchema=$TF_VAR_TEST_SCHEMA;EnableArrow=0" >> $GITHUB_OUTPUT

liquibase-test-harness:
name: Liquibase Test Harness
runs-on: ubuntu-22.04
needs: start-test-harness-infra
permissions:
checks: write
pull-requests: write
contents: write
env:
WORKSPACE_ID: ${{ secrets.TH_DATABRICKS_WORKSPACE_ID }}
LIQUIBOT_TOKEN: ${{ secrets.LIQUIBOT_PAT }}
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
TF_VAR_DBX_TOKEN: ${{ secrets.TH_DATABRICKS_WORKSPACE_TOKEN }}
strategy:
max-parallel: 1
matrix:
liquibase-support-level: [Foundational, Contributed, Advanced] # Define the different test levels to run
fail-fast: false # Set fail-fast to false to run all test levels even if some of them fail

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Temurin Java 17
uses: actions/setup-java@v4
Expand Down Expand Up @@ -110,7 +128,7 @@ jobs:

- name: Run ${{ matrix.liquibase-support-level }} Liquibase Test Harness # Run the Liquibase test harness at each test level
if: always() # Run the action even if the previous steps fail
run: mvn -B -ntp -DdbPassword=${{env.TF_VAR_DBX_TOKEN}} -DdbUrl='${{env.DATABRICKS_URL}}' -Dtest=liquibase.ext.databricks.${{ matrix.liquibase-support-level }}ExtensionHarnessTestSuite test -Dliquibase.version=master-SNAPSHOT # Run the Liquibase test harness at each test level
run: mvn -B -ntp -DdbPassword=${{env.TF_VAR_DBX_TOKEN}} -DdbUrl='${{needs.start-test-harness-infra.outputs.DATABRICKS_URL}}' -Dtest=liquibase.ext.databricks.${{ matrix.liquibase-support-level }}ExtensionHarnessTestSuite test -Dliquibase.version=master-SNAPSHOT # Run the Liquibase test harness at each test level

- name: Test Reporter # Generate a test report using the Test Reporter action
uses: dorny/[email protected]
Expand All @@ -121,19 +139,28 @@ jobs:
reporter: java-junit # Set the reporter to use
fail-on-error: false # Set fail-on-error to false to show report even if it has failed tests

stop-test-harness-infra:
name: Stop Liquibase Test Harness infra
needs: [liquibase-test-harness]
if: always() # Always destroy, even if the previous steps fail
runs-on: ubuntu-22.04
permissions:
checks: write
pull-requests: write
contents: write
env:
TF_VAR_DBX_HOST: ${{ secrets.TH_DATABRICKS_WORKSPACE_HOST }}
TF_VAR_DBX_TOKEN: ${{ secrets.TH_DATABRICKS_WORKSPACE_TOKEN }}
TF_VAR_TEST_CATALOG: main
TF_VAR_TEST_SCHEMA: liquibase_harness_test_ds

steps:
- name: Checkout code
uses: actions/checkout@v4

- run: terraform init
working-directory: src/test/terraform

- name: Stop test database
if: always() # Always destroy, even if the previous steps fail
working-directory: src/test/terraform
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
run: terraform destroy -auto-approve
Loading