Skip to content

Commit fb0ebb8

Browse files
committed
Adds backend tests to github actions
We're using github actions so we can conditionally skip it.
1 parent 2644ecc commit fb0ebb8

File tree

5 files changed

+106
-5
lines changed

5 files changed

+106
-5
lines changed
+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: Backend Test Workflow
2+
3+
on:
4+
push:
5+
branches:
6+
- main # or any specific branches you want to include
7+
pull_request:
8+
branches:
9+
- main
10+
11+
12+
jobs:
13+
check-changes:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
changes: ${{ steps.filter.outputs.changes }}
17+
steps:
18+
- uses: actions/checkout@v3
19+
with:
20+
fetch-depth: 2 # fetch previous commit for comparison
21+
- id: filter
22+
run: |
23+
echo "Checking for changes in the backend directory and branch..."
24+
# Check if the current branch is not main
25+
if [[ "${{ github.ref }}" != "refs/heads/main" ]]; then
26+
# Check for changes in the backend directory
27+
if git diff --quiet HEAD^ HEAD -- ui/backend/; then
28+
echo "::set-output name=skip::true"
29+
echo "No changes in backend/ or not on main branch, skipping subsequent jobs."
30+
else
31+
echo "::set-output name=skip::false"
32+
echo "Changes detected in backend/ and not on main branch."
33+
fi
34+
else
35+
echo "::set-output name=skip::false"
36+
echo "On main branch, proceeding with subsequent jobs."
37+
fi
38+
test-backend:
39+
needs: check-changes
40+
runs-on: ubuntu-latest
41+
strategy:
42+
matrix:
43+
testdir: [test_lifecycle, test_db_methods] # Specify your test directories
44+
services:
45+
postgres:
46+
image: postgres:14
47+
env:
48+
POSTGRES_USER: postgres
49+
POSTGRES_DB: circleci_test
50+
POSTGRES_HOST_AUTH_METHOD: trust
51+
ports:
52+
- 5432:5432
53+
options: >-
54+
--health-cmd pg_isready
55+
--health-interval 10s
56+
--health-timeout 100s
57+
--health-retries 10
58+
steps:
59+
- uses: actions/checkout@v3
60+
- name: Set up Python
61+
uses: actions/setup-python@v4
62+
with:
63+
python-version: '3.9'
64+
- name: Install dependencies
65+
run: |
66+
cd ui/backend/server
67+
pip install -r requirements-base.txt
68+
pip install -r requirements-test.txt
69+
- name: Run migrations
70+
env:
71+
DB_HOST: localhost
72+
DB_USER: postgres
73+
DB_PASSWORD: "postgres"
74+
DB_NAME: ${{ matrix.testdir }}
75+
DB_PORT: 5432
76+
HAMILTON_ENV: integration_tests
77+
DJANGO_SECRET_KEY: test
78+
PGPASSWORD: postgres
79+
PGHOST: localhost
80+
PGUSER: postgres
81+
HAMILTON_BLOB_STORE: local
82+
HAMILTON_LOCAL_BLOB_DIR: ./blob_data
83+
run: |
84+
cd ui/backend/server
85+
python manage.py sqlcreate
86+
echo $(python manage.py sqlcreate) | psql -U postgres
87+
python manage.py migrate
88+
- name: Run tests
89+
env:
90+
DB_HOST: localhost
91+
DB_USER: postgres
92+
DB_PASSWORD: "postgres"
93+
DB_NAME: ${{ matrix.testdir }}
94+
DB_PORT: 5432
95+
HAMILTON_ENV: integration_tests
96+
DJANGO_SECRET_KEY: test
97+
PGPASSWORD: postgres
98+
PGHOST: localhost
99+
PGUSER: postgres
100+
HAMILTON_BLOB_STORE: local
101+
HAMILTON_LOCAL_BLOB_DIR: ./blob_data
102+
run: |
103+
cd ui/backend/server
104+
python -m pytest tests/${{ matrix.testdir }} -vvvvv

ui/backend/server/server/settings.py

-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ def get_from_env(
3030

3131
HAMILTON_ENV = get_from_env("HAMILTON_ENV", ["integration_tests", "local", "dev", "prod"])
3232

33-
AUTH_PROVIDER = get_from_env("HAMILTON_AUTH_PROVIDER", ["propel", "local"])
34-
3533
PROPEL_AUTH_API_KEY = get_from_env("PROPEL_AUTH_API_KEY", allow_missing=True)
3634
PROPEL_AUTH_URL = get_from_env("PROPEL_AUTH_URL", allow_missing=True)
3735

ui/backend/server/trackingserver_base/apps.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import uuid
33

44
from django.apps import AppConfig
5+
from django.conf import settings
56

67
from hamilton.telemetry import API_KEY, BASE_PROPERTIES, is_telemetry_enabled, send_event_json
78

@@ -28,7 +29,7 @@ class TrackingServerConfig(AppConfig):
2829
name = "trackingserver_base"
2930

3031
def ready(self):
31-
if is_telemetry_enabled():
32+
if is_telemetry_enabled() and settings.HAMILTON_ENV in ["local"]:
3233
if not os.path.exists("/data/telemetry.txt"):
3334
telemetry_key = str(uuid.uuid4())
3435
with open("/data/telemetry.txt", "w") as f:

ui/deployment/docker-compose-prod.yml

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ services:
3232
- DB_PASSWORD=password # TODO: Change this to a secret
3333
- HAMILTON_BLOB_STORE=local
3434
- HAMILTON_ENV=local # local env
35-
- HAMILTON_AUTH_PROVIDER=local # local authentication means unauthenticated -- TODO: enable auth for prod
3635
- HAMILTON_LOCAL_BLOB_DIR=/data/blobs # TODO -- set this up to be a better one
3736
- DJANGO_SECRET_KEY=do_not_use_in_production
3837
- HAMILTON_TELEMETRY_ENABLED=${HAMILTON_TELEMETRY_ENABLED-true}

ui/deployment/docker-compose.yml

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ services:
3434
- DB_PASSWORD=password # Purely for local! Do not deploy to production!
3535
- HAMILTON_BLOB_STORE=local
3636
- HAMILTON_ENV=local # local env
37-
- HAMILTON_AUTH_PROVIDER=local # local authentication means unauthenticated -- do not use in production!!
3837
- HAMILTON_LOCAL_BLOB_DIR=/data/blobs # TODO -- set this up to be a better one
3938
- DJANGO_SECRET_KEY=do_not_use_in_production
4039
- HAMILTON_TELEMETRY_ENABLED=${HAMILTON_TELEMETRY_ENABLED}

0 commit comments

Comments
 (0)