steps:
- bash: |
    sudo apt-get update
    sudo apt-get remove postgresql-14 postgresql-client-14
    sudo apt-get remove postgresql postgresql-common postgresql-client-common libpq5
    sudo apt purge postgresql-14 postgresql-client-14
    sudo apt purge postgresql postgresql-common postgresql-client-common libpq5
    sudo apt-get install -y libboost-all-dev postgresql-common postgresql-12 postgresql-server-dev-12
    echo "add postgres user"
    sudo -u postgres createuser -s `whoami`
  displayName: Setup build environment
- bash: |
    mkdir build && cd build && \
    cmake .. \
    -DCMAKE_BUILD_TYPE=Release \
    -DRDK_INSTALL_INTREE=ON \
    -DRDK_BUILD_CPP_TESTS=OFF \
    -DRDK_BUILD_PYTHON_WRAPPERS=OFF \
    -DRDK_BUILD_COORDGEN_SUPPORT=ON \
    -DRDK_BUILD_MAEPARSER_SUPPORT=ON \
    -DRDK_OPTIMIZE_POPCNT=ON \
    -DRDK_BUILD_TEST_GZIP=ON \
    -DRDK_BUILD_AVALON_SUPPORT=ON \
    -DRDK_BUILD_INCHI_SUPPORT=ON \
    -DRDK_BUILD_SWIG_WRAPPERS=OFF \
    -DRDK_BUILD_THREADSAFE_SSS=ON \
    -DRDK_TEST_MULTITHREADED=ON \
    -DRDK_BUILD_PGSQL=ON \
    -DPostgreSQL_CONFIG=/usr/bin/pg_config
  displayName: Configure build (Run CMake)
- bash: |
    cd build
    make -j $( $(number_of_cores) ) install
    sudo sh ./Code/PgSQL/rdkit/pgsql_install.sh
  displayName: Build
- bash: |
    cd build
    sh ./Code/PgSQL/rdkit/pgsql_regress.sh
    if [ -e ./Code/PgSQL/rdkit/regression.diffs ]
    then
      cat ./Code/PgSQL/rdkit/regression.diffs
      exit 1
    fi
  displayName: Run tests

