Skip to content

Commit

Permalink
Add Spack-based CI workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderRichert-NOAA committed Nov 8, 2023
1 parent bb23506 commit 1fd9f32
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/Spack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# This is a CI workflow for the NCEPLIBS-gfsio project.
#
# This workflow builds gfsio with Spack, including installing with the "--test
# root" option to run the pFunit test. 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, Sep 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-gfsio
uses: actions/checkout@v4
with:
path: gfsio

- name: spack-build-and-test
run: |
git clone -c feature.manyFiles=true https://github.com/jcsda/spack
. spack/share/spack/setup-env.sh
spack env create gfsio-env
spack env activate gfsio-env
cp $GITHUB_WORKSPACE/gfsio/spack/package.py $SPACK_ROOT/var/spack/repos/builtin/packages/gfsio/package.py
spack develop --no-clone --path $GITHUB_WORKSPACE/gfsio gfsio@develop
spack add gfsio@develop%gcc@11 +pfunit
spack external find cmake gmake
spack concretize
# Run installation and run pFunit testing
spack install --verbose --fail-fast --test root
# Run 'spack load' to check for obvious errors in setup_run_environment
spack load gfsio
ls $GFSIO_LIB
ls $GFSIO_LIB4
# This job validates the Spack recipe by making sure each cmake build option is represented
recipe-check:
runs-on: ubuntu-latest

steps:

- name: checkout-gfsio
uses: actions/checkout@v4
with:
path: gfsio

- 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(?!(DUMMY_ENTRY))[^ ]+' $GITHUB_WORKSPACE/gfsio/CMakeLists.txt) ; do
echo "Checking for presence of '$opt' CMake option in package.py"
grep -cP "define.+\b${opt}\b" $GITHUB_WORKSPACE/gfsio/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-gfsio, which is found under Spack as "gfsio".

Before each release of NCEPLIBS-gfsio, 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.
49 changes: 49 additions & 0 deletions spack/package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# 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 Gfsio(CMakePackage):
"""The GFSIO library provides an API to convert GFS Gaussian output into
grib output.
This is part of the NOAA NCEPLIBS project."""

homepage = "https://github.com/NOAA-EMC/NCEPLIBS-gfsio"
url = "https://github.com/NOAA-EMC/NCEPLIBS-gfsio/archive/refs/tags/v1.4.1.tar.gz"
git = "https://github.com/NOAA-EMC/NCEPLIBS-gfsio"

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

version("develop", branch="develop")
version("1.4.1", sha256="eab106302f520600decc4f9665d7c6a55e7b4901fab6d9ef40f29702b89b69b1")

variant("pfunit", default=False, description="Enable pFunit testing")

depends_on("pfunit", when="+pfunit")

def cmake_args(self):
args = [
self.define("ENABLE_TESTS", self.run_tests),
]
return args

def setup_run_environment(self, env):
lib = find_libraries("libgfsio", root=self.prefix, shared=False, recursive=True)
# Only one library version, but still need to set _4 to make NCO happy
for suffix in ("4", ""):
env.set("GFSIO_LIB" + suffix, lib[0])
env.set("GFSIO_INC" + suffix, join_path(self.prefix, "include"))

def flag_handler(self, name, flags):
if self.spec.satisfies("%fj"):
if name == "fflags":
flags.append("-Free")
return (None, None, flags)

def check(self):
with working_dir(self.builder.build_directory):
make("test")

0 comments on commit 1fd9f32

Please sign in to comment.