Skip to content

Commit

Permalink
Add Spack-based CI
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderRichert-NOAA committed Nov 9, 2023
1 parent 5f22193 commit 879c720
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 0 deletions.
86 changes: 86 additions & 0 deletions .github/workflows/Spack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# This is a CI workflow for the NCEPLIBS-wrf_io project.
#
# This workflow builds wrf_io with Spack. It also has a one-off job that
# validates the recipe by ensuring that every CMake option that should be set
# in the Spack recipe is so set.
#
# Alex Richert, Nov 2023
name: Spack
on:
push:
branches:
- develop
pull_request:
branches:
- develop

jobs:
Spack:
strategy:
matrix:
os: ["ubuntu-latest"]

runs-on: ${{ matrix.os }}

steps:

- name: checkout-wrf-io
uses: actions/checkout@v4
with:
path: wrf-io

- name: cache-spack
id: cache-spack
uses: actions/cache@v3
with:
path: ~/spack-build-cache
key: spack-build-cache-${{ matrix.os }}-1

- name: spack-build-and-test
run: |
sudo apt install openmpi-bin libopenmpi-dev
cd
git clone -c feature.manyFiles=true https://github.com/jcsda/spack
. spack/share/spack/setup-env.sh
spack env create wrf-io-env
spack env activate wrf-io-env
cp $GITHUB_WORKSPACE/wrf-io/spack/package.py $SPACK_ROOT/var/spack/repos/builtin/packages/ncio/package.py
spack develop --no-clone --path $GITHUB_WORKSPACE/wrf-io ncio@develop
spack add wrf-io@develop%gcc@11 ^netcdf-c ~blosc ~szip ~mpi ^hdf5~mpi
spack external find cmake gmake openmpi
spack config add "packages:openmpi:buildable:false"
for mirror in $(spack mirror list | awk '{print $1}'); do
spack mirror rm --scope defaults ${mirror}
done
spack mirror add spack-build-cache ~/spack-build-cache
spack concretize
# Run installation and run CTest suite
if [ "${{ steps.cache.outputs.cache-hit }}" == true ]; then deps=only; else deps=auto; fi
spack install --verbose --fail-fast --no-check-signature --use-buildcache package:never,dependencies:${deps} --test root
spack buildcache push --only dependencies --unsigned --allow-root ~/spack-build-cache wrf-io
- name: Upload test results
uses: actions/upload-artifact@v3
if: ${{ failure() }}
with:
name: spackci-ctest-output-${{ matrix.os }}-${{ matrix.openmp }}
path: ${{ github.workspace }}/wrf-io/spack-build-*/Testing/Temporary/LastTest.log

# This job validates the Spack recipe by making sure each cmake build option is represented
recipe-check:
runs-on: ubuntu-latest

steps:

- name: checkout-wrf-io
uses: actions/checkout@v4
with:
path: wrf-io

- name: recipe-check
run: |
echo "If this jobs fails, look at the most recently output CMake option below and make sure that option appears in spack/package.py"
for opt in $(grep -ioP '^option\(\K(?!(ENABLE_DOCS))[^ ]+' $GITHUB_WORKSPACE/wrf-io/CMakeLists.txt) ; do
echo "Checking for presence of '$opt' CMake option in package.py"
grep -cP "define.+\b${opt}\b" $GITHUB_WORKSPACE/wrf-io/spack/package.py
done
3 changes: 3 additions & 0 deletions spack/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This directory contains an authoritative, up-to-date Spack recipe for NCEPLIBS-wrf_io, which is found under Spack as "wrf-io".

Before each release of NCEPLIBS-wrf_io, this file should be updated to accommodate changes in build options, etc., and .github/workflows/spack.yml should be updated to exercise all variants. Only the version entry should need to be updated after the release prior to incorporation into the Spack repository and the JCSDA Spack fork.
32 changes: 32 additions & 0 deletions spack/package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2013-2023 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

from spack.package import *


class WrfIo(CMakePackage):
"""The WRFIO package is a lightweight WRF-IO API library for Unified
Post Processor (UPP). It reads wrf forecasts (WRF state plus
diagnostics).
This is part of the NCEPLIBS project."""

homepage = "https://noaa-emc.github.io/NCEPLIBS-wrf_io"
url = "https://github.com/NOAA-EMC/NCEPLIBS-wrf_io/archive/refs/tags/v1.2.0.tar.gz"
git = "https://github.com/NOAA-EMC/NCEPLIBS-wrf_io"

maintainers("AlexanderRichert-NOAA", "Hang-Lei-NOAA", "edwardhartnett")

version("develop", branch="develop")
version("1.2.0", sha256="000cf5294a2c68460085258186e1f36c86d3d0d9c433aa969a0f92736b745617")

variant("openmp", default=False, description="Enable multithreading with OpenMP")

depends_on("netcdf-c")
depends_on("netcdf-fortran")

def cmake_args(self):
args = [self.define_from_variant("OPENMP", "openmp")]
return args

0 comments on commit 879c720

Please sign in to comment.