name: main

on:
  workflow_dispatch:
    inputs:
      logLevel:
        description: 'Log level'
        required: true
        default: 'info'
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:

    runs-on: ubuntu-20.04

    steps:
    - uses: actions/checkout@v2
      
    - name: Install apt-get packages
      run: |
        echo RESET grub-efi/install_devices | sudo debconf-communicate grub-pc
        sudo ACCEPT_EULA=Y apt-get update
        sudo ACCEPT_EULA=Y apt-get upgrade
        sudo apt-get install wget git curl software-properties-common build-essential libjpeg-dev libpng-dev cmake

    - name: Run qdrant in Docker
      run: |
        mkdir qdrant_storage
        nohup docker run -d -p 6333:6333 -p 6334:6334 -v ${{ github.workspace }}/qdrant_storage:/qdrant/storage:z qdrant/qdrant
    
    - name: Install Rust target for wasm
      run: |
        rustup target add wasm32-wasi

    - name: Install WasmEdge
      run: |
        VERSION=0.13.5
        curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | sudo bash -s -- -v $VERSION -p /usr/local
        # curl -X PUT 'http://localhost:6333/collections/test_collection' -H 'Content-Type: application/json' --data-raw '{ "vectors": { "size": 4, "distance": "Dot" } }'

    - name: Run examples
      run: |
        cd examples
        RUSTFLAGS="--cfg wasmedge --cfg tokio_unstable" cargo build --target wasm32-wasi --release
        wasmedgec target/wasm32-wasi/release/qdrant_examples.wasm qdrant_examples.wasm
        wasmedge qdrant_examples.wasm


