From a5c861b78cbec08311c4e7fe69ed4b1645d62c56 Mon Sep 17 00:00:00 2001 From: Emily Rockman Date: Wed, 31 Jan 2024 13:28:58 -0600 Subject: [PATCH] first pass at testing core +common branches --- .github/workflows/ci_dbt_core_testing.yml | 169 +++++++++++++++++++++- 1 file changed, 162 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci_dbt_core_testing.yml b/.github/workflows/ci_dbt_core_testing.yml index 5ee8fb31..88127075 100644 --- a/.github/workflows/ci_dbt_core_testing.yml +++ b/.github/workflows/ci_dbt_core_testing.yml @@ -17,6 +17,27 @@ on: merge_group: types: [checks_requested] workflow_dispatch: + inputs: + dbt-core-ref: + description: "The branch of dbt-core to test against" + required: true + default: "main" + dbt-common-ref: + description: "The branch of dbt-common to test against" + required: true + default: "main" + workflow_call: + inputs: + dbt-core-ref: + description: "The branch of dbt-core to test against" + type: string + required: true + default: "main" + dbt-common-ref: + description: "The branch of dbt-common to test against" + type: string + required: true + default: "main" permissions: read-all @@ -24,9 +45,15 @@ defaults: run: shell: bash +# top-level adjustments can be made here +env: + # number of parallel processes to spawn for python integration testing + PYTHON_INTEGRATION_TEST_WORKERS: 5s + jobs: - test-dbt-core: - name: "This does nothing right now - always passes" + # TODO: maybe split these into 2 workflows. Then we can call unit tests always and just do int tests on merge? or just use an trigger checks + dbt-core-unit-test: + name: "Run unit tests for dbt-core" runs-on: ubuntu-latest timeout-minutes: 10 @@ -34,20 +61,148 @@ jobs: steps: - name: "Check out dbt-core" uses: actions/checkout@v4 + with: + ref: ${{ github.event.inputs.dbt-core-ref }} - name: "Set up Python 3.11" uses: actions/setup-python@v5 with: python-version: "3.11" + - name: Install python dependencies + run: | + python -m pip install --user --upgrade pip + python -m pip --version + python -m pip install tox + tox --version + + - name: "Update the version of dbt-common" + run: | + pip install pip install git+https://github.com/dbt-labs/dbt-common.git@${{ inputs.dbt-common-ref }} + + - name: "Check installed versions" + run: pip freeze + + - name: Run tox - unit tests + env: + TOXENV: "unit" + run: tox + + dbt-core-integration-metadata: + name: integration test metadata generation + runs-on: ubuntu-latest + outputs: + split-groups: ${{ steps.generate-split-groups.outputs.split-groups }} + include: ${{ steps.generate-include.outputs.include }} + + steps: + - name: generate split-groups + id: generate-split-groups + run: | + MATRIX_JSON="[" + for B in $(seq 1 ${{ env.PYTHON_INTEGRATION_TEST_WORKERS }}); do + MATRIX_JSON+=$(sed 's/^/"/;s/$/"/' <<< "${B}") + done + MATRIX_JSON="${MATRIX_JSON//\"\"/\", \"}" + MATRIX_JSON+="]" + echo "split-groups=${MATRIX_JSON}" + echo "split-groups=${MATRIX_JSON}" >> $GITHUB_OUTPUT + + - name: generate include + id: generate-include + run: | + INCLUDE=('"python-version":"3.8","os":"windows-latest"' '"python-version":"3.8","os":"macos-latest"' ) + INCLUDE_GROUPS="[" + for include in ${INCLUDE[@]}; do + for group in $(seq 1 ${{ env.PYTHON_INTEGRATION_TEST_WORKERS }}); do + INCLUDE_GROUPS+=$(sed 's/$/, /' <<< "{\"split-group\":\"${group}\",${include}}") + done + done + INCLUDE_GROUPS=$(echo $INCLUDE_GROUPS | sed 's/,*$//g') + INCLUDE_GROUPS+="]" + echo "include=${INCLUDE_GROUPS}" + echo "include=${INCLUDE_GROUPS}" >> $GITHUB_OUTPUT + + dbt-core-integration-tests: + name: (${{ matrix.split-group }}) integration test / python ${{ matrix.python-version }} / ${{ matrix.os }} + + runs-on: ${{ matrix.os }} + timeout-minutes: 30 + needs: [dbt-core-integration-metadata] + strategy: + fail-fast: false + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11"] + os: [ubuntu-20.04] + split-group: ${{ fromJson(needs.integration-metadata.outputs.split-groups) }} + include: ${{ fromJson(needs.integration-metadata.outputs.include) }} + env: + TOXENV: integration + DBT_INVOCATION_ENV: github-actions + DBT_TEST_USER_1: dbt_test_user_1 + DBT_TEST_USER_2: dbt_test_user_2 + DBT_TEST_USER_3: dbt_test_user_3 + # DD_CIVISIBILITY_AGENTLESS_ENABLED: true + # DD_API_KEY: ${{ secrets.DATADOG_API_KEY }} TODO: set this up + # DD_SITE: datadoghq.com + # DD_ENV: ci + DD_SERVICE: ${{ github.event.repository.name }} + + steps: + - name: Check out the repository + uses: actions/checkout@v4 + with: + ref: ${{ github.event.inputs.dbt-core-ref }} + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Set up postgres (linux) + if: runner.os == 'Linux' + uses: ./.github/actions/setup-postgres-linux + + - name: Set up postgres (macos) + if: runner.os == 'macOS' + uses: ./.github/actions/setup-postgres-macos + + - name: Set up postgres (windows) + if: runner.os == 'Windows' + uses: ./.github/actions/setup-postgres-windows + + - name: Install python tools + run: | + python -m pip install --user --upgrade pip + python -m pip --version + python -m pip install tox + tox --version + - name: "Update the version of dbt-common" run: | - echo "Update the version of dbt-common ref'd in dbt-core" + pip install pip install git+https://github.com/dbt-labs/dbt-common.git@${{ inputs.dbt-common-ref }} - - name: "Install dbt-core" + - name: "Check installed versions" + run: pip freeze + + - name: Run tests + run: tox -- --ddtrace + env: + PYTEST_ADDOPTS: ${{ format('--splits {0} --group {1}', env.PYTHON_INTEGRATION_TEST_WORKERS, matrix.split-group) }} + + integration-report: + if: ${{ always() }} + name: Integration Test Suite + runs-on: ubuntu-latest + needs: [dbt-core-integration-tests] + steps: + - name: "Integration Tests Failed" + if: ${{ contains(needs.integration.result, 'failure') || contains(needs.integration.result, 'cancelled') }} + # when this is true the next step won't execute run: | - echo "Install dbt-core with updated dbt-common ref" + echo "::notice title='Integration test suite failed'" + exit 1 - - name: "Run Tests" + - name: "Integration Tests Passed" run: | - echo "Running tests in future versions." + echo "::notice title='Integration test suite passed'"