Skip to content

Commit

Permalink
Add python coverage to workflow and protobuf code for python client (I…
Browse files Browse the repository at this point in the history
…ntelLabs#77)

* Generate buffer code for python client, update coverage workflow to include python code
* Skip failing tests
  • Loading branch information
cwlacewe authored Dec 13, 2022
1 parent 2673edb commit 0321712
Show file tree
Hide file tree
Showing 9 changed files with 276 additions and 145 deletions.
181 changes: 181 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
name: Compare Coverage

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master and develop branch
on:
pull_request:
types: [ opened, edited, synchronize, reopened ]
branches:
- develop
- master

# Environment variables
env:
GITHUB_PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }}

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
coverage_job:
name: Coverage Test
runs-on:
group: intellabs-generic-runners
labels: vdms-check-in

strategy:
fail-fast: true
matrix:
include:
- coverage_type: Source
container_name: coverage_source_${GITHUB_PULL_REQUEST_NUMBER}
# container_output: coverage_cpp_source_output
container_tag: "vdms:source_coverage"
output_cpp_name: source_coverage_cpp
output_py_name: source_coverage_py
# report_name: source_coverage_report
branch_ref: ${{ github.event.pull_request.head.sha }}
- coverage_type: Target
container_name: coverage_cpp_target_${GITHUB_PULL_REQUEST_NUMBER}
# container_output: coverage_cpp_target_output
container_tag: "vdms:target_coverage"
# output_name: target_coverage
output_cpp_name: target_coverage_cpp
output_py_name: target_coverage_py
# report_name: target_coverage_report
branch_ref: ${{ github.event.pull_request.base.ref }}

outputs:
source_coverage_cpp: ${{ steps.report_coverage.outputs.source_coverage_cpp}}
source_coverage_py: ${{ steps.report_coverage.outputs.source_coverage_py}}
target_coverage_cpp: ${{ steps.report_coverage.outputs.target_coverage_cpp}}
target_coverage_py: ${{ steps.report_coverage.outputs.target_coverage_py}}

# Cancels previous workflows for same PR
concurrency:
group: ${{ matrix.coverage_type }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Clean workspace if git module is found
run: git submodule status || rm -rf "$GITHUB_WORKSPACE"/* "$GITHUB_WORKSPACE"/.gi*

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout ${{ matrix.coverage_type }} Branch
uses: actions/checkout@v3
with:
submodules: true
ref: ${{ matrix.branch_ref }}

- name: Build and Run Docker Container
run: |
set -x
docker stop $(docker ps -aqf "name=${{ matrix.container_name }}") || true
docker rm $(docker ps -aqf "name=${{ matrix.container_name }}") || true
docker build --build-arg MAVEN_OPTS=${{ secrets.MAVEN_OPTS }} \
-f docker/check-in/Dockerfile -t ${{ matrix.container_tag }} .
docker run -d --name ${{ matrix.container_name }} ${{ matrix.container_tag }}
- name: Get ${{ matrix.coverage_type }} Coverage
shell: bash
run: |
set -x
mkdir -p coverage
echo "${{ matrix.container_name }}"
# Make sure CPP coverage script is available
if [ ! -f docker/check-in/run_coverage_cpp.sh ]; then
docker exec ${{ matrix.container_name }} bash -c "touch /run_coverage_cpp.sh && echo 'cd /vdms/tests && chmod +x run_tests.sh && ./run_tests.sh' >> /run_coverage_cpp.sh && chmod +x /run_coverage_cpp.sh && mkdir -p /vdms/tests/coverage_report"
docker exec ${{ matrix.container_name }} bash -c "echo 'gcovr -k --root /vdms -e /vdms/src/pmgd -e /vdms/build/CMakeFiles -f "/vdms/client/.*\.cc" -f "/vdms/ext/.*\.cc" -f "/vdms/src/.*\.cc" -f src/SearchExpression.cc --exclude-unreachable-branches --xml-pretty --xml=/vdms/tests/coverage_report/c_coverage_report.xml --txt=/vdms/tests/coverage_report/c_coverage_report.txt' >> /run_coverage_cpp.sh && echo "echo 'DONE'" >> /run_coverage_cpp.sh"
docker exec ${{ matrix.container_name }} bash -c "echo 'cat /vdms/tests/coverage_report/c_coverage_report.txt' >> /run_coverage_cpp.sh"
fi
# Make sure Python coverage script is available
if [ ! -f docker/check-in/run_coverage_py.sh ]; then
docker exec ${{ matrix.container_name }} bash -c "touch /run_coverage_py.sh && echo 'cd /vdms/tests/python && ./run_python_tests.sh' >> /run_coverage_py.sh && chmod +x /run_coverage_py.sh && mkdir -p /vdms/tests/coverage_report"
docker exec ${{ matrix.container_name }} bash -c "echo 'python -m coverage report > /vdms/tests/coverage_report/py_coverage_report.txt' >> /run_coverage_py.sh && echo "echo 'DONE'" >> /run_coverage_py.sh"
docker exec ${{ matrix.container_name }} bash -c "echo 'cat /vdms/tests/coverage_report/py_coverage_report.txt' >> /run_coverage_py.sh"
fi
docker exec ${{ matrix.container_name }} bash -c "./run_coverage_cpp.sh"
docker cp $(docker ps -a | grep ${{ matrix.container_name }} | awk '{print $1}'):/vdms/tests/coverage_report/c_coverage_report.txt coverage/c_coverage_report_target.txt
docker cp $(docker ps -a | grep ${{ matrix.container_name }} | awk '{print $1}'):/vdms/tests/coverage_report/c_coverage_report.xml coverage/c_coverage_report_target.xml
echo "coverage_value_cpp=$(cat coverage/c_coverage_report_target.xml | grep -oP 'coverage line-rate="([-+]?\d*\.\d+|\d+)"' | grep -oP "[-+]?\d*\.\d+|\d+" | awk '{print $1*100}')" >> $GITHUB_ENV
docker exec ${{ matrix.container_name }} bash -c "./run_coverage_py.sh"
docker cp $(docker ps -a | grep ${{ matrix.container_name }} | awk '{print $1}'):/vdms/tests/coverage_report/py_coverage_report.txt coverage/py_coverage_report_target.txt || true
docker cp $(docker ps -a | grep ${{ matrix.container_name }} | awk '{print $1}'):/vdms/tests/coverage_report/py_coverage_report.xml coverage/py_coverage_report_target.xml || true
if [ ! -f coverage/py_coverage_report_target.xml ] && [ "${{ matrix.coverage_type }}" == "Target" ]; then
echo "coverage_value_py=0" >> $GITHUB_ENV
else
echo "coverage_value_py=$(cat coverage/py_coverage_report_target.xml | grep "coverage version" | grep -oP 'line-rate="([-+]?\d*\.\d+|\d+)"' | grep -oP "[-+]?\d*\.\d+|\d+"| awk '{print $1*100}')" >> $GITHUB_ENV
fi
docker ps -aqf "name=${{ matrix.container_name }}" | xargs docker stop
docker ps -aqf "name=${{ matrix.container_name }}" | xargs docker rm
docker rmi $(docker images | grep '<none>' | awk '{print $3}') || true
- name: Report ${{ matrix.coverage_type }} Coverage
id: report_coverage
run: |
set -x
# CPP
if [[ -z $coverage_value_cpp ]]
then
exit 1
fi
echo "${{ matrix.coverage_type }} CPP Coverage: ${coverage_value_cpp}"
echo "${{ matrix.output_cpp_name }}=${coverage_value_cpp}" >> $GITHUB_OUTPUT
# Python
if [[ -z $coverage_value_py ]]
then
exit 1
fi
echo "${{ matrix.coverage_type }} Python Coverage: ${coverage_value_py}"
echo "${{ matrix.output_py_name }}=${coverage_value_py}" >> $GITHUB_OUTPUT
compare_coverage:
name: Compare Reported Coverage
runs-on:
group: intellabs-generic-runners
labels: vdms-check-in
needs: coverage_job
steps:
- name: Comment Coverage
if: (github.event_name == 'pull_request')
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: ${{ github.event.number }},
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Target CPP Coverage: ${{ needs.coverage_job.outputs.target_coverage_cpp }}%\nSource CPP Coverage: ${{ needs.coverage_job.outputs.source_coverage_cpp }}%\n\n\nTarget Python Coverage: ${{ needs.coverage_job.outputs.target_coverage_py }}%\nSource Python Coverage: ${{ needs.coverage_job.outputs.source_coverage_py }}%'
})
- name: Compare Coverage
run: |
echo "Source CPP Coverage: ${{needs.coverage_job.outputs.source_coverage_cpp}}"
echo "Target CPP Coverage: ${{needs.coverage_job.outputs.target_coverage_cpp}}"
if ${{ needs.coverage_job.outputs.target_coverage_cpp > needs.coverage_job.outputs.source_coverage_cpp }}
then
echo 'CPP Coverage below CPP Target'
exit 1
else
echo "CPP Coverage threshold met!"
fi
echo "Source Python Coverage: ${{needs.coverage_job.outputs.source_coverage_py}}"
echo "Target Python Coverage: ${{needs.coverage_job.outputs.target_coverage_py}}"
if ${{needs.coverage_job.outputs.target_coverage_py}} != 0 && ${{ needs.coverage_job.outputs.target_coverage_py > needs.coverage_job.outputs.source_coverage_py }}
then
echo 'Python coverage below target'
exit 1
else
echo "Python coverage threshold met!"
fi
140 changes: 0 additions & 140 deletions .github/workflows/cpp_coverage.yml

This file was deleted.

Loading

0 comments on commit 0321712

Please sign in to comment.