Skip to content

Commit

Permalink
break out integration tests into a composite action
Browse files Browse the repository at this point in the history
  • Loading branch information
mikealfare committed Nov 22, 2023
1 parent 71a093b commit 3469652
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 68 deletions.
48 changes: 48 additions & 0 deletions .github/actions/run-integration-tests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Run Integration Tests
description: Runs integration tests for a specific version of Python
inputs:
python-version:
description: The version of Python to test against
required: true
dbt-core-branch:
description: The branch of dbt-core to test against
required: false
default: ''
runs:
using: 'composite'
steps:
- name: Set up Python ${{ inputs.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }}
- name: Install dependencies
shell: bash
run: |
python -m pip install --user --upgrade pip
python -m pip install .[test]
- name: Update pyproject.toml
if: inputs.dbt-core-branch != ''
shell: bash
run: |
python -m pip install bumpversion
./.github/scripts/update_dbt_core_branch.sh ${{ inputs.dbt-core-branch }}
python -m pip install --force-reinstall .
- name: Run integration tests
env:
SNOWFLAKE_TEST_ACCOUNT: ${{ secrets.SNOWFLAKE_TEST_ACCOUNT }}
SNOWFLAKE_TEST_PASSWORD: ${{ secrets.SNOWFLAKE_TEST_PASSWORD }}
SNOWFLAKE_TEST_USER: ${{ secrets.SNOWFLAKE_TEST_USER }}
SNOWFLAKE_TEST_WAREHOUSE: ${{ secrets.SNOWFLAKE_TEST_WAREHOUSE }}
SNOWFLAKE_TEST_OAUTH_REFRESH_TOKEN: ${{ secrets.SNOWFLAKE_TEST_OAUTH_REFRESH_TOKEN }}
SNOWFLAKE_TEST_OAUTH_CLIENT_ID: ${{ secrets.SNOWFLAKE_TEST_OAUTH_CLIENT_ID }}
SNOWFLAKE_TEST_OAUTH_CLIENT_SECRET: ${{ secrets.SNOWFLAKE_TEST_OAUTH_CLIENT_SECRET }}
SNOWFLAKE_TEST_ALT_DATABASE: ${{ secrets.SNOWFLAKE_TEST_ALT_DATABASE }}
SNOWFLAKE_TEST_ALT_WAREHOUSE: ${{ secrets.SNOWFLAKE_TEST_ALT_WAREHOUSE }}
SNOWFLAKE_TEST_DATABASE: ${{ secrets.SNOWFLAKE_TEST_DATABASE }}
SNOWFLAKE_TEST_QUOTED_DATABASE: ${{ secrets.SNOWFLAKE_TEST_QUOTED_DATABASE }}
SNOWFLAKE_TEST_ROLE: ${{ secrets.SNOWFLAKE_TEST_ROLE }}
DBT_TEST_USER_1: dbt_test_role_1
DBT_TEST_USER_2: dbt_test_role_2
DBT_TEST_USER_3: dbt_test_role_3
shell: bash
run: python -m pytest tests/functional --ddtrace
84 changes: 16 additions & 68 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ jobs:
console.log(matrix)
return matrix
test:
integration-tests:
name: Integration Tests / Python ${{ matrix.python-version }} / ${{ matrix.os }}

runs-on: ${{ matrix.os }}
needs: test-metadata
# run if not a PR from a forked repository or has a label to mark as safe to test
# also checks that the matrix generated is not empty
if: >-
Expand All @@ -124,10 +125,6 @@ jobs:
contains(github.event.pull_request.labels.*.name, 'ok to test')
)
runs-on: ${{ matrix.os }}

needs: test-metadata

strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.test-metadata.outputs.matrix) }}
Expand All @@ -141,87 +138,38 @@ jobs:
DD_SERVICE: ${{ github.event.repository.name }}

steps:
- name: Check out the repository
if: github.event_name != 'pull_request_target'
uses: actions/checkout@v3
with:
persist-credentials: false

# explicitly checkout the branch for the PR,
# this is necessary for the `pull_request_target` event
- name: Check out the repository (PR)
- uses: actions/checkout@v3
if: github.event_name == 'pull_request_target'
uses: actions/checkout@v3
with:
persist-credentials: false
ref: ${{ github.event.pull_request.head.sha }}

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
- uses: actions/checkout@v3
if: github.event_name != 'pull_request_target'
with:
persist-credentials: false
- uses: ./.github/actions/run-integration-tests
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --user --upgrade pip
python -m pip install .[test]
- name: Update pyproject.toml
if: inputs.dbt-core-branch != ''
run: |
python -m pip install bumpversion
./.github/scripts/update_dbt_core_branch.sh ${{ inputs.dbt-core-branch }}
python -m pip install .[test]
- name: Run integration tests
if: matrix.adapter == 'snowflake'
env:
SNOWFLAKE_TEST_ACCOUNT: ${{ secrets.SNOWFLAKE_TEST_ACCOUNT }}
SNOWFLAKE_TEST_PASSWORD: ${{ secrets.SNOWFLAKE_TEST_PASSWORD }}
SNOWFLAKE_TEST_USER: ${{ secrets.SNOWFLAKE_TEST_USER }}
SNOWFLAKE_TEST_WAREHOUSE: ${{ secrets.SNOWFLAKE_TEST_WAREHOUSE }}
SNOWFLAKE_TEST_OAUTH_REFRESH_TOKEN: ${{ secrets.SNOWFLAKE_TEST_OAUTH_REFRESH_TOKEN }}
SNOWFLAKE_TEST_OAUTH_CLIENT_ID: ${{ secrets.SNOWFLAKE_TEST_OAUTH_CLIENT_ID }}
SNOWFLAKE_TEST_OAUTH_CLIENT_SECRET: ${{ secrets.SNOWFLAKE_TEST_OAUTH_CLIENT_SECRET }}
SNOWFLAKE_TEST_ALT_DATABASE: ${{ secrets.SNOWFLAKE_TEST_ALT_DATABASE }}
SNOWFLAKE_TEST_ALT_WAREHOUSE: ${{ secrets.SNOWFLAKE_TEST_ALT_WAREHOUSE }}
SNOWFLAKE_TEST_DATABASE: ${{ secrets.SNOWFLAKE_TEST_DATABASE }}
SNOWFLAKE_TEST_QUOTED_DATABASE: ${{ secrets.SNOWFLAKE_TEST_QUOTED_DATABASE }}
SNOWFLAKE_TEST_ROLE: ${{ secrets.SNOWFLAKE_TEST_ROLE }}
DBT_TEST_USER_1: dbt_test_role_1
DBT_TEST_USER_2: dbt_test_role_2
DBT_TEST_USER_3: dbt_test_role_3
run: python -m pytest tests/functional --ddtrace

dbt-core-branch: ${{ inputs.dbt-core-branch }}
- uses: ./.github/actions/archive-test-results
with:
python-version: ${{ matrix.python-version }}
file-name-stub: integration_results
- uses: actions/upload-artifact@v3
if: always()
with:
name: logs
path: ./logs

- name: Get current date
if: always()
id: date
run: echo "date=$(date +'%Y-%m-%dT%H_%M_%S')" >> $GITHUB_OUTPUT #no colons allowed for artifacts

- uses: actions/upload-artifact@v3
if: always()
with:
name: integration_results_${{ matrix.python-version }}_${{ matrix.os }}_${{ matrix.adapter }}-${{ steps.date.outputs.date }}.csv
path: test_results.csv

require-label-comment:
runs-on: ubuntu-latest

needs: test

needs: integration-tests
permissions:
pull-requests: write

steps:
- name: Needs permission PR comment
if: >-
needs.test.result == 'skipped' &&
needs.integration-tests.result == 'skipped' &&
github.event_name == 'pull_request_target' &&
github.event.pull_request.head.repo.full_name != github.repository
uses: unsplash/comment-on-pr@master
Expand Down

0 comments on commit 3469652

Please sign in to comment.