diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 9182bf7d..414c83f7 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -17,7 +17,20 @@ jobs: - run: WD=`(cd ../../.. && pwd)` && export RAVEN_LIBS_NAME="raven_libs_"`basename $WD` && ../raven/scripts/establish_conda_env.sh --install - run: cd ../raven && ./build_raven - run: ../raven/run_tests --library-report - - run: ../raven/run_tests -j4 --plugins --re=HERON + # The overhead time added by checking coverage is currently about 19% for a single run_tests. + # Reducing the frequency of coverage checks may be preferable if this increases. + - run: bash coverage_scripts/check_py_coverage.sh -j4 + # report_py_coverage is being called twice, once within check_py_coverage to print to the terminal and once here to get data for the annotation + - run: > + DATA_FILE=`pwd`/.coverage && COV_RCFILE=`pwd`/coverage_scripts/.coveragerc && + COV_RPT=`bash coverage_scripts/report_py_coverage.sh --data-file=$DATA_FILE --coverage-rc-file=$COV_RCFILE` && + echo "::notice title=Coverage Summary::$COV_RPT For details, download 'coverage_results' from Artifacts, extract all files, and open 'index.html'." + - name: Archive coverage results + uses: actions/upload-artifact@v4 + if: always() + with: + name: coverage_results + path: tests/coverage_html_report Test-HERON-Windows: runs-on: [self-hosted, windows] steps: @@ -33,4 +46,4 @@ jobs: - run: $Env:RAVEN_LIBS_NAME = "raven_libraries_"+(Get-Location).Path.Split("\")[-4]; bash ../raven/scripts/establish_conda_env.sh --install --conda-defs $HOME/Miniconda3/etc/profile.d/conda.sh - run: cd ../raven; bash ./build_raven - run: bash ../raven/run_tests --library-report - - run: bash ../raven/run_tests -j4 --plugins --re=HERON + - run: bash ../raven/run_tests -j4 --plugins --re=HERON/tests diff --git a/tests/.coveragerc b/coverage_scripts/.coveragerc similarity index 100% rename from tests/.coveragerc rename to coverage_scripts/.coveragerc diff --git a/coverage_scripts/check_py_coverage.sh b/coverage_scripts/check_py_coverage.sh new file mode 100644 index 00000000..e7bbdb77 --- /dev/null +++ b/coverage_scripts/check_py_coverage.sh @@ -0,0 +1,26 @@ +#!/bin/bash +SCRIPT_DIRNAME=`dirname $0` +HERON_DIR=`(cd $SCRIPT_DIRNAME/..; pwd)` +cd $HERON_DIR +RAVEN_DIR=`python -c 'from src._utils import get_raven_loc; print(get_raven_loc())'` + +source $HERON_DIR/coverage_scripts/initialize_coverage.sh + +#coverage help run +SRC_DIR=`(cd src && pwd)` + +export COVERAGE_RCFILE="$SRC_DIR/../coverage_scripts/.coveragerc" +SOURCE_DIRS=($SRC_DIR,$SRC_DIR/../templates/) +OMIT_FILES=($SRC_DIR/dispatch/twin_pyomo_test.py,$SRC_DIR/dispatch/twin_pyomo_test_rte.py,$SRC_DIR/dispatch/twin_pyomo_limited_ramp.py,$SRC_DIR/ArmaBypass.py) +EXTRA="--source=${SOURCE_DIRS[@]} --omit=${OMIT_FILES[@]} --parallel-mode " +export COVERAGE_FILE=`pwd`/.coverage + +coverage erase +($RAVEN_DIR/run_tests "$@" --re=HERON/tests --python-command="coverage run $EXTRA " || echo run_tests done but some tests failed) + +## Prepare data and generate the html documents +coverage combine +coverage html + +# See report_py_coverage.sh file for explanation of script separation +(bash $HERON_DIR/coverage_scripts/report_py_coverage.sh --data-file=$COVERAGE_FILE --coverage-rc-file=$COVERAGE_RCFILE) diff --git a/check_py_coverage.sh b/coverage_scripts/initialize_coverage.sh old mode 100755 new mode 100644 similarity index 60% rename from check_py_coverage.sh rename to coverage_scripts/initialize_coverage.sh index 3476e0d0..aa588b64 --- a/check_py_coverage.sh +++ b/coverage_scripts/initialize_coverage.sh @@ -1,13 +1,17 @@ #!/bin/bash + +# This script prepares for running commands from the coverage package + SCRIPT_DIRNAME=`dirname $0` -SCRIPT_DIR=`(cd $SCRIPT_DIRNAME; pwd)` +HERON_DIR=`(cd $SCRIPT_DIRNAME/..; pwd)` +echo $HERON_DIR +cd $HERON_DIR RAVEN_DIR=`python -c 'from src._utils import get_raven_loc; print(get_raven_loc())'` source $RAVEN_DIR/scripts/establish_conda_env.sh --quiet --load RAVEN_LIBS_PATH=`conda env list | awk -v rln="$RAVEN_LIBS_NAME" '$0 ~ rln {print $NF}'` BUILD_DIR=${BUILD_DIR:=$RAVEN_LIBS_PATH/build} INSTALL_DIR=${INSTALL_DIR:=$RAVEN_LIBS_PATH} PYTHON_CMD=${PYTHON_CMD:=python} -JOBS=${JOBS:=1} mkdir -p $BUILD_DIR mkdir -p $INSTALL_DIR DOWNLOADER='curl -C - -L -O ' @@ -23,7 +27,7 @@ update_python_path () } update_python_path -PATH=$INSTALL_DIR/bin:$PATH +export PATH=$INSTALL_DIR/bin:$PATH if which coverage then @@ -45,30 +49,3 @@ else fi update_python_path - -cd $SCRIPT_DIR - -#coverage help run -SRC_DIR=`(cd src && pwd)` - -# get display var -DISPLAY_VAR=`(echo $DISPLAY)` -# reset it -export DISPLAY= - -export COVERAGE_RCFILE="$SRC_DIR/../tests/.coveragerc" -SOURCE_DIRS=($SRC_DIR,$SRC_DIR/../templates/) -OMIT_FILES=($SRC_DIR/dispatch/twin_pyomo_test.py,$SRC_DIR/dispatch/twin_pyomo_test_rte.py,$SRC_DIR/dispatch/twin_pyomo_limited_ramp.py,$SRC_DIR/ArmaBypass.py) -EXTRA="--source=${SOURCE_DIRS[@]} --omit=${OMIT_FILES[@]} --parallel-mode " -export COVERAGE_FILE=`pwd`/.coverage - -coverage erase -($RAVEN_DIR/run_tests "$@" --re=HERON/tests --python-command="coverage run $EXTRA " || echo run_tests done but some tests failed) - -#get DISPLAY BACK -DISPLAY=$DISPLAY_VAR - -## Prepare data and generate the html documents -coverage combine -coverage html - diff --git a/coverage_scripts/report_py_coverage.sh b/coverage_scripts/report_py_coverage.sh new file mode 100644 index 00000000..4ba7b65d --- /dev/null +++ b/coverage_scripts/report_py_coverage.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# To be run after a run of check_py_coverage.sh +# This script has been separated from check_py_coverage.sh for the github action, so that +# the output of run_tests within check_py_coverage.sh can be printed, but the report +# value can be caught and put in an annotation. This is necessary because calling +# "coverage report --format=total" directly in the yaml does not work + +SCRIPT_DIRNAME=`dirname $0` +HERON_DIR=`(cd $SCRIPT_DIRNAME/..; pwd)` +cd $HERON_DIR + +source coverage_scripts/initialize_coverage.sh > /dev/null 2>&1 + +# read command-line arguments +ARGS=() +for A in "$@" +do + case $A in + --data-file=*) + export COVERAGE_FILE="${A#--data-file=}" # Removes "--data-file=" and puts path into env variable + ;; + --coverage-rc-file=*) + export COVERAGE_RCFILE="${A#--coverage-rc-file=}" # See above + ;; + *) + ARGS+=("$A") + ;; + esac +done + +COV_VAL=`coverage report --format=total "${ARGS[@]}"` +if [[ $COV_VAL = "No data to report." ]] +then + echo "Could not find data file with coverage results." + exit 0 +fi + +echo "Coverage for this repository is now $COV_VAL%."