Skip to content

Commit

Permalink
Add Spack-based CI (NOAA-EMC#556)
Browse files Browse the repository at this point in the history
* Add Spack-based CI

* Use correct package.py

* Update package.py

* no build_8

* fix shared variant

* Update Spack_Linux.yml

* Update package.py

* try adding macos-latest

* fix os matrix for spack ci

* Update package.py

* Update package.py

* Update package.py

* Update and rename Spack_Linux.yml to Spack.yml

* Update package.py
  • Loading branch information
AlexanderRichert-NOAA authored Sep 11, 2023
1 parent 762c923 commit d4f3cbc
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 0 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/Spack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# This is a CI workflow for the NCEPLIBS-g2 project.
#
# This workflow builds g2 with Spack, including installing with the "--test
# root" option to run the CTest suite. 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:
# This job builds with Spack using every combination of variants and runs the CTest suite each time
Spack:
strategy:
matrix:
os: ["ubuntu-latest", "macos-latest"]
pic: ["+pic", "~pic"]
precision: ["precision=d", "precision=4"]
w3emc: ["+w3emc", "~w3emc"]
runs-on: ${{ matrix.os }}

steps:

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

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

steps:

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

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

Before each release of NCEPLIBS-g2, 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.
64 changes: 64 additions & 0 deletions spack/package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# 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 G2(CMakePackage):
"""Utilities for coding/decoding GRIB2 messages. This library contains
Fortran 90 decoder/encoder routines for GRIB edition 2, as well as
indexing/searching utility routines.
This is part of the NCEPLIBS project."""

homepage = "https://noaa-emc.github.io/NCEPLIBS-g2"
url = "https://github.com/NOAA-EMC/NCEPLIBS-g2/archive/refs/tags/v3.4.3.tar.gz"
git = "https://github.com/NOAA-EMC/NCEPLIBS-g2"

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

version("develop", branch="develop")
version("3.4.7", sha256="d6530611e3a515122f11ed4aeede7641f6f8932ef9ee0d4828786572767304dc")
version("3.4.6", sha256="c4b03946365ce0bacf1e10e8412a5debd72d8671d1696aa4fb3f3adb119175fe")
version("3.4.5", sha256="c18e991c56964953d778632e2d74da13c4e78da35e8d04cb742a2ca4f52737b6")
version("3.4.3", sha256="679ea99b225f08b168cbf10f4b29f529b5b011232f298a5442ce037ea84de17c")

variant("pic", default=True, description="Build with position-independent-code")
variant(
"precision",
default=("4", "d"),
values=("4", "d"),
multi=True,
description="Set precision (_4/_d library versions)",
when="@3.4.6:",
)
variant("w3emc", default=True, description="Enable GRIB1 through w3emc", when="@3.4.6:")

depends_on("jasper@:2.0.32")
depends_on("libpng")
depends_on("bacio", when="@3.4.6:")
with when("+w3emc"):
depends_on("w3emc")
depends_on("w3emc precision=4", when="precision=4")
depends_on("w3emc precision=d", when="precision=d")

def cmake_args(self):
args = [
self.define_from_variant("CMAKE_POSITION_INDEPENDENT_CODE", "pic"),
self.define_from_variant("BUILD_WITH_W3EMC", "w3emc"),
self.define("BUILD_4", self.spec.satisfies("precision=4")),
self.define("BUILD_D", self.spec.satisfies("precision=d")),
]

return args

def setup_run_environment(self, env):
precisions = (
self.spec.variants["precision"].value if self.spec.satisfies("@3.4.6:") else ("4", "d")
)
for suffix in precisions:
lib = find_libraries("libg2_" + suffix, root=self.prefix, shared=False, recursive=True)
env.set("G2_LIB" + suffix, lib[0])
env.set("G2_INC" + suffix, join_path(self.prefix, "include_" + suffix))

0 comments on commit d4f3cbc

Please sign in to comment.