diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml new file mode 100644 index 0000000000..b1f27ab5d3 --- /dev/null +++ b/.github/workflows/build_and_test.yml @@ -0,0 +1,154 @@ +# This workflow builds and tests the tudat source code on Windows, Linux, and MacOS using GitHub Actions. It is triggered upon push and pull requests to master, develop, and feature branches. +# This Github actions workflow automates the build and test process of the tudat source code on Windows, Linux, and MacOS. The workflow is triggered upon push and pull requests to master, develop, and feature branches. The workflow is built on top of the GitHub starter workflow for CMake on multiple platforms. +# ccache is used to cache previous compilation results to speed up the build process across s +# The workflow is built on top of the GitHub starter workflow for CMake on multiple platforms https://github.com/actions/starter-workflows/blob/main/ci/cmake-multi-platform.yml + + +name: Build and Test + +on: + push: + branches: [ "master", "develop"] + pull_request: + branches: [ "master", "develop"] + +jobs: + build-and-test: + + env: + CACHE_NUMBER: 0 + + runs-on: ${{ matrix.os }} + + strategy: + # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable. + fail-fast: false + + # Set up a matrix to run the following 3 configurations: + # 1. + # 2. + # 3. + # + # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + build_type: [Release] + c_compiler: [gcc, clang, cl] + include: + - os: windows-latest + c_compiler: cl + cpp_compiler: cl + label: win-64 + path_conda_env: C:\Miniconda3\envs\tudat + - os: ubuntu-latest + c_compiler: gcc + cpp_compiler: g++ + label: linux-64 + path_conda_env: /usr/share/miniconda3/envs/tudat + - os: macos-latest + c_compiler: clang + cpp_compiler: clang++ + label: osx-64 + path_conda_env: /Users/runner/miniconda3/envs/tudat + exclude: + - os: windows-latest + c_compiler: gcc + - os: windows-latest + c_compiler: clang + - os: ubuntu-latest + c_compiler: cl + - os: macos-latest + c_compiler: gcc + - os: macos-latest + c_compiler: cl + - os: ubuntu-latest + c_compiler: clang + + steps: + - uses: actions/checkout@v4 + + + - name: Setup conda environment using mamba + # This step sets up a conda environment using mamba, a faster alternative to conda. It creates an empty conda environment with the name 'tudat' and activates it. The environment is created using the latest version of Mambaforge, a conda distribution that includes mamba. + uses: conda-incubator/setup-miniconda@v2 + with: + miniforge-variant: Mambaforge + miniforge-version: latest + activate-environment: tudat + use-mamba: true + + + - name: Get date + # Get the current date and time in UTC format. This step is used to create a unique cache key for the conda environment cache by appending the date to the cache key. + # GitHub cache action doucmentation recommends refreshing the cache every 24 hours to avoid inconsistencies of package versions between the CI pipeline and local installations. This is ensured by appending the date to the cache key.See https://github.com/marketplace/actions/setup-miniconda#caching-environments for more detail. + id: get-date + run: echo "today=$(/bin/date -u '+%Y%m%d')" >> $GITHUB_OUTPUT + shell: bash + + + - name: Cache conda environment + # Cache the conda environment to avoid re-installing the same packages every time the workflow runs. The cache key is based on the environment.yml file, the operating system, and the date. The cache is restored if the cache key matches the cache key of the previous run. + uses: actions/cache@v4 + with: + path: ${{ matrix.path_conda_env }} + key: ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles('environment.yml') }}-${{steps.get-date.outputs.today}} + id: cache + + + - name: Create conda environment from environment.yml + # Update the tudat conda environment created using the environment.yml file if the cache is not restored + run: mamba env update -n tudat -f environment.yml + if: steps.cache.outputs.cache-hit != 'true' + + + - name: Download tudat resources data files for Linux and MacOS + # The data files in tudat-resources are downloaded upon the installation of + # the tudat-resources conda package in the previous step, but the data files are + # not cached by the cache action. When the cache is hit, the update environment + # step is skipped, skipping the installation of the tudat-resources package, + # thereby skipping the download of the data files. Therefore, the data files must + # be downloaded manually when the cache is hit. + # This step downloads the data files in the tudat-resources package by running + # the post-link scripts in https://github.com/tudat-team/tudat-resources-feedstock/blob/master/recipe/ + if: (runner.os == 'Linux' || runner.os == 'MacOS') && steps.cache.outputs.cache-hit == 'true' + run: bash -c "$(curl -fsSL https://raw.githubusercontent.com/tudat-team/tudat-resources-feedstock/master/recipe/post-link.sh)" + + + - name: Download tudat-resources data files for Windows + if: runner.os == 'Windows' && steps.cache.outputs.cache-hit == 'true' + run: cmd /c "curl -fsSL https://raw.githubusercontent.com/tudat-team/tudat-resources-feedstock/master/recipe/post-link.bat | cmd" + + + - name: Restore cached compilation results + # This third party action will setup ccache on the runner and restore any previously saved cache. Caches are saved automatically by the action after a build. + uses: hendrikmuhs/ccache-action@v1.2.12 + with: + key: ${{ matrix.os }}-${{ matrix.build_type }} + + + - name: Configure CMake + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + shell: bash -l {0} + run: > + cmake -B "${{ github.workspace }}/build" + -S "${{ github.workspace }}" + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache + -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} + -DCMAKE_C_COMPILER_LAUNCHER=ccache + -DTUDAT_BUILD_GITHUB_ACTIONS=ON + + + - name: Build + # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). Use multiple cpu cores available in the runner. + shell: bash -l {0} + run: cmake --build "${{ github.workspace }}/build" --config "${{ matrix.build_type }}" -j4 + + + - name: Test + working-directory: "${{ github.workspace }}/build" + # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + run: ctest --build-config ${{ matrix.build_type }} --output-on-failure -j4 \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index ba7e2f837e..217e82a328 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,6 +86,31 @@ else() option(TUDAT_BUILD_WITH_EXTENDED_PRECISION_PROPAGATION_TOOLS "Build tudat with extended precision propagation tools." OFF) endif() +# Build as part of a GitHub Actions workflow +# Option enables the use of ccache by MSVC +# see https://github.com/ccache/ccache/wiki/MS-Visual-Studio +option(TUDAT_BUILD_GITHUB_ACTIONS "Build as part of GitHub Actions workflow." OFF) +if (TUDAT_BUILD_GITHUB_ACTIONS AND MSVC) + find_program(ccache_exe ccache) + if(ccache_exe) + message(STATUS "CONFIGURING MSVC FOR CCACHE") + file(COPY_FILE ${ccache_exe} ${CMAKE_BINARY_DIR}/cl.exe ONLY_IF_DIFFERENT) + + # By default Visual Studio generators will use /Zi which is not compatible + # with ccache, so tell Visual Studio to use /Z7 instead. + message(STATUS "Setting MSVC debug information format to 'Embedded'") + set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<$:Embedded>") + + set(CMAKE_VS_GLOBALS + "CLToolExe=cl.exe" + "CLToolPath=${CMAKE_BINARY_DIR}" + "TrackFileAccess=false" + "UseMultiToolTask=true" + "DebugInformationFormat=OldStyle" + ) + endif() +endif() + message(STATUS "******************** BUILD CONFIGURATION ********************") message(STATUS "TUDAT_BUILD_TESTS ${TUDAT_BUILD_TESTS}") message(STATUS "TUDAT_BUILD_WITH_PROPAGATION_TESTS ${TUDAT_BUILD_WITH_PROPAGATION_TESTS}") diff --git a/environment.yml b/environment.yml new file mode 100644 index 0000000000..b21c5a7358 --- /dev/null +++ b/environment.yml @@ -0,0 +1,11 @@ +name: tudat +channels: + - conda-forge + - tudat-team +dependencies: + - eigen + - boost-cpp + - tudat-resources + - sofa-cmake + - nrlmsise-00 + - cspice-cmake \ No newline at end of file