-
Notifications
You must be signed in to change notification settings - Fork 55
72 lines (58 loc) · 2.43 KB
/
unit_test_coverage.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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