steps:
- bash: |
    sudo apt-get update
    sudo apt-get install -y postgresql-14 postgresql-client-14 postgresql-server-dev-14 postgresql-common
    echo "start postgres server"
    sudo systemctl start postgresql.service
    echo "add postgres user"
    sudo -u postgres createuser -s `whoami`
    source ${CONDA}/etc/profile.d/conda.sh
    conda config --set always_yes yes --set changeps1 no
    conda update -q conda
    conda info -a
    conda create --name rdkit_build -c conda-forge --override-channels  cmake \
        boost-cpp=$(boost_version) \
        boost=$(boost_version) \
        eigen \
        cairo
    conda activate rdkit_build
    conda config --env --add channels conda-forge
    conda config --env --set channel_priority strict
  displayName: Setup build environment
- bash: |
    source ${CONDA}/etc/profile.d/conda.sh
    conda activate rdkit_build
    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: |
    source ${CONDA}/etc/profile.d/conda.sh
    conda activate rdkit_build
    cd build
    make -j $( $(number_of_cores) ) install
    sudo sh ./Code/PgSQL/rdkit/pgsql_install.sh
  displayName: Build
- bash: |
    source ${CONDA}/etc/profile.d/conda.sh
    conda activate rdkit_build
    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