name: Run Python Tests
on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:

    runs-on: ubuntu-20.04
    services:
      postgres:
        image: postgres:13
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: hunter2
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
        ports:
          - 5432:5432
    steps:
    - uses: actions/checkout@v3
    - name: Set up Python
      uses: actions/setup-python@v4
      with:
        python-version: 3.9
    - name: Install Dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt
    - name: Run Tests
      env:
        SECRET_KEY: beepbeep
        DEBUG: false
        USE_HTTPS: true
        DOMAIN: your.domain.here
        BOOKWYRM_DATABASE_BACKEND: postgres
        MEDIA_ROOT: images/
        POSTGRES_PASSWORD: hunter2
        POSTGRES_USER: postgres
        POSTGRES_DB: github_actions
        POSTGRES_HOST: 127.0.0.1
        CELERY_BROKER: ""
        REDIS_BROKER_PORT: 6379
        REDIS_BROKER_PASSWORD: beep
        USE_DUMMY_CACHE: true
        FLOWER_PORT: 8888
        EMAIL_HOST: "smtp.mailgun.org"
        EMAIL_PORT: 587
        EMAIL_HOST_USER: ""
        EMAIL_HOST_PASSWORD: ""
        EMAIL_USE_TLS: true
        ENABLE_PREVIEW_IMAGES: false
        ENABLE_THUMBNAIL_GENERATION: true
        HTTP_X_FORWARDED_PROTO: false
      run: |
        pytest -n 3
