44 pull_request :
55 paths :
66 - ' .github/workflows/test-python.yml'
7+ - ' action-setup.sh'
78 - ' compilesketches/**'
89
910 push :
1011 paths :
1112 - ' .github/workflows/test-python.yml'
13+ - ' action-setup.sh'
1214 - ' compilesketches/**'
1315
14- # The actions/setup-python action will periodically break the workflow by dropping the Python version we have pinned
15- # Better to catch that before it causes confusion for a contributor
16+ # Catch issues resulting from new patch releases of Python in the APT repository
1617 schedule :
1718 # run every Tuesday at 3 AM UTC
1819 - cron : " 0 3 * * 2"
@@ -32,29 +33,52 @@ jobs:
3233 env :
3334 PYTHON_PROJECT_PATH : ${GITHUB_WORKSPACE}/compilesketches
3435 PYTHON_PROJECT_TESTS_PATH : ${GITHUB_WORKSPACE}/compilesketches/tests
36+ COVERAGE_DATA_FILENAME : coverage.xml
3537
3638 steps :
3739 - name : Checkout
3840 uses : actions/checkout@v2
3941
40- - name : Set up Python
41- uses : actions/ setup-python@v1
42- with :
43- python-version : ' 3.8.6 '
42+ - name : Run the set up script
43+ id : setup
44+ run : |
45+ "${{ github.workspace }}/action-setup.sh"
4446
45- - name : Install dependencies
47+ - name : Install test dependencies
4648 run : |
47- python -m pip install --upgrade pip
48- pip install --requirement "${{ env.PYTHON_PROJECT_TESTS_PATH }}/requirements.txt"
49+ source "${{ steps.setup.outputs.python-venv-activate-script-path }}"
50+ "${{ steps.setup.outputs.python-command }}" \
51+ -m \
52+ pip install \
53+ --requirement "${{ env.PYTHON_PROJECT_TESTS_PATH }}/requirements.txt"
4954
50- - name : Run Python unit tests and report code coverage
55+ - name : Run Python unit tests and record code coverage data
5156 run : |
57+ source "${{ steps.setup.outputs.python-venv-activate-script-path }}"
5258 export PYTHONPATH="${{ env.PYTHON_PROJECT_PATH }}"
53- coverage run --source="${{ env.PYTHON_PROJECT_PATH }}" --module pytest "${{ env.PYTHON_PROJECT_TESTS_PATH }}"
54- # Display code coverage report in workflow run log
55- coverage report
59+ "${{ steps.setup.outputs.python-command }}" \
60+ -m \
61+ coverage run \
62+ --rcfile="${{ env.PYTHON_PROJECT_TESTS_PATH }}/.coveragerc" \
63+ --source="${{ env.PYTHON_PROJECT_PATH }}" \
64+ --module \
65+ pytest "${{ env.PYTHON_PROJECT_TESTS_PATH }}"
66+ # Generate coverage data file for consumption by `codecov/codecov-action`.
67+ # Otherwise that action generates the file using the system Python environment, which doesn't work.
68+ "${{ steps.setup.outputs.python-command }}" \
69+ -m \
70+ coverage xml \
71+ -o "${{ github.workspace }}/${{ env.COVERAGE_DATA_FILENAME }}"
72+
73+ - name : Display code coverage report
74+ run : |
75+ source "${{ steps.setup.outputs.python-venv-activate-script-path }}"
76+ "${{ steps.setup.outputs.python-command }}" \
77+ -m \
78+ coverage report
5679
5780 - name : Upload coverage report to Codecov
5881 uses : codecov/codecov-action@v1
5982 with :
83+ file : ${{ env.COVERAGE_DATA_FILENAME }}
6084 fail_ci_if_error : true
0 commit comments