Skip to content

Commit

Permalink
Adds backend tests to github actions
Browse files Browse the repository at this point in the history
We're using github actions so we can conditionally skip it.
  • Loading branch information
elijahbenizzy committed Apr 23, 2024
1 parent 2644ecc commit fb0ebb8
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 5 deletions.
104 changes: 104 additions & 0 deletions .github/workflows/hamilton-ui-backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Backend Test Workflow

on:
push:
branches:
- main # or any specific branches you want to include
pull_request:
branches:
- main


jobs:
check-changes:
runs-on: ubuntu-latest
outputs:
changes: ${{ steps.filter.outputs.changes }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2 # fetch previous commit for comparison
- id: filter
run: |
echo "Checking for changes in the backend directory and branch..."
# Check if the current branch is not main
if [[ "${{ github.ref }}" != "refs/heads/main" ]]; then
# Check for changes in the backend directory
if git diff --quiet HEAD^ HEAD -- ui/backend/; then
echo "::set-output name=skip::true"
echo "No changes in backend/ or not on main branch, skipping subsequent jobs."
else
echo "::set-output name=skip::false"
echo "Changes detected in backend/ and not on main branch."
fi
else
echo "::set-output name=skip::false"
echo "On main branch, proceeding with subsequent jobs."
fi
test-backend:
needs: check-changes
runs-on: ubuntu-latest
strategy:
matrix:
testdir: [test_lifecycle, test_db_methods] # Specify your test directories
services:
postgres:
image: postgres:14
env:
POSTGRES_USER: postgres
POSTGRES_DB: circleci_test
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 100s
--health-retries 10
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: |
cd ui/backend/server
pip install -r requirements-base.txt
pip install -r requirements-test.txt
- name: Run migrations
env:
DB_HOST: localhost
DB_USER: postgres
DB_PASSWORD: "postgres"
DB_NAME: ${{ matrix.testdir }}
DB_PORT: 5432
HAMILTON_ENV: integration_tests
DJANGO_SECRET_KEY: test
PGPASSWORD: postgres
PGHOST: localhost
PGUSER: postgres
HAMILTON_BLOB_STORE: local
HAMILTON_LOCAL_BLOB_DIR: ./blob_data
run: |
cd ui/backend/server
python manage.py sqlcreate
echo $(python manage.py sqlcreate) | psql -U postgres
python manage.py migrate
- name: Run tests
env:
DB_HOST: localhost
DB_USER: postgres
DB_PASSWORD: "postgres"
DB_NAME: ${{ matrix.testdir }}
DB_PORT: 5432
HAMILTON_ENV: integration_tests
DJANGO_SECRET_KEY: test
PGPASSWORD: postgres
PGHOST: localhost
PGUSER: postgres
HAMILTON_BLOB_STORE: local
HAMILTON_LOCAL_BLOB_DIR: ./blob_data
run: |
cd ui/backend/server
python -m pytest tests/${{ matrix.testdir }} -vvvvv
2 changes: 0 additions & 2 deletions ui/backend/server/server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ def get_from_env(

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

AUTH_PROVIDER = get_from_env("HAMILTON_AUTH_PROVIDER", ["propel", "local"])

PROPEL_AUTH_API_KEY = get_from_env("PROPEL_AUTH_API_KEY", allow_missing=True)
PROPEL_AUTH_URL = get_from_env("PROPEL_AUTH_URL", allow_missing=True)

Expand Down
3 changes: 2 additions & 1 deletion ui/backend/server/trackingserver_base/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import uuid

from django.apps import AppConfig
from django.conf import settings

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

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

def ready(self):
if is_telemetry_enabled():
if is_telemetry_enabled() and settings.HAMILTON_ENV in ["local"]:
if not os.path.exists("/data/telemetry.txt"):
telemetry_key = str(uuid.uuid4())
with open("/data/telemetry.txt", "w") as f:
Expand Down
1 change: 0 additions & 1 deletion ui/deployment/docker-compose-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ services:
- DB_PASSWORD=password # TODO: Change this to a secret
- HAMILTON_BLOB_STORE=local
- HAMILTON_ENV=local # local env
- HAMILTON_AUTH_PROVIDER=local # local authentication means unauthenticated -- TODO: enable auth for prod
- HAMILTON_LOCAL_BLOB_DIR=/data/blobs # TODO -- set this up to be a better one
- DJANGO_SECRET_KEY=do_not_use_in_production
- HAMILTON_TELEMETRY_ENABLED=${HAMILTON_TELEMETRY_ENABLED-true}
Expand Down
1 change: 0 additions & 1 deletion ui/deployment/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ services:
- DB_PASSWORD=password # Purely for local! Do not deploy to production!
- HAMILTON_BLOB_STORE=local
- HAMILTON_ENV=local # local env
- HAMILTON_AUTH_PROVIDER=local # local authentication means unauthenticated -- do not use in production!!
- HAMILTON_LOCAL_BLOB_DIR=/data/blobs # TODO -- set this up to be a better one
- DJANGO_SECRET_KEY=do_not_use_in_production
- HAMILTON_TELEMETRY_ENABLED=${HAMILTON_TELEMETRY_ENABLED}
Expand Down

0 comments on commit fb0ebb8

Please sign in to comment.