UnitTestCoverage #5
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: UnitTestCoverage | |
on: workflow_dispatch | |
jobs: | |
check-coverage: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.9' | |
- name: Make Temp Dir for Artifacts | |
run: | | |
mkdir coverageDir | |
touch coverageDir/coverage.csv | |
- name: Run Coverage on Plugin Unit Tests | |
run: | | |
set +e | |
cd plugins | |
for plugin in ${{ secrets.PLUGIN_COVERAGE }} | |
do | |
cd $plugin | |
echo $plugin | |
# checking if plugin has unit tests. if not percentage set to 0 and skip everything else. | |
if [ ! -d "unit_test" ]; then | |
PERCENTAGE="0%" | |
echo "No Unit Test Found." | |
else | |
# Creating venv so we can install required libraries and later delete them to avoid conflicts | |
python3 -m venv venv | |
source venv/bin/activate | |
# setuptools is version pinned here to avoid an import compatibility issue with 2to3 | |
echo Installing required libraries | |
pip3 install -q setuptools==41.2.0 --no-cache-dir --disable-pip-version-check | |
pip3 install -q coverage insightconnect_plugin_runtime --no-cache-dir --disable-pip-version-check | |
pip3 install -r requirements.txt --no-cache-dir --disable-pip-version-check | |
# Exporting PYTHONPATH to plugins unit test directory so all imports are found | |
export PYTHONPATH=$(pwd)/unit_test/ | |
# Running Coverage and collecting total coverage | |
coverage run -m unittest | |
output=$(python3 -m coverage report --data-file=$data_file) | |
PERCENTAGE=$(echo $output | grep TOTAL | awk '{print $NF}') | |
fi | |
# Writing plugin name and coverage percentage to file | |
echo "$plugin, $PERCENTAGE" >> ../../coverageDir/coverage.csv | |
# Deactivating and deleting venv to prepare for next plugin if exists | |
if [ -d "venv" ]; then | |
deactivate | |
rm -r venv | |
fi | |
cd ../ | |
done | |
- name: Upload Coverage | |
uses: actions/upload-artifact@v3 | |
with: | |
name: coverage | |
path: coverageDir |