diff --git a/regression_scripts/build_pmesdr.sh b/regression_scripts/build_pmesdr.sh index d4539945..38733d08 100755 --- a/regression_scripts/build_pmesdr.sh +++ b/regression_scripts/build_pmesdr.sh @@ -8,11 +8,15 @@ # This script requires the name of a conda env to use to run the unit tests for CETB # comparison utilities. +# If any simple step or pipeline fails, this script will fail +set -eo pipefail + error_exit() { # Use for fatal program error # Argument: # optional string containing descriptive error message # if no error message, prints "Unknown Error" + # Assumes caller has done set_pmesdr_environment.sh echo "build_pmesdr.sh: ERROR: ${1:-"Unknown Error"}" 1>&2 return -1 @@ -29,5 +33,3 @@ cd ${PMESDR_TOP_DIR}/python source activate $condaenv nosetests test_cetb_utilities.py || error_exit "unit tests failed" -# End of example job shell script -# diff --git a/regression_scripts/git_pull.sh b/regression_scripts/git_pull.sh index 73dbe4c4..46810329 100755 --- a/regression_scripts/git_pull.sh +++ b/regression_scripts/git_pull.sh @@ -1,4 +1,6 @@ #!/bin/bash -l +# If any simple step or pipeline fails, this script will fail +set -eo pipefail PROGNAME=$(basename $0) @@ -7,14 +9,14 @@ error_exit() { # Argument: # optional string containing descriptive error message # if no error message, prints "Unknown Error" + # Assumes user has done set_pmesdr_environment.sh echo "${PROGNAME}: ERROR: ${1:-"Unknown Error"}" 1>&2 - exit -1 + return -1 } printf "%s: On %s, fetching latest software changes...\n" ${PROGNAME} $(hostname) -source /projects/$USER/PMESDR_regression/src/prod/set_pmesdr_environment.sh cd $PMESDR_TOP_DIR || error_exit "$LINENO: Error changing to PMESDR_TOP_DIR." git pull || error_exit "$LINENO: Error on git pull." git status diff --git a/regression_scripts/pull_build_and_run_regression.sh b/regression_scripts/pull_build_and_run_regression.sh new file mode 100755 index 00000000..5d89def8 --- /dev/null +++ b/regression_scripts/pull_build_and_run_regression.sh @@ -0,0 +1,33 @@ +#!/bin/bash -l +# +# Re-builds a fresh copy of the system at PMESDR_TOP_DIR, runs unit tests and +# either quick or daily regression +# +# Assumes the user has set the bash environment with set_pmesdr_environment.sh +# + +# If any simple step or pipeline fails, this script will fail +# thanks to this page for this tip: +# https://stackoverflow.com/questions/821396/aborting-a-shell-script-if-any-command-returns-a-non-zero-value +set -eo pipefail + +error_exit() { + # Use for fatal program error + # Argument: + # optional string containing descriptive error message + # if no error message, prints "Unknown Error" + + echo "pull_build_and_run_regression.sh: ERROR: ${1:-"Unknown Error"}" 1>&2 + return 1 +} + +REGRESSIONTYPE=$1 + +source ${PMESDR_TOP_DIR}/regression_scripts/git_pull.sh || \ + error_exit "failed to git pull from remote" +source ${PMESDR_TOP_DIR}/regression_scripts/build_pmesdr.sh ${PMESDR_CONDAENV} || \ + error_exit "failed to build system" +source ${PMESDR_TOP_DIR}/regression_scripts/run_regression.sh \ + ${REGRESSIONTYPE} ${PMESDR_CONDAENV} || \ + error_exit "failed to run regression" + diff --git a/regression_scripts/run_regression.sh b/regression_scripts/run_regression.sh index 3c311357..b53e38fc 100755 --- a/regression_scripts/run_regression.sh +++ b/regression_scripts/run_regression.sh @@ -9,7 +9,11 @@ # # It is assumed that the caller has set the system location to # $PMESDR_TOP_DIR -# +# + +# If any simple step or pipeline fails, this script will fail +set -eo pipefail + regressiontype=$1 condaenv=$2 @@ -42,7 +46,6 @@ echo "`basename $0`: Regression type is $regressiontype" echo "`basename $0`: Conda env is $condaenv" echo "`basename $0`: Make target is $maketarget" -source ${PMESDR_TOP_DIR}/src/prod/set_pmesdr_environment.sh eval "$(conda shell.bash hook)" conda activate ${condaenv} date diff --git a/src/prod/Makefile b/src/prod/Makefile index afe13c96..76454732 100644 --- a/src/prod/Makefile +++ b/src/prod/Makefile @@ -23,6 +23,13 @@ BINDIR = $(TOPDIR)/bin # SHELL = /bin/sh +# Note that the extra activate is needed to ensure that the +# activate floats env to the front of PATH +# Thanks to this web site for the tip on how to use conda envs +# from a makefile: +# https://blog.ianpreston.ca/posts/2020-05-13-conda_envs.html +CONDA_ACTIVATE=source $$(conda info --base)/etc/profile.d/conda.sh ; conda activate ; conda activate + # # C compiler options, debug or optimization settings # @@ -90,9 +97,13 @@ regression-setup: conda-env: conda create -y -n $(CONDAENV) gsx; \ - conda activate $(CONDAENV); \ + $(CONDA_ACTIVATE) $(CONDAENV); \ pip install pynose +clean-conda: + $(CONDA_ACTIVATE) base; \ + conda remove -n $(CONDAENV) --all + unit-test: ${PMESDR_TOP_DIR}/regression_scripts/build_pmesdr.sh $(CONDAENV)