From a8dd34d1fa50f4b1ec4bdfdfab52818ac5b92d40 Mon Sep 17 00:00:00 2001 From: Rahul Mahajan Date: Wed, 16 Aug 2023 09:15:59 -0400 Subject: [PATCH] Enable testing on Github Actions (#841) Add workflows for GCC and Intel respectively that builds the dependencies with spack, caches them and then builds ufs-utils. If the build is successful, the ctests are also run. Fixes #668. --- .github/workflows/gcc.yaml | 97 +++++++++++++++++++++++++++++ .github/workflows/intel.yaml | 115 +++++++++++++++++++++++++++++++++++ ci/spack.yaml | 24 ++++++++ 3 files changed, 236 insertions(+) create mode 100644 .github/workflows/gcc.yaml create mode 100644 .github/workflows/intel.yaml create mode 100644 ci/spack.yaml diff --git a/.github/workflows/gcc.yaml b/.github/workflows/gcc.yaml new file mode 100644 index 000000000..bb89ad10b --- /dev/null +++ b/.github/workflows/gcc.yaml @@ -0,0 +1,97 @@ +name: GCC Linux Build and Test +on: [push, pull_request, workflow_dispatch] + + +# Use custom shell with -l so .bash_profile is sourced +# without having to do it in manually every step +defaults: + run: + shell: bash -leo pipefail {0} + +env: + cache_key: gcc + CC: gcc-10 + FC: gfortran-10 + CXX: g++-10 + +# The jobs are split into: +# 1. a dependency build step (setup), and +# 2. a UFS-utils build and test step (ufs_utils) +# The setup is run once and the environment is cached, +# so each subsequent build and test of UFS-utils can reuse the cached +# dependencies to save time (and compute). + +jobs: + setup: + runs-on: ubuntu-latest + + steps: + - name: checkout # this is to get the ci/spack.yaml file + uses: actions/checkout@v3 + with: + path: ufs_utils + + # Cache spack, compiler and dependencies + - name: cache-env + id: cache-env + uses: actions/cache@v2 + with: + path: | + spack + ~/.spack + key: spack-${{ runner.os }}-${{ env.cache_key }}-${{ hashFiles('ufs_utils/ci/spack.yaml') }} + + # Install dependencies using Spack + - name: install-dependencies-with-spack + if: steps.cache-env.outputs.cache-hit != 'true' + run: | + git clone -c feature.manyFiles=true https://github.com/JCSDA/spack.git + source spack/share/spack/setup-env.sh + spack env create ufs_utils-env ufs_utils/ci/spack.yaml + spack env activate ufs_utils-env + sudo apt install cmake + spack external find + spack add mpich@3.4.2 + spack concretize + spack install -v --fail-fast --dirty + spack clean --all + + ufs_utils: + needs: setup + runs-on: ubuntu-latest + + steps: + - name: checkout + uses: actions/checkout@v3 + with: + path: ufs_utils + submodules: recursive + + - name: cache-env + id: cache-env + uses: actions/cache@v2 + with: + path: | + spack + ~/.spack + key: spack-${{ runner.os }}-${{ env.cache_key }}-${{ hashFiles('ufs_utils/ci/spack.yaml') }} + + - name: build + run: | + source spack/share/spack/setup-env.sh + spack env activate ufs_utils-env + export CC=mpicc + export FC=mpif90 + cd ufs_utils + mkdir -p build && cd build + cmake -DCMAKE_INSTALL_PREFIX=../install .. + make -j2 VERBOSE=1 + make install + + - name: ctest + run: | + source spack/share/spack/setup-env.sh + spack env activate ufs_utils-env + cd ufs_utils + cd build + ctest --verbose --rerun-failed --output-on-failure diff --git a/.github/workflows/intel.yaml b/.github/workflows/intel.yaml new file mode 100644 index 000000000..ef801020a --- /dev/null +++ b/.github/workflows/intel.yaml @@ -0,0 +1,115 @@ +name: Intel Linux Build and Test +on: [push, pull_request, workflow_dispatch] + +# Use custom shell with -l so .bash_profile is sourced which loads intel/oneapi/setvars.sh +# without having to do it in manually every step +defaults: + run: + shell: bash -leo pipefail {0} + +# Set I_MPI_CC/F90 so Intel MPI wrapper uses icc/ifort instead of gcc/gfortran +env: + cache_key: intel + CC: icc + FC: ifort + CXX: icpc + I_MPI_CC: icc + I_MPI_F90: ifort + +# The jobs are split into: +# 1. a dependency build step (setup), and +# 2. a UFS-utils build and test step (ufs_utils) +# The setup is run once and the environment is cached, +# so each subsequent build and test of UFS-utils can reuse the cached +# dependencies to save time (and compute). + +jobs: + setup: + runs-on: ubuntu-20.04 + + steps: + - name: checkout # this is to get the ci/spack.yaml file + uses: actions/checkout@v3 + with: + path: ufs_utils + + # Cache spack, compiler and dependencies + - name: cache-env + id: cache-env + uses: actions/cache@v3 + with: + path: | + spack + ~/.spack + /opt/intel + key: spack-${{ runner.os }}-${{ env.cache_key }}-${{ hashFiles('ufs_utils/ci/spack.yaml') }} + + - name: install-intel-compilers + run: | + wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB + sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB + echo "deb https://apt.repos.intel.com/oneapi all main" | sudo tee /etc/apt/sources.list.d/oneAPI.list + sudo apt-get update + sudo apt-get install intel-oneapi-dev-utilities intel-oneapi-mpi-devel intel-oneapi-openmp intel-oneapi-compiler-fortran intel-oneapi-compiler-dpcpp-cpp-and-cpp-classic + echo "source /opt/intel/oneapi/setvars.sh" >> ~/.bash_profile + + # Install dependencies using Spack + - name: install-dependencies-with-spack + if: steps.cache-env.outputs.cache-hit != 'true' + run: | + git clone -c feature.manyFiles=true https://github.com/NOAA-EMC/spack.git + source spack/share/spack/setup-env.sh + spack env create ufs_utils-env ufs_utils/ci/spack.yaml + spack env activate ufs_utils-env + spack compiler find + sudo apt install cmake + spack external find + spack add intel-oneapi-mpi + spack concretize + spack install --dirty -v --fail-fast + spack clean --all + + ufs_utils: + needs: setup + runs-on: ubuntu-20.04 + + steps: + - name: install-intel + run: | + echo "source /opt/intel/oneapi/setvars.sh" >> ~/.bash_profile + + - name: checkout + uses: actions/checkout@v3 + with: + path: ufs_utils + submodules: recursive + + - name: cache-env + id: cache-env + uses: actions/cache@v3 + with: + path: | + spack + ~/.spack + /opt/intel + key: spack-${{ runner.os }}-${{ env.cache_key }}-${{ hashFiles('ufs_utils/ci/spack.yaml') }} + + - name: build + run: | + source spack/share/spack/setup-env.sh + spack env activate ufs_utils-env + export CC=mpiicc + export FC=mpiifort + cd ufs_utils + mkdir -p build && cd build + cmake -DCMAKE_INSTALL_PREFIX=../install .. + make -j2 VERBOSE=1 + make install + + - name: ctest + run: | + source spack/share/spack/setup-env.sh + spack env activate ufs_utils-env + cd ufs_utils + cd build + ctest --verbose --rerun-failed --output-on-failure diff --git a/ci/spack.yaml b/ci/spack.yaml new file mode 100644 index 000000000..ffbf1c97c --- /dev/null +++ b/ci/spack.yaml @@ -0,0 +1,24 @@ +# Spack environment file to build UFS utilities dependencies +spack: + packages: + all: + compiler: + - intel + - gcc@10:10 + specs: + - netcdf-c@4.7.4 + - netcdf-fortran@4.5.3 + - bacio@2.4.1 + - g2@3.4.5 + - ip@3.3.3 + - nemsio@2.5.4 + - sp@2.3.3 + - w3emc@2.9.2 + - sfcio@1.4.1 + - sigio@2.3.2 + - nccmp@1.9.0.1 + - parallelio@2.5.9+fortran~pnetcdf + - esmf@8.4.2~debug~xerces+external-parallelio + view: true + concretizer: + unify: true