From f62e0efdfc36f78adacd1c1438c28ff1be9389b1 Mon Sep 17 00:00:00 2001 From: Edward Hartnett <38856240+edwardhartnett@users.noreply.github.com> Date: Wed, 11 Oct 2023 03:01:56 -0600 Subject: [PATCH] add spack-based CI build (#100) * adding package file * adding spack CI build * trying to get spack build to work * trying to get spack build to work * trying to get spack build to work * trying to fix spack workflow * Update package.py --------- Co-authored-by: Alex Richert <82525672+AlexanderRichert-NOAA@users.noreply.github.com> --- .github/workflows/Spack.yml | 68 +++++++++++++++++++++++++++++++++++++ spack/package.py | 33 ++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 .github/workflows/Spack.yml create mode 100644 spack/package.py diff --git a/.github/workflows/Spack.yml b/.github/workflows/Spack.yml new file mode 100644 index 0000000..367874c --- /dev/null +++ b/.github/workflows/Spack.yml @@ -0,0 +1,68 @@ +# This is a CI workflow for the NCEPLIBS-g2tmpl project. +# +# This workflow builds w3emc 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"] + + runs-on: ${{ matrix.os }} + + steps: + + - name: checkout-g2tmpl + uses: actions/checkout@v4 + with: + path: g2tmpl + + - 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 g2tmpl-env + spack env activate g2tmpl-env + cp $GITHUB_WORKSPACE/g2tmpl/spack/package.py $SPACK_ROOT/var/spack/repos/builtin/packages/g2tmpl/package.py + mv $GITHUB_WORKSPACE/g2tmpl $SPACK_ENV/g2tmpl + spack develop --no-clone g2tmpl@develop + spack add g2tmpl@develop%gcc@11 + 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 g2tmpl + + # This job validates the Spack recipe by making sure each cmake build option is represented + recipe-check: + runs-on: ubuntu-latest + + steps: + + - name: checkout-g2tmpl + uses: actions/checkout@v4 + with: + path: g2tmpl + + - 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/g2tmpl/CMakeLists.txt) ; do + echo "Checking for presence of '$opt' CMake option in package.py" + grep -cP "define.+\b${opt}\b" $GITHUB_WORKSPACE/g2tmpl/spack/package.py + done diff --git a/spack/package.py b/spack/package.py new file mode 100644 index 0000000..e5a94b4 --- /dev/null +++ b/spack/package.py @@ -0,0 +1,33 @@ +# 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 G2tmpl(CMakePackage): + """Utilities for GRIB2 templates. + + This is part of NOAA's NCEPLIBS project.""" + + homepage = "https://github.com/NOAA-EMC/NCEPLIBS-g2tmpl" + url = "https://github.com/NOAA-EMC/NCEPLIBS-g2tmpl/archive/refs/tags/v1.10.0.tar.gz" + git = "https://github.com/NOAA-EMC/NCEPLIBS-g2tmpl" + + maintainers("edwardhartnett", "AlexanderRichert-NOAA", "Hang-Lei-NOAA") + + version("develop", branch="develop") + version("1.10.2", sha256="4063361369f3691f75288c801fa9d1a2414908b7d6c07bbf69d4165802e2a7fc") + version("1.10.1", sha256="0be425e5128fabb89915a92261aa75c27a46a3e115e00c686fc311321e5d1e2a") + version("1.10.0", sha256="dcc0e40b8952f91d518c59df7af64e099131c17d85d910075bfa474c8822649d") + + variant("shared", default=False, description="Build shared library") + + def cmake_args(self): + args = [self.define_from_variant("BUILD_SHARED_LIBS", "shared")] + return args + + def check(self): + with working_dir(self.builder.build_directory): + make("test")