Use Conda-Forge's CSPICE Package in Tudat #60
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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", "feature/**" ] | |
pull_request: | |
branches: [ "master", "develop", "feature/**" ] | |
jobs: | |
build-and-test: | |
env: | |
CACHE_NUMBER: 1 | |
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. <Windows, Release, latest MSVC compiler toolchain on the default runner image, default generator> | |
# 2. <Linux, Release, latest GCC compiler toolchain on the default runner image, default generator> | |
# 3. <Linux, Release, latest Clang compiler toolchain on the default runner image, default generator> | |
# | |
# 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 | |
- os: ubuntu-latest | |
c_compiler: gcc | |
cpp_compiler: g++ | |
label: linux-64 | |
- os: macos-latest | |
c_compiler: clang | |
cpp_compiler: clang++ | |
label: osx-64 | |
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@v3 | |
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: Set platform-specific data path | |
run: | | |
echo "TUDAT_DATA_PATH=$(python -c "import tudatpy.data; print(tudatpy.data.get_resource_path())")" >> $GITHUB_ENV | |
echo "TUDAT_DATA_PATH=${{ env.TUDAT_DATA_PATH }}" | |
echo "TUDAT_DATA_PATH=$TUDAT_DATA_PATH" | |
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: | | |
${{ env.CONDA }}/envs/tudat | |
${{ env.TUDAT_DATA_PATH }} | |
key: ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles('environment.yml') }}-${{steps.get-date.outputs.today}} | |
id: cache-environment | |
- 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-environment.outputs.cache-hit != 'true' | |
- name: Export the environment to a YAML file | |
run: | | |
conda env export --from-history -f environment-locked.yml | |
- name: Upload the locked environment file | |
# This step uploads the locked conda environment to the artifacts. This is useful for debugging and reproducing the environment locally. | |
uses: actions/upload-artifact@v4 | |
with: | |
name: locked-conda-environment-${{ runner.os }} | |
path: environment-locked.yml | |
- 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/[email protected] | |
with: | |
key: ${{ matrix.os }}-${{ matrix.build_type }}-${{ hashFiles('**/*.cmake', '**/CMakeLists.txt') }} | |
- 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 |