|
| 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 | + ports: |
| 51 | + - 5432:5432 |
| 52 | + options: >- |
| 53 | + --health-cmd pg_isready |
| 54 | + --health-interval 10s |
| 55 | + --health-timeout 5s |
| 56 | + --health-retries 5 |
| 57 | + steps: |
| 58 | + - uses: actions/checkout@v3 |
| 59 | + - name: Set up Python |
| 60 | + uses: actions/setup-python@v4 |
| 61 | + with: |
| 62 | + python-version: '3.9' |
| 63 | + - name: Install dependencies |
| 64 | + run: | |
| 65 | + cd ui/backend/server |
| 66 | + pip install -r requirements-base.txt |
| 67 | + pip install -r requirements-test.txt |
| 68 | + - name: Run migrations |
| 69 | + run: | |
| 70 | + cd ui/backend/server |
| 71 | + python manage.py sqlcreate |
| 72 | + echo $(python manage.py sqlcreate) | psql -U postgres |
| 73 | + python manage.py migrate |
| 74 | + - name: Run tests |
| 75 | + env: |
| 76 | + DB_HOST: localhost |
| 77 | + DB_USER: postgres |
| 78 | + DB_PASSWORD: "postgres" |
| 79 | + DB_NAME: ${{ matrix.testdir }} |
| 80 | + DW_ENV: integration_tests |
| 81 | + DJANGO_SECRET_KEY: test |
| 82 | + PGPASSWORD: postgres |
| 83 | + PGHOST: localhost |
| 84 | + PGUSER: postgres |
| 85 | + HAMILTON_BLOB_STORE: local |
| 86 | + LOCAL_HAMILTON_BLOB_STORE: ./blob_data |
| 87 | + run: | |
| 88 | + cd backend/server |
| 89 | + python -m pytest tests/${{ matrix.testdir }} -vvvvv |
0 commit comments