Skip to content

Commit 9c4e3c5

Browse files
Merge pull request #378 from caleb-sitton-inl/coverage-github-action
Added code coverage tracking to github action
2 parents b9ac072 + c543d79 commit 9c4e3c5

File tree

5 files changed

+87
-32
lines changed

5 files changed

+87
-32
lines changed

.github/workflows/github-actions.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,20 @@ jobs:
1717
- run: WD=`(cd ../../.. && pwd)` && export RAVEN_LIBS_NAME="raven_libs_"`basename $WD` && ../raven/scripts/establish_conda_env.sh --install
1818
- run: cd ../raven && ./build_raven
1919
- run: ../raven/run_tests --library-report
20-
- run: ../raven/run_tests -j4 --plugins --re=HERON
20+
# The overhead time added by checking coverage is currently about 19% for a single run_tests.
21+
# Reducing the frequency of coverage checks may be preferable if this increases.
22+
- run: bash coverage_scripts/check_py_coverage.sh -j4
23+
# 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
24+
- run: >
25+
DATA_FILE=`pwd`/.coverage && COV_RCFILE=`pwd`/coverage_scripts/.coveragerc &&
26+
COV_RPT=`bash coverage_scripts/report_py_coverage.sh --data-file=$DATA_FILE --coverage-rc-file=$COV_RCFILE` &&
27+
echo "::notice title=Coverage Summary::$COV_RPT For details, download 'coverage_results' from Artifacts, extract all files, and open 'index.html'."
28+
- name: Archive coverage results
29+
uses: actions/upload-artifact@v4
30+
if: always()
31+
with:
32+
name: coverage_results
33+
path: tests/coverage_html_report
2134
Test-HERON-Windows:
2235
runs-on: [self-hosted, windows]
2336
steps:
@@ -33,4 +46,4 @@ jobs:
3346
- 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
3447
- run: cd ../raven; bash ./build_raven
3548
- run: bash ../raven/run_tests --library-report
36-
- run: bash ../raven/run_tests -j4 --plugins --re=HERON
49+
- run: bash ../raven/run_tests -j4 --plugins --re=HERON/tests
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
SCRIPT_DIRNAME=`dirname $0`
3+
HERON_DIR=`(cd $SCRIPT_DIRNAME/..; pwd)`
4+
cd $HERON_DIR
5+
RAVEN_DIR=`python -c 'from src._utils import get_raven_loc; print(get_raven_loc())'`
6+
7+
source $HERON_DIR/coverage_scripts/initialize_coverage.sh
8+
9+
#coverage help run
10+
SRC_DIR=`(cd src && pwd)`
11+
12+
export COVERAGE_RCFILE="$SRC_DIR/../coverage_scripts/.coveragerc"
13+
SOURCE_DIRS=($SRC_DIR,$SRC_DIR/../templates/)
14+
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)
15+
EXTRA="--source=${SOURCE_DIRS[@]} --omit=${OMIT_FILES[@]} --parallel-mode "
16+
export COVERAGE_FILE=`pwd`/.coverage
17+
18+
coverage erase
19+
($RAVEN_DIR/run_tests "$@" --re=HERON/tests --python-command="coverage run $EXTRA " || echo run_tests done but some tests failed)
20+
21+
## Prepare data and generate the html documents
22+
coverage combine
23+
coverage html
24+
25+
# See report_py_coverage.sh file for explanation of script separation
26+
(bash $HERON_DIR/coverage_scripts/report_py_coverage.sh --data-file=$COVERAGE_FILE --coverage-rc-file=$COVERAGE_RCFILE)
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
#!/bin/bash
2+
3+
# This script prepares for running commands from the coverage package
4+
25
SCRIPT_DIRNAME=`dirname $0`
3-
SCRIPT_DIR=`(cd $SCRIPT_DIRNAME; pwd)`
6+
HERON_DIR=`(cd $SCRIPT_DIRNAME/..; pwd)`
7+
echo $HERON_DIR
8+
cd $HERON_DIR
49
RAVEN_DIR=`python -c 'from src._utils import get_raven_loc; print(get_raven_loc())'`
510
source $RAVEN_DIR/scripts/establish_conda_env.sh --quiet --load
611
RAVEN_LIBS_PATH=`conda env list | awk -v rln="$RAVEN_LIBS_NAME" '$0 ~ rln {print $NF}'`
712
BUILD_DIR=${BUILD_DIR:=$RAVEN_LIBS_PATH/build}
813
INSTALL_DIR=${INSTALL_DIR:=$RAVEN_LIBS_PATH}
914
PYTHON_CMD=${PYTHON_CMD:=python}
10-
JOBS=${JOBS:=1}
1115
mkdir -p $BUILD_DIR
1216
mkdir -p $INSTALL_DIR
1317
DOWNLOADER='curl -C - -L -O '
@@ -23,7 +27,7 @@ update_python_path ()
2327
}
2428

2529
update_python_path
26-
PATH=$INSTALL_DIR/bin:$PATH
30+
export PATH=$INSTALL_DIR/bin:$PATH
2731

2832
if which coverage
2933
then
@@ -45,30 +49,3 @@ else
4549
fi
4650

4751
update_python_path
48-
49-
cd $SCRIPT_DIR
50-
51-
#coverage help run
52-
SRC_DIR=`(cd src && pwd)`
53-
54-
# get display var
55-
DISPLAY_VAR=`(echo $DISPLAY)`
56-
# reset it
57-
export DISPLAY=
58-
59-
export COVERAGE_RCFILE="$SRC_DIR/../tests/.coveragerc"
60-
SOURCE_DIRS=($SRC_DIR,$SRC_DIR/../templates/)
61-
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)
62-
EXTRA="--source=${SOURCE_DIRS[@]} --omit=${OMIT_FILES[@]} --parallel-mode "
63-
export COVERAGE_FILE=`pwd`/.coverage
64-
65-
coverage erase
66-
($RAVEN_DIR/run_tests "$@" --re=HERON/tests --python-command="coverage run $EXTRA " || echo run_tests done but some tests failed)
67-
68-
#get DISPLAY BACK
69-
DISPLAY=$DISPLAY_VAR
70-
71-
## Prepare data and generate the html documents
72-
coverage combine
73-
coverage html
74-
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
# To be run after a run of check_py_coverage.sh
4+
# This script has been separated from check_py_coverage.sh for the github action, so that
5+
# the output of run_tests within check_py_coverage.sh can be printed, but the report
6+
# value can be caught and put in an annotation. This is necessary because calling
7+
# "coverage report --format=total" directly in the yaml does not work
8+
9+
SCRIPT_DIRNAME=`dirname $0`
10+
HERON_DIR=`(cd $SCRIPT_DIRNAME/..; pwd)`
11+
cd $HERON_DIR
12+
13+
source coverage_scripts/initialize_coverage.sh > /dev/null 2>&1
14+
15+
# read command-line arguments
16+
ARGS=()
17+
for A in "$@"
18+
do
19+
case $A in
20+
--data-file=*)
21+
export COVERAGE_FILE="${A#--data-file=}" # Removes "--data-file=" and puts path into env variable
22+
;;
23+
--coverage-rc-file=*)
24+
export COVERAGE_RCFILE="${A#--coverage-rc-file=}" # See above
25+
;;
26+
*)
27+
ARGS+=("$A")
28+
;;
29+
esac
30+
done
31+
32+
COV_VAL=`coverage report --format=total "${ARGS[@]}"`
33+
if [[ $COV_VAL = "No data to report." ]]
34+
then
35+
echo "Could not find data file with coverage results."
36+
exit 0
37+
fi
38+
39+
echo "Coverage for this repository is now $COV_VAL%."

0 commit comments

Comments
 (0)