-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added code coverage tracking to github action #378
base: devel
Are you sure you want to change the base?
Changes from 8 commits
71614bd
ce3d555
96f3b1a
9c6bc7f
9df92e4
9c8feba
1fed821
f2a5787
c543d79
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
# 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: > | ||
bash coverage_scripts/check_py_coverage.sh -j4 && | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just to confirm -- this doesn't change any functionality, it just cleans up the reporting? since there are no tests run outside of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, because of some strange paths in the github runner, with the previous version all plugin tests for HERON, TEAL, and the ExamplePlugin were being run. This limits it to only the HERON tests. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/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)` | ||
|
||
# get display var | ||
DISPLAY_VAR=`(echo $DISPLAY)` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this not just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't actually have a great understanding of the importance of the |
||
# reset it | ||
export DISPLAY= | ||
|
||
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) | ||
|
||
#get DISPLAY BACK | ||
DISPLAY=$DISPLAY_VAR | ||
|
||
## 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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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%." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so all of these commands have to be within the same
run
command because they rely on having the same environment variable definitions, I presume. all of the&&
s get a little confusing, at least for me, so I think setting some variables at the top of this .yml might help clean up the code? That way you can refer to things likeDATA_FILE
without having to define it all within thisrun
job. See theenv
section defined above thejobs
section here: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables#defining-environment-variables-for-a-single-workflowThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put them all in the same
run
mostly because they're related, so I just assumed that the samerun
would be best for stylistic reasons and just to avoid any potential errors from splitting them up that I might not spot. I agree that it makes more sense to split it though if possible. I can definitely move theDATA_FILE
andCOV_RCFILE
definitions to somewhere more out of the way using theenv
section. I think I can separate thecheck_py_coverage
line out into its ownrun
job as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, since
DATA_FILE
andCOV_RCFILE
definitions both usepwd
, I think I do actually need to define them in the samerun
step as they're used. Thecheck_py_coverage
can still be moved to a differentrun
step though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I would assume that pwd would give about the same value each time (if not, other things would fail I think).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is that, to be accessible where they're used, the environment variables need to either be defined over an entire section with
env
or defined within the samerun
, and inenv
, I don't believe you can run bash commands, includingpwd
.