Skip to content

Commit a72fe03

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

File tree

1 file changed

+100
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)