os: linux
dist: noble

language: python

python:
  - "3.12"

branches:
  only:
    - master
    - /^maint_.*$/
    - release

cache:
  pip: true
  directories:
    - .git/lfs

notifications:
  email: false

git:
  depth: 10
  lfs_skip_smudge: true

services:
  - docker
  - xvfb

env:
  global:
    - DOCKER_REPONAME=lbnlblum
    - BUILDINGSPY_VERSION=BuildingsPy@v5.2.0
    - OMC_VERSION=ubuntu-2204-omc:1.24.0-1
    - OPTIMICA_VERSION=travis-ubuntu-2204-optimica:1.55.11
    - DYMOLA_VERSION=travis_ubuntu-2004_dymola:2025x-x86_64_rev-2
    - ENERGYPLUS_9_6_0=EnergyPlus-9.6.0-f420c06a69-Linux-Ubuntu20.04-x86_64
    - ENERGYPLUS_23_1_0=EnergyPlus-23.1.0-87ed9199d4-Linux-Ubuntu20.04-x86_64
    - MODELICA_JSON_VERSION=6d950c3592fa021aa914ba4ff34a67cbb69962c6
    - MODELICA_JSON_HOME=${TRAVIS_BUILD_DIR}/modelica-json

  jobs:
    - TEST_ARG="make test-cdl-conformance"
    - TEST_ARG="make test-energyplus-validations test-dymola-spawn-spaces test-openmodelica-spawn-spaces test-openmodelica-cdl" #target test-optimica-spawn-fmu removed as it requires a local installation of OCT
    - TEST_ARG="make test-bestest"
    - TEST_ARG="make test-dymola    PACKAGE=\"Buildings.{Air,Examples}\""
    - TEST_ARG="make test-openmodelica PACKAGE=\"Buildings.{Air,Examples}\""
    - TEST_ARG="make test-optimica  PACKAGE=\"Buildings.{Air,Examples}\""
    - TEST_ARG="make test-dymola    PACKAGE=\"Buildings.Controls\""
    - TEST_ARG="make test-openmodelica PACKAGE=\"Buildings.Controls\""
    - TEST_ARG="make test-optimica  PACKAGE=\"Buildings.Controls\""
    - TEST_ARG="make test-dymola    PACKAGE=\"Buildings.ThermalZones.EnergyPlus_24_2_0\""
    - TEST_ARG="make test-openmodelica PACKAGE=\"Buildings.ThermalZones.EnergyPlus_24_2_0\""
    - TEST_ARG="make test-optimica  PACKAGE=\"Buildings.ThermalZones.EnergyPlus_24_2_0\""
    - TEST_ARG="make test-dymola    PACKAGE=\"Buildings.ThermalZones.Detailed.{BaseClasses,Constructions,Examples}\""
    - TEST_ARG="make test-openmodelica PACKAGE=\"Buildings.ThermalZones.Detailed.{BaseClasses,Constructions,Examples}\""
    - TEST_ARG="make test-optimica  PACKAGE=\"Buildings.ThermalZones.Detailed.{BaseClasses,Constructions,Examples}\""
    - TEST_ARG="make test-dymola    PACKAGE=\"Buildings.ThermalZones.Detailed.Validation.BESTEST\""
    - TEST_ARG="make test-openmodelica PACKAGE=\"Buildings.ThermalZones.Detailed.Validation.BESTEST\""
    - TEST_ARG="make test-optimica  PACKAGE=\"Buildings.ThermalZones.Detailed.Validation.BESTEST\""
    - TEST_ARG="make test-dymola    PACKAGE=\"Buildings.ThermalZones.Detailed.Validation.{Initialization,LBNL_71T,TestConditionalConstructions}\""
    - TEST_ARG="make test-openmodelica PACKAGE=\"Buildings.ThermalZones.Detailed.Validation.{Initialization,LBNL_71T,TestConditionalConstructions}\""
    - TEST_ARG="make test-optimica  PACKAGE=\"Buildings.ThermalZones.Detailed.Validation.{Initialization,LBNL_71T,TestConditionalConstructions}\""
    - TEST_ARG="make test-dymola    PACKAGE=\"Buildings.ThermalZones.Detailed.FLEXLAB\""
    - TEST_ARG="make test-openmodelica PACKAGE=\"Buildings.ThermalZones.Detailed.FLEXLAB\""
    - TEST_ARG="make test-optimica  PACKAGE=\"Buildings.ThermalZones.Detailed.FLEXLAB\""
    - TEST_ARG="make test-dymola    PACKAGE=\"Buildings.ThermalZones.{ISO13790,ReducedOrder}\""
    - TEST_ARG="make test-openmodelica PACKAGE=\"Buildings.ThermalZones.{ISO13790,ReducedOrder}\""
    - TEST_ARG="make test-optimica  PACKAGE=\"Buildings.ThermalZones.{ISO13790,ReducedOrder}\""
    - TEST_ARG="make test-dymola    PACKAGE=\"Buildings.Applications\""
    - TEST_ARG="make test-openmodelica PACKAGE=\"Buildings.Applications\""
    - TEST_ARG="make test-optimica  PACKAGE=\"Buildings.Applications\""
    - TEST_ARG="make test-dymola    PACKAGE=\"Buildings.DHC.{ETS,Loads,Networks,Plants}\""
    - TEST_ARG="make test-openmodelica PACKAGE=\"Buildings.DHC.{ETS,Loads,Networks,Plants}\" SINGLEPROC=\"true\""
    - TEST_ARG="make test-optimica  PACKAGE=\"Buildings.DHC.{ETS,Loads,Networks,Plants}\""
    - TEST_ARG="make test-dymola  PACKAGE=\"Buildings.DHC.Examples\""
    - TEST_ARG="make test-openmodelica PACKAGE=\"Buildings.DHC.Examples\" SINGLEPROC=\"true\""
    - TEST_ARG="make test-optimica  PACKAGE=\"Buildings.DHC.Examples\""
    - TEST_ARG="make test-dymola    PACKAGE=\"Buildings.Fluid.{Actuators,BaseClasses,Boilers,Chillers,CHPs,Delays}\""
    - TEST_ARG="make test-openmodelica PACKAGE=\"Buildings.Fluid.{Actuators,BaseClasses,Boilers,Chillers,CHPs,Delays}\""
    - TEST_ARG="make test-optimica  PACKAGE=\"Buildings.Fluid.{Actuators,BaseClasses,Boilers,Chillers,CHPs,Delays}\""
    - TEST_ARG="make test-dymola    PACKAGE=\"Buildings.Fluid.{Examples,FMI}\""
    - TEST_ARG="make test-openmodelica PACKAGE=\"Buildings.Fluid.{Examples,FMI}\""
    - TEST_ARG="make test-optimica  PACKAGE=\"Buildings.Fluid.{Examples,FMI}\""
    - TEST_ARG="make test-dymola    PACKAGE=\"Buildings.Fluid.FixedResistances\""
    - TEST_ARG="make test-openmodelica PACKAGE=\"Buildings.Fluid.FixedResistances\""
    - TEST_ARG="make test-optimica  PACKAGE=\"Buildings.Fluid.FixedResistances\""
    - TEST_ARG="make test-dymola    PACKAGE=\"Buildings.Fluid.Geothermal\""
    - TEST_ARG="make test-openmodelica PACKAGE=\"Buildings.Fluid.Geothermal\""
    - TEST_ARG="make test-optimica  PACKAGE=\"Buildings.Fluid.Geothermal\""
    - TEST_ARG="make test-dymola    PACKAGE=\"Buildings.Fluid.{HeatExchangers,HeatPumps,Humidifiers,HydronicConfigurations,Interfaces}\""
    - TEST_ARG="make test-openmodelica PACKAGE=\"Buildings.Fluid.{HeatExchangers,HeatPumps,Humidifiers,HydronicConfigurations,Interfaces}\""
    - TEST_ARG="make test-optimica  PACKAGE=\"Buildings.Fluid.{HeatExchangers,HeatPumps,Humidifiers,HydronicConfigurations,Interfaces}\""
    - TEST_ARG="make test-dymola    PACKAGE=\"Buildings.Fluid.{MassExchangers,MixingVolumes,Movers,Sensors,SolarCollectors,Sources,Storage,Utilities}\""
    - TEST_ARG="make test-openmodelica PACKAGE=\"Buildings.Fluid.{MassExchangers,MixingVolumes,Movers,Sensors,SolarCollectors,Sources,Storage,Utilities}\""
    - TEST_ARG="make test-optimica  PACKAGE=\"Buildings.Fluid.{MassExchangers,MixingVolumes,Movers,Sensors,SolarCollectors,Sources,Storage,Utilities}\""
    - TEST_ARG="make test-dymola    PACKAGE=\"Buildings.Electrical\""
    - TEST_ARG="make test-openmodelica PACKAGE=\"Buildings.Electrical\""
    - TEST_ARG="make test-optimica  PACKAGE=\"Buildings.Electrical\""
    - TEST_ARG="make test-dymola    PACKAGE=\"Buildings.{Airflow,BoundaryConditions}\""
    - TEST_ARG="make test-openmodelica PACKAGE=\"Buildings.{Airflow,BoundaryConditions}\""
    - TEST_ARG="make test-optimica  PACKAGE=\"Buildings.{Airflow,BoundaryConditions}\""
    - TEST_ARG="make test-dymola    PACKAGE=\"Buildings.HeatTransfer\""
    - TEST_ARG="make test-openmodelica PACKAGE=\"Buildings.HeatTransfer\""
    - TEST_ARG="make test-optimica  PACKAGE=\"Buildings.HeatTransfer\""
    - TEST_ARG="make test-dymola    PACKAGE=\"Buildings.{Obsolete,Occupants,Media}\""
    - TEST_ARG="make test-openmodelica PACKAGE=\"Buildings.{Obsolete,Occupants,Media}\""
    - TEST_ARG="make test-optimica  PACKAGE=\"Buildings.{Obsolete,Occupants,Media}\""
    - TEST_ARG="make test-dymola    PACKAGE=\"Buildings.Utilities\""
    - TEST_ARG="make test-openmodelica PACKAGE=\"Buildings.Utilities\""
    - TEST_ARG="make test-optimica  PACKAGE=\"Buildings.Utilities\""
    - TEST_ARG="make test-dymola    PACKAGE=\"Buildings.Templates\""
    - TEST_ARG="make test-openmodelica  PACKAGE=\"Buildings.Templates\""
    - TEST_ARG="make test-optimica  PACKAGE=\"Buildings.Templates\""
    - TEST_ARG="make test-templates-dymola PACKAGE=\"Buildings.Templates.AirHandlersFans\" COVER=0.5"
    - TEST_ARG="make test-templates-dymola PACKAGE=\"Buildings.Templates.Plants.HeatPumps\" COVER=0.2"
    - TEST_ARG="make test-templates-dymola PACKAGE=\"Buildings.Templates.ZoneEquipment\""

before_install:
  - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
  - nvm install 24.5 # Installs the specific version
  - nvm use 24.5
  - if [[ "$TEST_ARG" == *test-dymola* || "$TEST_ARG" == *test-templates-dymola* || "$TEST_ARG" == *test-bestest* || "$TEST_ARG" == *spawn-portability* ]]; then
       docker pull "$DOCKER_REPONAME"/${DYMOLA_VERSION};
       cp Buildings/Resources/Scripts/travis/dymola/dymola $HOME/bin/;
    fi;
  - if [[ "$TEST_ARG" == *test-optimica* || "$TEST_ARG" == *test-templates-optimica* ]]; then
       docker pull "$DOCKER_REPONAME"/${OPTIMICA_VERSION};
       cp Buildings/Resources/Scripts/travis/optimica/jm_ipython.sh $HOME/bin/jm_ipython.sh;
    fi;
# The Spawn idf reference results are generated with EnergyPlus 9.6.0,
# while others use a more recent EnergyPlus, hence we install both
  - if [[ "$TEST_ARG" == *test-energyplus* ]]; then
      wget --no-verbose https://github.com/NREL/EnergyPlus/releases/download/v9.6.0/${ENERGYPLUS_9_6_0}.tar.gz;
      tar xzf ${ENERGYPLUS_9_6_0}.tar.gz;
      rm ${ENERGYPLUS_9_6_0}.tar.gz;
      echo "Installed EnergyPlus in ${PWD}/${ENERGYPLUS_9_6_0}";
      wget --no-verbose https://github.com/NREL/EnergyPlus/releases/download/v23.1.0/${ENERGYPLUS_23_1_0}.tar.gz;
      tar xzf ${ENERGYPLUS_23_1_0}.tar.gz;
      rm ${ENERGYPLUS_23_1_0}.tar.gz;
      echo "Installed EnergyPlus in ${PWD}/${ENERGYPLUS_23_1_0}";
    fi;
  - if [[ "$TEST_ARG" == *test-cdl-conformance* ]]; then
      wget --no-verbose https://github.com/lbl-srg/modelica-json/archive/${MODELICA_JSON_VERSION}.tar.gz;
      tar xzf ${MODELICA_JSON_VERSION}.tar.gz;
      rm ${MODELICA_JSON_VERSION}.tar.gz;
      mv modelica-json-${MODELICA_JSON_VERSION} ${MODELICA_JSON_HOME};
      cd ${MODELICA_JSON_HOME};
      make install-node-packages;
      make compile;
      cd -;
      echo "Installed modelica-json in ${MODELICA_JSON_HOME}";
    fi;
  - if [[ "$TEST_ARG" == *test-openmodelica* || "$TEST_ARG" == *test-templates-openmodelica* ]]; then
       docker pull lbnlblum/${OMC_VERSION};
       cp Buildings/Resources/Scripts/travis/omc/omc $HOME/bin/omc;
    fi;

# Install dependencies
# For sphinx, we need to install specific package versions, otherwise
# the html output may have small formatting differences which causes
# the test to fail
install:
  - git lfs pull
  - pip3 install --upgrade pip wheel
  - pip3 install git+https://github.com/lbl-srg/${BUILDINGSPY_VERSION}
  - if [[ "$TEST_ARG" == *test-energyplus* ]] || [[ "$TEST_ARG" == *test-templates* ]]; then
      export ENERGYPLUS_9_6_0=${ENERGYPLUS_9_6_0};
      export ENERGYPLUS_23_1_0=${ENERGYPLUS_23_1_0};
      pip3 install -r Buildings/Resources/Scripts/EnergyPlus/requirements.txt;
    fi;
  - if [[ "$TEST_ARG" == *EnergyPlus_24_2_0* ]] || [[ "$TEST_ARG" == *Buildings.{Obsolete* ]] || [[ "$TEST_ARG" == *Buildings.DHC.{ETS,Loads,Networks,Plants}* ]] || [[ "$TEST_ARG" == *spawn* ]]; then
      echo "Installing Spawn binaries";
      Buildings/Resources/src/ThermalZones/install.py --binaries-for-os-only;
    fi;
  - if [[ "$TEST_ARG" == *SINGLEPROC* ]]; then
      export NPROC=1;
    else
      export NPROC=10;
    fi;

# Execute tests
script:
  - |
    TRAVIS_WAIT=90
    if [[ "$TEST_ARG" == *test-templates* ]]; then
      TRAVIS_WAIT=120
    fi
    (cd Buildings/Resources/Scripts/travis && travis_wait $TRAVIS_WAIT $TEST_ARG)


after_failure:
  - |
    for ff in `find Buildings -maxdepth 1 -name '*.log'`; do
      echo "*** Content of $ff"
      cat $ff
      echo "*** End of $ff"
    done
