Skip to content

Commit 2917522

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

File tree

4 files changed

+102
-4
lines changed

4 files changed

+102
-4
lines changed
+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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+
HAMILTON_ENV: integration_tests
76+
DJANGO_SECRET_KEY: test
77+
PGPASSWORD: postgres
78+
PGHOST: localhost
79+
PGUSER: postgres
80+
HAMILTON_BLOB_STORE: local
81+
LOCAL_HAMILTON_BLOB_STORE: ./blob_data
82+
run: |
83+
cd ui/backend/server
84+
python manage.py sqlcreate
85+
echo $(python manage.py sqlcreate) | psql -U postgres
86+
python manage.py migrate
87+
- name: Run tests
88+
env:
89+
DB_HOST: localhost
90+
DB_USER: postgres
91+
DB_PASSWORD: "postgres"
92+
DB_NAME: ${{ matrix.testdir }}
93+
HAMILTON_ENV: integration_tests
94+
DJANGO_SECRET_KEY: test
95+
PGPASSWORD: postgres
96+
PGHOST: localhost
97+
PGUSER: postgres
98+
HAMILTON_BLOB_STORE: local
99+
LOCAL_HAMILTON_BLOB_STORE: ./blob_data
100+
run: |
101+
cd backend/server
102+
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/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)