name: Browsertrix Cloud Integration Test (for Swarm)

on: [push, pull_request]

jobs:
  btrix-swarm-test:
    runs-on: ubuntu-20.04
    services:
      registry:
        image: registry:2
        ports:
          - 5000:5000

    steps:
      -
        name: Checkout
        uses: actions/checkout@v3

      -
        name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2
        with:
          driver-opts: network=host

      - 
        name: Copy Configs
        run: ./scripts/init-configs.sh

      -
        name: Build Backend
        uses: docker/build-push-action@v3
        with:
          context: backend
          push: true
          tags: localhost:5000/webrecorder/browsertrix-backend:latest
          cache-from: type=gha,scope=backend
          cache-to: type=gha,scope=backend,mode=max

      -
        name: Build Frontend
        uses: docker/build-push-action@v3
        with:
          context: frontend
          push: true
          tags: localhost:5000/webrecorder/browsertrix-frontend:latest
          cache-from: type=gha,scope=frontend
          cache-to: type=gha,scope=frontend,mode=max

      - 
        name: Run Bootstrap Script
        run: ./test/setup.sh

      -
        name: Install Python
        uses: actions/setup-python@v3
        with:
          python-version: '3.9'

      - 
        name: Install Python Libs
        run: pip install pytest requests
 
      - 
        name: Backend Tests
        run: py.test -vv ./backend/test/*.py

