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

core -> common testing #54

Merged
merged 43 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
cae6bb4
first pass at testing core +common branches
emmyoop Jan 31, 2024
a196f35
fix vars
emmyoop Jan 31, 2024
25a25f8
check out the right repo
emmyoop Jan 31, 2024
458f9a7
remove extra s
emmyoop Jan 31, 2024
e57823f
rename workflow
emmyoop Jan 31, 2024
b750406
add pull request logic
emmyoop Jan 31, 2024
244f7b1
remove tox dependency
emmyoop Jan 31, 2024
7f26732
add another pip freeze
emmyoop Jan 31, 2024
4af76ca
force reinstall
emmyoop Feb 1, 2024
56ffe72
remove s
emmyoop Feb 1, 2024
630610e
add some debugging
emmyoop Feb 1, 2024
e199d9a
add questions
emmyoop Feb 1, 2024
04cda8e
cat file
emmyoop Feb 1, 2024
056fbc5
remove postgres setup
emmyoop Feb 1, 2024
a85d784
clean up and add comments
emmyoop Feb 1, 2024
4154ff3
conditionally fill refs
emmyoop Feb 1, 2024
fca3c3a
fix event_name
emmyoop Feb 1, 2024
b4a19b1
edit run-name
emmyoop Feb 1, 2024
aa1b9ed
edit run-name
emmyoop Feb 1, 2024
c38887b
cleanup inputs
emmyoop Feb 1, 2024
43ec4a4
remove echos
emmyoop Feb 1, 2024
b63626c
flip conditional
emmyoop Feb 1, 2024
09c7e87
add quotes?
emmyoop Feb 1, 2024
edd5aac
more var tweaks
emmyoop Feb 1, 2024
3acd3c2
add parens?
emmyoop Feb 1, 2024
b87fe4a
add back fucntional tests
emmyoop Feb 1, 2024
e6e8b66
remove typo
emmyoop Feb 1, 2024
cbe2d0a
split out ref resolution
emmyoop Feb 1, 2024
fa3b167
fix pip install
emmyoop Feb 1, 2024
979cec4
add support of skipping tests with label
emmyoop Feb 1, 2024
9359290
basic cleanup
emmyoop Feb 1, 2024
58a3609
fix label logic
emmyoop Feb 1, 2024
4194f31
add some mroe debugging
emmyoop Feb 1, 2024
3d2f461
testing
emmyoop Feb 1, 2024
976575c
testing
emmyoop Feb 1, 2024
315b30d
fix conditional, remove bebugging
emmyoop Feb 1, 2024
3c6ab04
fix job names for clarity
emmyoop Feb 1, 2024
572727b
make titles even more clear
emmyoop Feb 1, 2024
b69cfbd
make testing placeholder for now
emmyoop Feb 5, 2024
b3ee93c
put back commented out testing structure
emmyoop Feb 5, 2024
49a0757
change pip upgrade
emmyoop Feb 5, 2024
5eee730
Merge branch 'main' into er/18-core-testing
emmyoop Feb 5, 2024
bda211e
remove debug statements
emmyoop Feb 6, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ on:
merge_group:
types: [checks_requested]
workflow_dispatch:
workflow_call:

permissions: read-all

Expand Down
276 changes: 263 additions & 13 deletions .github/workflows/ci_dbt_core_testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,302 @@
# Runs all tests in dbt-core with this branch of dbt-common to ensure nothing is broken

# **why?**
# Ensure dbt-common changes do nto break dbt-core
# Ensure dbt-common changes do not break dbt-core

# **when?**
# This will run when trying to merge a PR into main.
# It can also be manually triggered.

## TODO: This is a stub. It does nothing right now.
# It will be updated in the future as part of https://github.com/dbt-labs/dbt-common/issues/18
# This workflow can be skipped by adding the "Skip Core Testing" label to the PR. This is
# useful when making a change in both `dbt-core` and `dbt-common` where the changes are dependant
# and cause the other repository to break.

name: Test Against dbt-core
name: "dbt-core Tests"
run-name: >-
${{ (github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_call')
&& format('dbt-core@{0} with dbt-common@{1}', inputs.dbt-core-ref, inputs.dbt-common-ref)
|| 'dbt-core@main with dbt-common branch' }}

on:
merge_group:
types: [checks_requested]
pull_request:
workflow_dispatch:
inputs:
dbt-core-ref:
description: "The branch of dbt-core to test against"
default: "main"
dbt-common-ref:
description: "The branch of dbt-common to test against"
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

# will cancel previous workflows triggered by the same event
# and for the same ref for PRs/merges or same SHA otherwise
# and for the same inputs on workflow_dispatch or workflow_call
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ contains(fromJson('["pull_request", "merge_group"]'), github.event_name) && github.event.pull_request.head.ref || github.sha }}-${{ contains(fromJson('["workflow_call", "workflow_dispatch"]'), github.event_name) && github.event.inputs.dbt-core-ref && github.event.inputs.dbt-common-ref || github.sha }}
cancel-in-progress: true

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: 5

jobs:
test-dbt-core:
name: "This does nothing right now - always passes"
job-prep:
# This allow us to run the workflow on pull_requests as well so we can always run unit tests
# and only run integration tests on merge for time purposes
name: Setup Repo Refs
runs-on: ubuntu-latest
outputs:
dbt-core-ref: ${{ steps.core-ref.outputs.ref }}
dbt-common-ref: ${{ steps.common-ref.outputs.ref }}

steps:
- name: "Input Refs"
id: job-inputs
run: |
echo "inputs.dbt-core-ref=${{ inputs.dbt-core-ref }}"
echo "inputs.dbt-common-ref=${{ inputs.dbt-common-ref }}"

- name: "Determine dbt-core ref"
id: core-ref
run: |
if [[ -z "${{ inputs.dbt-core-ref }}" ]]; then
REF="main"
else
REF=${{ inputs.dbt-core-ref }}
fi
echo "ref=$REF" >> $GITHUB_OUTPUT

- name: "Determine dbt-common ref"
id: common-ref
run: |
if [[ -z "${{ inputs.dbt-common-ref }}" ]]; then
# these will be commits instead of branches
if [[ "${{ github.event_name }}" == "merge_group" ]]; then
REF=${{ github.event.pull_request.merge_commit_sha }}
else
REF=${{ github.event.pull_request.base.sha }}
fi
else
REF=${{ inputs.dbt-common-ref }}
fi
echo "ref=$REF" >> $GITHUB_OUTPUT

- name: "Final Refs"
run: |
echo "dbt-core-ref=${{ steps.core-ref.outputs.ref }}"
echo "dbt-common-ref=${{ steps.common-ref.outputs.ref }}"

dbt-core-unit-test:
name: "dbt-core unit tests"
needs: [job-prep]

runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- name: "Check out dbt-core"
- name: "Check out dbt-core@${{ needs.job-prep.outputs.dbt-core-ref }}"
uses: actions/checkout@v4
with:
repository: dbt-labs/dbt-core
ref: ${{ needs.job-prep.outputs.dbt-core-ref }}

- name: "Set up Python 3.11"
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: "Update the version of dbt-common"
- name: "Upgrade pip"
run: |
python -m pip install --upgrade pip
python -m pip --version

# tox takes care of installing the correct version of dbt-core dependencies but we need to
# install them first s that we can override the dbt-common branch
- name: "Manually install dbt-core dependencies"
run: |
python -m pip uninstall dbt-common -y
python -m pip install -r dev-requirements.txt -r editable-requirements.txt

# Since the dbt-common dependency is pinned in dev-requirements.txt we need to force update it
# Since tox installs dependencies but doesn't force update, it won't get overridden in the next
# step since the requirements will already be met
- name: "Force update the version of dbt-common@${{ needs.job-prep.outputs.dbt-common-ref }}"
run: |
python -m pip install pip install git+https://github.com/dbt-labs/dbt-common.git@${{ needs.job-prep.outputs.dbt-common-ref }} --force-reinstall

- name: "Run unit tests"
# Doing the check here instead of the top level because this is job a required check, the
# label just means we should skip the tests
if: ${{ !contains(github.event.label.name, 'Skip Core Testing')}}
run: tox
env:
TOXENV: unit

- name: "Check installed versions"
run: pip freeze

dbt-core-integration-metadata:
name: "integration test metadata generation"
runs-on: ubuntu-latest
if: ${{ github.event_name != 'pull_request' && !contains(github.event.label.name, 'Skip Core Testing')}}
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 }}"
if: ${{ github.event_name != 'pull_request' && !contains(github.event.label.name, 'Skip Core Testing')}}

runs-on: ${{ matrix.os }}
timeout-minutes: 30
needs: [job-prep, 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.dbt-core-integration-metadata.outputs.split-groups) }}
include: ${{ fromJson(needs.dbt-core-integration-metadata.outputs.include) }}
env:
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

steps:
- name: "Check out the repository@${{ needs.job-prep.outputs.dbt-core-ref }}"
uses: actions/checkout@v4
with:
repository: dbt-labs/dbt-core
ref: ${{ needs.job-prep.outputs.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: "Upgrade pip"
run: |
python -m pip install --upgrade pip
python -m pip --version

# tox takes care of installing the correct version of dbt-core dependencies but we need to
# install them first s that we can override the dbt-common branch
- name: "Manually install dbt-core dependencies"
run: |
python -m pip install -r dev-requirements.txt -r editable-requirements.txt

# Since the dbt-common dependency is pinned in dev-requirements.txt we need to force update it
# Since tox installs dependencies but doesn't force update, it won't get overridden in the next
# step since the requirements will already be met
- name: "Force update the version of dbt-common@${{ needs.job-prep.outputs.dbt-common-ref }}"
run: |
python -m pip uninstall dbt-common -y
python -m pip install pip install git+https://github.com/dbt-labs/dbt-common.git@${{ needs.job-prep.outputs.dbt-common-ref }} --force-reinstall

- name: "Run Functional tests"
run: tox -- --ddtrace
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 }}
DD_SITE: datadoghq.com
DD_ENV: ci
DD_SERVICE: dbt-core
PYTEST_ADDOPTS: ${{ format('--splits {0} --group {1}', env.PYTHON_INTEGRATION_TEST_WORKERS, matrix.split-group) }}

- name: "Check installed versions"
run: pip freeze

integration-report:
if: ${{ always() }}
name: "dbt-core Integration Test Suite Report"
runs-on: ubuntu-latest
needs: [dbt-core-integration-tests]
steps:
- name: "Integration Tests Failed"
if: ${{ contains(needs.dbt-core-integration-tests.result, 'failure') || contains(needs.dbt-core-integration-tests.result, 'cancelled') }}
# when this is true the next step won't execute
run: |
echo "::notice title='Integration test suite failed'"
exit 1

- name: "Integration Tests Passed"
if: ${{ github.event_name != 'pull_request' }}
run: |
echo "Update the version of dbt-common ref'd in dbt-core"
echo "::notice title='Integration test suite passed'"

- name: "Install dbt-core"
- name: "Integration Tests Skipped on Pull Request"
if: ${{ github.event_name == 'pull_request' && !contains(github.event.label.name, 'Skip Core Testing')}}
run: |
echo "Install dbt-core with updated dbt-common ref"
echo "::notice title='Integration test suite skipped on Pull Requests - they will run on merge'"

- name: "Run Tests"
- name: "Integration Tests Skipped by Label"
if: ${{ contains(github.event.label.name, 'Skip Core Testing')}}
run: |
echo "Running tests in future versions."
echo "::notice title='dbt-core test suite skipped due to Skip Core Testing label'"
1 change: 1 addition & 0 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ on:
merge_group:
types: [checks_requested]
workflow_dispatch:
workflow_call:

permissions: read-all

Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/scheduled_testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# **what?**
# The purpose of this workflow is to trigger CI to run for each
# on a regular cadence. This will also test core + common to prevent breaks.
# If the CI workflow fails, it will post to #dev-core-alerts to raise awareness.

# **why?**
# Ensures dbt-common is always shippable and not broken.
# Also, can catch any dependencies shifting beneath us that might
# introduce breaking changes (could also impact Cloud).

# **when?**
# Mainly on a schedule of 9:00, 13:00, 18:00 UTC everyday.
# Manual trigger can also test on demand

name: Scheduled Testing [ placeholders]

on:
# schedule:
# - cron: '0 9,13,18 * * *' # 9:00, 13:00, 18:00 UTC
workflow_dispatch: # for manual triggering


# no special access is needed
permissions: read-all

jobs:
run_tests:
# uses: dbt-labs/actions/.github/workflows/release-branch-tests.yml@main
# with:
# workflows_to_run: '["ci_tests.yml", "build.yml", "ci_dbt_core_testing.yml"]'
# secrets: inherit
runs-on: ubuntu-latest
steps:

- name: Placeholder
run: echo "This is a placeholder job"
Loading