name: Lint and test
on: ["push", "pull_request"]
jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - uses: actions/setup-python@v1
      with:
        python-version: 3.11
    - name: Install flake8
      run: pip install flake8
    - name: Flake8
      run: flake8 askomics tests cli --ignore=E501,W504

  node_test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-node@v2-beta
      with:
        node-version: '10'
    - name: Install modules
      run: make install-js MODE=dev
    - name: Run ESLint
      run: make eslint MODE=dev TRAVIS=true

  py_test:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - uses: actions/setup-python@v1
      with:
        python-version: 3.11
    - name: Update apt cache
      run: sudo apt-get update
    - name: Install python-ldap deps
      run: sudo apt-get install libldap2-dev libsasl2-dev
    - name: Install python dev deps
      run: pip install ephemeris coveralls
    - name: Install deps
      run: make install-python MODE=dev
    - name: Launch containers
      run: |
        docker pull redis:4.0
        docker pull askomics/virtuoso:7.2.5.1
        docker pull bgruening/galaxy-stable:20.05
        docker pull xgaia/corese:latest
        docker pull xgaia/isql-api:2.1.1
        docker pull xgaia/simple-ldap:latest
        docker run -d --name virtuoso -p 8891:8890 -p 1112:1111 -e DBA_PASSWORD=dba -e DEFAULT_GRAPH=http://localhost:8891/DAV -t askomics/virtuoso:7.2.5.1 /bin/sh -c "netstat -nr | grep '^0\.0\.0\.0' | grep -oE '((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])' | grep -v '^0\.0\.0\.0' | sed 's/$/ askomics-host/' >> /etc/hosts && /virtuoso/virtuoso.sh"
        sleep 1m
        docker run -d --name redis -p 6380:6379 -t redis:4.0
        docker run -d --name galaxy -p 8081:80 -t bgruening/galaxy-stable:20.05
        docker run -d --name corese -p 8082:8080 -t xgaia/corese:latest /bin/sh -c "netstat -nr | grep '^0\.0\.0\.0' | grep -oE '((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])' | grep -v '^0\.0\.0\.0' | sed 's/$/ askomics-host/' >> /etc/hosts && /corese/start.sh"
        docker run -d --name isql-api -p 5051:5050 -e VIRTUOSO_HOST=askomics-host -e VIRTUOSO_ISQL_PORT=1112 -t xgaia/isql-api:2.1.1  /bin/sh -c "netstat -nr | grep '^0\.0\.0\.0' | grep -oE '((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])' | grep -v '^0\.0\.0\.0' | sed 's/$/ askomics-host/' >> /etc/hosts && sh /isqlapi/docker-run.sh"
        docker run -d --name ldap -p 8389:389 -e ORGANISATION_NAME=AskOmics -e SUFFIX='dc=askomics,dc=org' -e ROOT_USER=admin -e ROOT_PW_CLEAR=admin -e FIRST_USER=true -e USER_UID=jwick -e USER_GIVEN_NAME=John -e USER_SURNAME=Wick -e USER_EMAIL=john.wick@askomics.org -e USER_PW_CLEAR=jwick -t xgaia/simple-ldap:latest
        galaxy-wait -g http://localhost:8081 --timeout 900
        echo "Galaxy is online, waiting a bit more for admin user creation"
        sleep 1m
    - name: Run tests
      run: |
        make pytest MODE=dev TRAVIS=true
    - name: Coveralls
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      run: |
        coveralls