Skip to content

Code Coverage

Code Coverage #35

name: Code Coverage
on:
workflow_dispatch:
jobs:
run-containers:
runs-on: ubuntu-latest
steps:
# Step 0: Checkout Wrapyfi for upload to codecov
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
# Step 1: Create a local directory with full read-write permissions
- name: Create and verify local directory
run: |
# Create the directory
mkdir -p ${GITHUB_WORKSPACE}/shared_directory
echo "Local directory created"
# Grant full read-write permissions
chmod 777 ${GITHUB_WORKSPACE}/shared_directory
echo "Granted full read-write permissions to the directory"
# Verify creation
if [ -d "${GITHUB_WORKSPACE}/shared_directory" ]; then
echo "Verification: shared_directory exists and is writable"
else
echo "Error: shared_directory was not created successfully"
exit 1
fi
# Step 2: Pull Docker images (remains unchanged)
- name: Pull Docker image DockA
run: docker pull modularml/wrapyfi:0.4.32-zeromq-yarp-ros2
- name: Pull Docker Image DockB
run: docker pull modularml/wrapyfi:0.4.32-zeromq-ros
# Step 3: Run YARP and ROS servers (replace volume mounts with bind mounts)
- name: Run DockA with YARP server
run: docker run --name wrapyfi__yarpserver --net host --rm -d -v ${GITHUB_WORKSPACE}/shared_directory:/tmp/shared_volume modularml/wrapyfi:0.4.32-zeromq-yarp-ros2 yarpserver
- name: Run DockB with ROS server
run: docker run --name wrapyfi__roscore --net host --rm -d -v ${GITHUB_WORKSPACE}/shared_directory:/tmp/shared_volume modularml/wrapyfi:0.4.32-zeromq-ros roscore
# Step 4 & 5 & 6: Install packages, run tests, and append coverage data (replace volume mounts with bind mounts)
- name: Run tests and coverage on DockA
run: |
docker run --name wrapyfi_zeromq_yarp_ros2 --net host --rm -v ${GITHUB_WORKSPACE}/shared_directory:/tmp/shared_volume -w /tmp/shared_volume modularml/wrapyfi:0.4.32-zeromq-yarp-ros2 bash -c "\
yarp detect --write; \
pip install coverage && \
ROS_LOG_DIR=/tmp WRAPYFI_ZEROMQ_PUBSUB_MONITOR_LISTENER_SPAWN=thread WRAPYFI_ZEROMQ_PROXY_BROKER_SPAWN=thread coverage run --source=wrapyfi -m unittest discover -s wrapyfi && \
coverage report --data-file=/tmp/shared_volume/.coverage && \
coverage xml -o /tmp/shared_volume/coverage.xml --data-file=/tmp/shared_volume/.coverage"
# WIP(fabawi): This breaks as coverage tries to append previous source location /opt/conda/.../wrapyfi to current and they don't match
# - name: Run tests and append coverage on DockB. Generate the final report from the combined .coverage file
# run: |
# docker run --name wrapyfi_zeromq_ros --net host --rm -v ${GITHUB_WORKSPACE}/shared_directory:/tmp/shared_volume -w /tmp/shared_volume modularml/wrapyfi:0.4.32-zeromq-ros bash -c "\
# pip install coverage && \
# pip uninstall -y pyzmq && \
# coverage run -a --source=wrapyfi -m unittest discover -s wrapyfi; \
# coverage report --data-file=/tmp/shared_volume/.coverage && \
# coverage xml -o /tmp/shared_volume/coverage.xml --data-file=/tmp/shared_volume/.coverage"
# Step 7: Modify codecov paths
- name: Modify paths in coverage.xml
run: |
cp ${GITHUB_WORKSPACE}/shared_directory/coverage.xml ${GITHUB_WORKSPACE}/coverage.xml
rm ${GITHUB_WORKSPACE}/shared_directory/coverage.xml
sed -i 's|<source></source>|<source>/home/runner/work/wrapyfi/wrapyfi</source>|' ${GITHUB_WORKSPACE}/coverage.xml
sed -i 's|.opt.conda.envs.zeromq_yarp_ros2.lib.python3.10.site-packages.wrapyfi|.|g' ${GITHUB_WORKSPACE}/coverage.xml
sed -i 's|/opt/conda/envs/zeromq_yarp_ros2/lib/python3.10/site-packages/wrapyfi||g' ${GITHUB_WORKSPACE}/coverage.xml
sed -i 's|filename="./|filename="|g' ${GITHUB_WORKSPACE}/coverage.xml
sed -i 's|<package name="..\([^ ]\)|<package name=".\1|g' ${GITHUB_WORKSPACE}/coverage.xml
cat ${GITHUB_WORKSPACE}/coverage.xml # Optional: Print to verify
# Step 8: Upload the coverage report (remains unchanged)
- name: Upload coverage report to Codecov
uses: codecov/codecov-action@v3
with:
file: ${{ github.workspace }}/coverage.xml
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}