diff --git a/.github/workflows/unittests.yaml b/.github/workflows/unittests.yaml index 5622a4de6..2a409cbd5 100644 --- a/.github/workflows/unittests.yaml +++ b/.github/workflows/unittests.yaml @@ -1,5 +1,5 @@ name: Run Unit Tests -on: [pull_request] +on: [push, pull_request] jobs: ctests: diff --git a/ci/driver.sh b/ci/driver.sh new file mode 100755 index 000000000..cbd326960 --- /dev/null +++ b/ci/driver.sh @@ -0,0 +1,100 @@ +#!/bin/bash --login + +my_dir="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )" + +# ============================================================================== +usage() { + set +x + echo + echo "Usage: $0 -t -h" + echo + echo " -t target/machine script is running on DEFAULT: $(hostname)" + echo " -h display this message and quit" + echo + exit 1 +} + +# ============================================================================== +# First, set up runtime environment + +export TARGET="$(hostname)" + +while getopts "t:h" opt; do + case $opt in + t) + TARGET=$OPTARG + ;; + h|\?|:) + usage + ;; + esac +done + +case ${TARGET} in + hera | orion) + echo "Running Automated Testing on $TARGET" + source $MODULESHOME/init/sh + source $my_dir/${TARGET}.sh + module purge + module use $GDAS_MODULE_USE + module load GDAS/$TARGET + module list + ;; + *) + echo "Unsupported platform. Exiting with error." + exit 1 + ;; +esac + + +# ============================================================================== +# pull on the repo and get list of open PRs +cd $GDAS_CI_ROOT/repo +CI_LABEL="${GDAS_CI_HOST}-RT" +gh pr list --label "$CI_LABEL" --state "open" | awk '{print $1;}' > $GDAS_CI_ROOT/open_pr_list +open_pr_list=$(cat $GDAS_CI_ROOT/open_pr_list) + +# ============================================================================== +# clone, checkout, build, test, etc. +repo_url="https://github.com/NOAA-EMC/GDASApp.git" +# loop through all open PRs +for pr in $open_pr_list; do + gh pr edit $pr --remove-label $CI_LABEL --add-label ${CI_LABEL}-Running + echo "Processing Pull Request #${pr}" + mkdir -p $GDAS_CI_ROOT/PR/$pr + cd $GDAS_CI_ROOT/PR/$pr + + # clone copy of repo + git clone $repo_url + cd GDASApp + + # checkout pull request + git pull + gh pr checkout $pr + + # get commit hash + commit=$(git log --pretty=format:'%h' -n 1) + if [ -f "$GDAS_CI_ROOT/PR/$pr/commit" ]; then + oldcommit=$(cat $GDAS_CI_ROOT/PR/$pr/commit) + if [ $oldcommit == $commit ]; then + # do no more for this PR, as the commit has already been tested + continue + fi + fi + echo "$commit" > $GDAS_CI_ROOT/PR/$pr/commit + + # run build and testing command + $my_dir/run_ci.sh -d $GDAS_CI_ROOT/PR/$pr/GDASApp -o $GDAS_CI_ROOT/PR/$pr/output_${commit} + ci_status=$? + gh pr comment $pr --body-file $GDAS_CI_ROOT/PR/$pr/output_${commit} + if [ $ci_status -eq 0 ]; then + gh pr edit $pr --remove-label ${CI_LABEL}-Running --add-label ${CI_LABEL}-Passed + else + gh pr edit $pr --remove-label ${CI_LABEL}-Running --add-label ${CI_LABEL}-Failed + fi +done + +# ============================================================================== +# scrub working directory for older files +find $GDAS_CI_ROOT/PR/* -mtime +3 -exec rm -rf {} \; + diff --git a/ci/orion.sh b/ci/orion.sh new file mode 100644 index 000000000..1084046ce --- /dev/null +++ b/ci/orion.sh @@ -0,0 +1,10 @@ +GDAS_CI_ROOT=/work2/noaa/stmp/cmartin/CI/GDASApp +GDAS_CI_HOST='orion' +export GDAS_MODULE_USE=$GDAS_CI_ROOT/repo/modulefiles +export SLURM_ACCOUNT=da-cpu +export SALLOC_ACCOUNT=$SLURM_ACCOUNT +export SBATCH_ACCOUNT=$SLURM_ACCOUNT +export SLURM_QOS=debug +export SLURM_EXCLUSIVE=user +export OMP_NUM_THREADS=1 +ulimit -s unlimited diff --git a/ci/run_ci.sh b/ci/run_ci.sh new file mode 100755 index 000000000..c3bdbd7f1 --- /dev/null +++ b/ci/run_ci.sh @@ -0,0 +1,75 @@ +#!/bin/bash +#set -eu + +# ============================================================================== +usage() { + set +x + echo + echo "Usage: $0 -d -o -h" + echo + echo " -d Run build and ctest for clone in " + echo " -o Path to output message detailing results of CI tests" + echo " -h display this message and quit" + echo + exit 1 +} + +# ============================================================================== +while getopts "d:o:h" opt; do + case $opt in + d) + repodir=$OPTARG + ;; + o) + outfile=$OPTARG + ;; + h|\?|:) + usage + ;; + esac +done + +# ============================================================================== +# start output file +echo "Automated Pull Request Testing Results:" > $outfile +echo "Machine: ${TARGET}" >> $outfile +echo '```' >> $outfile +echo "Start: $(date) on $(hostname)" >> $outfile +echo "---------------------------------------------------" >> $outfile +# ============================================================================== +# run build script +cd $repodir +module purge +./build.sh -t $TARGET &>> log.build +build_status=$? +if [ $build_status -eq 0 ]; then + echo "Build: *SUCCESS*" >> $outfile + echo "Build: Completed at $(date)" >> $outfile +else + echo "Build: *FAILED*" >> $outfile + echo "Build: Failed at $(date)" >> $outfile + echo "Build: see output at $repodir/log.build" >> $outfile + echo '```' >> $outfile + exit $build_status +fi +# ============================================================================== +# run ctests +cd $repodir/build +module use $GDAS_MODULE_USE +module load GDAS/$TARGET +echo "---------------------------------------------------" >> $outfile +ctest -R gdasapp --output-on-failure &>> log.ctest +ctest_status=$? +npassed=$(cat log.ctest | grep "tests passed") +if [ $ctest_status -eq 0 ]; then + echo "Tests: *SUCCESS*" >> $outfile + echo "Tests: Completed at $(date)" >> $outfile + echo "Tests: $npassed" >> $outfile +else + echo "Tests: *Failed*" >> $outfile + echo "Tests: Failed at $(date)" >> $outfile + echo "Tests: $npassed" >> $outfile + echo "Tests: see output at $repodir/build/log.ctest" >> $outfile +fi +echo '```' >> $outfile +exit $ctest_status diff --git a/modulefiles/GDAS/orion.lua b/modulefiles/GDAS/orion.lua index c68a1e093..56e9ca73f 100644 --- a/modulefiles/GDAS/orion.lua +++ b/modulefiles/GDAS/orion.lua @@ -41,9 +41,9 @@ load("eckit/ecmwf-1.16.0") load("fckit/ecmwf-0.9.2") load("atlas/ecmwf-0.24.1") -load("hpc") -load("miniconda3") -load("gdasapp") +load("hpc/1.2.0") +load("miniconda3/4.6.14") +load("gdasapp/1.0.0") setenv("CC","mpiicc") setenv("FC","mpiifort") diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b8ff8c906..f006b413b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -28,14 +28,14 @@ install(FILES ${test_data} ##### unit tests # test for python coding norms -add_test(NAME GDASApp_check_python_norms +add_test(NAME test_gdasapp_check_python_norms COMMAND pycodestyle -v --config ./.pycodestyle . WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) # test for ush/check_yaml_keys.py -add_test(NAME GDASApp_check_yaml_keys +add_test(NAME test_gdasapp_check_yaml_keys COMMAND ${Python3_EXECUTABLE} ${PROJECT_SOURCE_DIR}/ush/check_yaml_keys.py ${PROJECT_SOURCE_DIR}/test/testinput/check_yaml_keys_ref.yaml ${PROJECT_SOURCE_DIR}/test/testinput/check_yaml_keys_test.yaml WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/test/) # test for ush/jediinc2fv3.py -add_test(NAME GDASApp_jedi_increment_to_fv3 +add_test(NAME test_gdasapp_jedi_increment_to_fv3 COMMAND ${Python3_EXECUTABLE} ${PROJECT_SOURCE_DIR}/ush/jediinc2fv3.py ${PROJECT_BINARY_DIR}/test/testdata/atminc_compress.nc4 ${PROJECT_BINARY_DIR}/test/testdata/fv_increment.nc WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/test/)