Refactor CI to remove duplication #2
Workflow file for this run
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
name: CI | |
on: | |
push: | |
branches: [ development ] | |
pull_request: | |
# CI runs when new commits are pushed or when draft PR is marked ready for review | |
types: [opened, synchronize, reopened, ready_for_review] | |
workflow_dispatch: | |
inputs: | |
debug_enabled: | |
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)' | |
required: false | |
default: false | |
env: | |
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) | |
BUILD_TYPE: Release | |
OMP_NUM_THREADS: 2 | |
jobs: | |
build: | |
# Skip CI if PR is a draft | |
if: github.event.pull_request.draft == false | |
# The CMake configure and build commands are platform agnostic and should work equally | |
# well on Windows or Mac. You can convert this to a matrix build if you need | |
# cross-platform coverage. | |
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix | |
runs-on: ${{matrix.os}} | |
env: | |
CC: ${{ matrix.cc }} | |
CXX: ${{ matrix.cxx }} | |
strategy: | |
fail-fast: false | |
matrix: | |
os: | |
- ubuntu-22.04 | |
cc: | |
- gcc-12 | |
cxx: | |
- g++-12 | |
mpi: | |
- "ON" | |
omp: | |
- "ON" | |
steps: | |
- uses: actions/checkout@v4 | |
# Enable tmate debugging of manually-triggered workflows if the input option was provided | |
- name: Setup tmate session | |
uses: mxschmitt/action-tmate@v3 | |
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }} | |
- name: Prepare ccache timestamp | |
id: ccache_cache_timestamp | |
run: echo "{date_and_time}={$(date +'%Y-%m-%d-%H;%M;%S')}" >> $GITHUB_OUTPUT | |
- name: Set ccache cache directory | |
shell: bash | |
run: echo "CCACHE_DIR=${{runner.workspace}}/.ccache" >> "${GITHUB_ENV}" | |
- name: Cache ccache files | |
uses: actions/cache@v3 | |
with: | |
path: ${{runner.workspace}}/.ccache | |
key: ${{matrix.os}}-${{matrix.cxx}}-${{matrix.mpi}}-${{matrix.omp}}-${{ steps.ccache_cache_timestamp.outputs.date_and_time }} | |
restore-keys: | | |
${{ matrix.os }}-${{ matrix.cxx }}-${{ matrix.mpi }}-${{ matrix.omp }} | |
${{ matrix.os }}-${{ matrix.cxx }}-${{ matrix.mpi }} | |
${{ matrix.os }}-${{ matrix.cxx }} | |
${{ matrix.os }} | |
# - name: Clear ccache | |
# run: ccache --clear | |
- name: Install Dependencies on Ubunutu | |
if: ${{ contains(matrix.os, 'ubuntu') }} | |
run: | | |
sudo apt update | |
sudo apt install openmpi-bin libopenmpi-dev ccache graphviz libeigen3-dev libspdlog-dev libtiff-dev libcfitsio-dev libbenchmark-dev libboost-all-dev libyaml-cpp-dev | |
- name: Install Dependencies on MacOS | |
if: ${{ contains(matrix.os, 'macos') }} | |
run: | | |
brew install gcc libtiff open-mpi libomp eigen libyaml ccache cfitsio boost yaml-cpp | |
echo "CMAKE_PREFIX_PATH=/opt/homebrew/opt/libomp" >> $GITHUB_ENV | |
echo "/opt/homebrew/opt/ccache/libexec" >> $GITHUB_PATH | |
- name: Checkout Catch2 | |
uses: actions/checkout@v4 | |
with: | |
repository: catchorg/Catch2.git | |
path: Catch2 | |
ref: v3.4.0 | |
- name: Build Catch2 | |
run: | | |
mkdir Catch2/build | |
cd Catch2/build | |
cmake .. -DBUILD_TESTING=OFF -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local | |
make -j$(nproc --ignore 1) install | |
- name: Install FFTW | |
run: | | |
wget --no-check-certificate --no-verbose http://www.fftw.org/fftw-3.3.10.tar.gz -O- | tar --no-same-owner -xz; | |
cd fftw-3.3.10 | |
./configure --prefix=${{github.workspace}}/local --enable-shared | |
make -j$(nproc --ignore 1) install CFLAGS=-fPIC | |
# Fix bug in FFT3 (cf. https://github.com/FFTW/fftw3/issues/332) | |
sed -i -e 's/^.*FFTW3LibraryDepends.cmake.*$//1' ${{github.workspace}}/local/lib*/cmake/*/FFTW3Config.cmake | |
- name: Checkout SOPT | |
uses: actions/checkout@v4 | |
with: | |
repository: astro-informatics/sopt.git | |
path: sopt | |
ref: development | |
- name: Build sopt | |
run: | | |
export CMAKE_PREFIX_PATH=${{github.workspace}}/local:$CMAKE_PREFIX_PATH | |
mkdir -p ${{github.workspace}}/sopt/build | |
cd ${{github.workspace}}/sopt/build | |
cmake .. --fresh -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local -Ddompi=${{matrix.mpi}} -Dopenmp=${{matrix.omp}} -Dtests=OFF -Dexamples=OFF | |
make -j$(nproc --ignore 1) install | |
test: | |
needs: | |
build | |
runs-on: ${{matrix.os}} | |
env: | |
CC: ${{ matrix.cc }} | |
CXX: ${{ matrix.cxx }} | |
strategy: | |
fail-fast: false | |
matrix: | |
os: | |
- ubuntu-22.04 | |
cc: | |
- gcc-12 | |
cxx: | |
- g++-12 | |
mpi: | |
- "ON" | |
omp: | |
- "ON" | |
steps: | |
- name: Build tests | |
# Build your program with the given configuration | |
run: | | |
export CMAKE_PREFIX_PATH=${{github.workspace}}/local:$CMAKE_PREFIX_PATH | |
mkdir -p ${{github.workspace}}/build | |
cd ${{github.workspace}}/build | |
cmake .. --fresh -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local -Ddocasa=OFF -Ddompi=${{matrix.mpi}} -Dopenmp=${{matrix.omp}} -Dtests=ON | |
make -j$(nproc --ignore 1) install | |
- name: Test | |
working-directory: ${{github.workspace}}/build | |
# Execute tests defined by the CMake configuration. | |
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail | |
run: | | |
export LD_LIBRARY_PATH=${{github.workspace}}/local/lib:${{github.workspace}}/local/external/lib:${LD_LIBRARY_PATH} | |
ctest -C ${{env.BUILD_TYPE}} --output-on-failure | |
doc: | |
needs: | |
build | |
runs-on: ${{matrix.os}} | |
env: | |
CC: ${{ matrix.cc }} | |
CXX: ${{ matrix.cxx }} | |
strategy: | |
fail-fast: false | |
matrix: | |
os: | |
- ubuntu-22.04 | |
cc: | |
- gcc-12 | |
cxx: | |
- g++-12 | |
mpi: | |
- "ON" | |
omp: | |
- "ON" | |
steps: | |
- name: Build docs | |
run: | | |
export CMAKE_PREFIX_PATH=${{github.workspace}}/local:$CMAKE_PREFIX_PATH | |
mkdir -p ${{github.workspace}}/build | |
cd ${{github.workspace}}/build | |
cmake .. --fresh -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local -Ddompi=OFF -Dopenmp=OFF -Ddocs=ON | |
make -j$(nproc --ignore 1) install | |
- name: Deploy to GH pages | |
if: ${{github.event_name == 'push'}} | |
uses: JamesIves/[email protected] | |
with: | |
branch: gh-pages # The branch the action should deploy to. | |
folder: build/cpp/docs/html # The folder the action should deploy. | |