Code Coverage #33
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Code Coverage | |
on: | |
workflow_dispatch: | |
jobs: | |
run-containers: | |
runs-on: ubuntu-latest | |
steps: | |
# 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 seems to break after coverage losing track of Wrapyfi's location | |
# - 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: | | |
# Set the <source> correctly | |
sed -i 's|<source></source>|<source>/wrapyfi</source>|' ${GITHUB_WORKSPACE}/shared_directory/coverage.xml | |
sed -i 's|.opt.conda.envs.zeromq_yarp_ros2.lib.python3.10.site-packages.wrapyfi|.|g' ${GITHUB_WORKSPACE}/shared_directory/coverage.xml | |
sed -i 's|/opt/conda/envs/zeromq_yarp_ros2/lib/python3.10/site-packages/wrapyfi||g' ${GITHUB_WORKSPACE}/shared_directory/coverage.xml | |
sed -i 's|filename="./|filename="|g' ${GITHUB_WORKSPACE}/shared_directory/coverage.xml | |
sed -i 's|<package name="..\([^ ]\)|<package name=".\1|g' ${GITHUB_WORKSPACE}/shared_directory/coverage.xml | |
cat ${GITHUB_WORKSPACE}/shared_directory/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 }}/shared_directory/coverage.xml | |
env: | |
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |