version: 2

jobs:
  end2end_tests:
    docker:
      # TODO not sure which is easier to pick...
      - image: circleci/python:latest-browsers
    steps:
      - checkout
      - run: sudo apt install nodejs npm
      - run:
          name: 'build extension'
          command: |
            cd extension
            npm install
            ./build --firefox
            ./build --chrome

      - run: python3 -m pip install --user tox
      - run: sudo apt install atool # used to pack the extension
      - run: python3 -m tox -e end2end

  install_and_run_test:
    # right, docker doesn't seem to be systemd friendly
    machine:
      image: ubuntu-1604:201903-01
    steps:
      - checkout

      - run:
          name: 'setup python'
          command: |
            pyenv global 3.7.0
            pip3 install --upgrade pip

      # - run: curl -sS https://bootstrap.pypa.io/get-pip.py | sudo python3 # right, this container is quite old and doesn't have python3-pip package..

      # - run: sudo apt install python3.5-dev # pyjq depenency; not sure if should be specified in dependencies...
      # WARNING: The script hug is installed in '/home/circleci/.local/bin' which is not on PATH.
      # Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
      
      # right, since we're using pyenv now, we should be doing global install apaprently, otherwise hug is shadowed
      - run: python3 -m pip install . # TODO meh
       #
       # ugh. otherwise systemd doesn't know of pyenv :((
      - run: sudo ln -sf /opt/circleci/.pyenv/versions/3.7.0/bin/python3 /usr/bin/python3
      - run: tests/install_and_run


workflows:
  version: 2
  build_and_test:
    jobs:
      - end2end_tests
      - install_and_run_test
