Skip to content

Commit f43277b

Browse files
GitHub workflow on pr (Velir#93)
* started testing workflow * working local version of unit tests * fixing working directory * adding manual execution * fixing keyfile location
1 parent 6efa9d5 commit f43277b

18 files changed

+71
-22
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Run Unit Tests on Pull Request
2+
3+
on: [pull_request,workflow_dispatch]
4+
env:
5+
BIGQUERY_PROJECT: ${{ secrets.BIGQUERY_PROJECT }}
6+
KEYFILE_LOCATION: /dbt-service-account.json
7+
8+
jobs:
9+
pytest_run_all:
10+
name: Pytest Run All
11+
runs-on: ubuntu-latest
12+
defaults:
13+
run:
14+
working-directory: ./unit_tests
15+
steps:
16+
- name: Check out
17+
uses: actions/checkout@v3
18+
with:
19+
ref: ${{ github.event.pull_request.head.sha }}
20+
21+
- uses: actions/setup-python@v1
22+
with:
23+
python-version: "3.7.x"
24+
25+
- name: Authenticate using service account
26+
run: 'echo "$KEYFILE" > ./dbt-service-account.json'
27+
shell: bash
28+
env:
29+
KEYFILE: ${{secrets.GCP_BIGQUERY_USER_KEYFILE}}
30+
31+
- name: Install dependencies
32+
run: |
33+
pip install dbt-core
34+
pip install dbt-bigquery
35+
pip install pytest
36+
37+
- name: Run tests
38+
run: python -m pytest .

.gitignore

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
target/
33
dbt_packages/
44
logs/
5-
google-cloud-sdk/
6-
integration_tests/.env
7-
integration_tests/__pycache__
8-
integration_tests/.pytest_cache
95

6+
google-cloud-sdk/
7+
unit_tests/.env
8+
unit_tests/__pycache__
9+
unit_tests/.pytest_cache
10+
unit_tests/dbt-service-account.json
1011

1112
# Byte-compiled / optimized / DLL files
1213
__pycache__/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# GA4 DBT Package
1+
# GA4 DBT Package
22

33
This package connects to an exported GA4 dataset and provides useful transformations as well as report-ready dimensional models that can be used to build reports or blend GA4 data with exported GA3 data.
44

integration_tests/conftest.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

unit_tests/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
BIGQUERY_PROJECT=
File renamed without changes.

unit_tests/conftest.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import pytest
2+
import os
3+
4+
# Import the standard functional fixtures as a plugin
5+
pytest_plugins = ["dbt.tests.fixtures.project"]
6+
7+
# The profile dictionary, used to write out profiles.yml
8+
@pytest.fixture(scope="class")
9+
def dbt_profile_target():
10+
# Set project and keyfile for github automated tests
11+
if os.environ.get('GITHUB_ACTIONS') is not None:
12+
return {
13+
'type': 'bigquery',
14+
'method': 'service-account',
15+
'keyfile': os.getcwd() + os.environ.get("KEYFILE_LOCATION"),
16+
'threads': 4,
17+
'timeout_seconds': 300,
18+
'project': os.environ.get("BIGQUERY_PROJECT")
19+
}
20+
return {
21+
'type': 'bigquery',
22+
'method': 'oauth',
23+
'threads': 4,
24+
'project': os.environ.get("BIGQUERY_PROJECT")
25+
}
File renamed without changes.

0 commit comments

Comments
 (0)