Skip to content

Commit

Permalink
Update integration workflow (#13)
Browse files Browse the repository at this point in the history
* Update integration workflow

* New dispatch logic to fix unit test
  • Loading branch information
jtcohen6 authored Oct 11, 2021
1 parent 465a268 commit 5c26ce7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 57 deletions.
52 changes: 22 additions & 30 deletions .github/scripts/integration-test-matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,39 @@ module.exports = ({ context }) => {
// `changes` is a list of adapter names that have related
// file changes in the PR
// ex: ['postgres', 'snowflake']
const changes = JSON.parse(process.env.CHANGES);
const labels = context.payload.pull_request.labels.map(({ name }) => name);
console.log("labels", labels);
console.log("changes", changes);
const testAllLabel = labels.includes("test all");
const include = [];

for (const adapter of supportedAdapters) {
if (
changes.includes(adapter) ||
testAllLabel ||
labels.includes(`test ${adapter}`)
) {
for (const pythonVersion of supportedPythonVersions) {
if (
pythonVersion === defaultPythonVersion ||
labels.includes(`test python${pythonVersion}`) ||
testAllLabel
) {
// always run tests on ubuntu by default
for (const pythonVersion of supportedPythonVersions) {
if (
pythonVersion === defaultPythonVersion ||
labels.includes(`test python${pythonVersion}`) ||
testAllLabel
) {
// always run tests on ubuntu by default
include.push({
os: "ubuntu-latest",
adapter,
"python-version": pythonVersion,
});

if (labels.includes("test windows") || testAllLabel) {
include.push({
os: "ubuntu-latest",
os: "windows-latest",
adapter,
"python-version": pythonVersion,
});
}

if (labels.includes("test windows") || testAllLabel) {
include.push({
os: "windows-latest",
adapter,
"python-version": pythonVersion,
});
}

if (labels.includes("test macos") || testAllLabel) {
include.push({
os: "macos-latest",
adapter,
"python-version": pythonVersion,
});
}
if (labels.includes("test macos") || testAllLabel) {
include.push({
os: "macos-latest",
adapter,
"python-version": pythonVersion,
});
}
}
}
Expand Down
18 changes: 3 additions & 15 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ on:
pull_request_target:
# manual trigger
workflow_dispatch:
# run this once per night to ensure no regressions from latest dbt-core changes
schedule:
- cron: '0 5 * * *' # 5 UTC

# explicitly turn off permissions for `GITHUB_TOKEN`
permissions: read-all
Expand Down Expand Up @@ -74,21 +77,6 @@ jobs:
persist-credentials: false
ref: ${{ github.event.pull_request.head.sha }}

- name: Check if relevant files changed
# https://github.com/marketplace/actions/paths-changes-filter
# For each filter, it sets output variable named by the filter to the text:
# 'true' - if any of changed files matches any of filter rules
# 'false' - if none of changed files matches any of filter rules
# also, returns:
# `changes` - JSON array with names of all filters matching any of the changed files
uses: dorny/paths-filter@v2
id: get-changes
with:
token: ${{ secrets.GITHUB_TOKEN }}
filters: |
redshift:
- 'dbt/**'
- 'tests/**'
- name: Generate integration test matrix
id: generate-matrix
uses: actions/github-script@v4
Expand Down
6 changes: 3 additions & 3 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# install latest changes in dbt-core + dbt-postgres
# TODO: how to automate switching from develop to version branches?
git+https://github.com/dbt-labs/dbt.git@develop#egg=dbt-core&subdirectory=core
git+https://github.com/dbt-labs/dbt.git@develop#egg=dbt-postgres&subdirectory=plugins/postgres
# TODO: how to switch from HEAD to x.y.latest branches after minor releases?
git+https://github.com/dbt-labs/dbt.git#egg=dbt-core&subdirectory=core
git+https://github.com/dbt-labs/dbt.git#egg=dbt-postgres&subdirectory=plugins/postgres

bumpversion
flake8
Expand Down
22 changes: 13 additions & 9 deletions tests/unit/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,16 +446,20 @@ def test_resolve_specific(config, manifest_extended, redshift_adapter, get_inclu
manifest=manifest_extended,
)

ctx['adapter'].config.dispatch

# macro_a exists, but default__macro_a and redshift__macro_a do not
with pytest.raises(dbt.exceptions.CompilationException):
ctx['adapter'].dispatch('macro_a').macro

assert ctx['adapter'].dispatch('some_macro').macro is package_rs_macro
assert ctx['adapter'].dispatch('some_macro', packages=[
'dbt']).macro is rs_macro
assert ctx['adapter'].dispatch('some_macro', packages=[
'root']).macro is package_rs_macro
assert ctx['adapter'].dispatch('some_macro', packages=[
'root', 'dbt']).macro is package_rs_macro
assert ctx['adapter'].dispatch('some_macro', packages=[
'dbt', 'root']).macro is rs_macro
assert ctx['adapter'].dispatch('some_macro', 'dbt').macro is rs_macro
assert ctx['adapter'].dispatch('some_macro', 'root').macro is package_rs_macro

# override 'dbt' namespace, dispatch to 'root' first
ctx['adapter'].config.dispatch = [{'macro_namespace': 'dbt', 'search_order': ['root', 'dbt']}]
assert ctx['adapter'].dispatch('some_macro', macro_namespace = 'dbt').macro is package_rs_macro

# override 'root' namespace, dispatch to 'dbt' first
ctx['adapter'].config.dispatch = [{'macro_namespace': 'root', 'search_order': ['dbt', 'root']}]
assert ctx['adapter'].dispatch('some_macro', macro_namespace='root').macro is rs_macro

0 comments on commit 5c26ce7

Please sign in to comment.