Test runner #62
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: unit-tests | |
on: | |
pull_request: | |
push: | |
branches: | |
- master | |
jobs: | |
run-tests: | |
name: ${{ matrix.shard_name }}(py=${{ matrix.python-version }},dj=${{ matrix.django-version }},mongo=${{ matrix.mongo-version }}) | |
runs-on: [ "ubuntu-20.04" ] | |
strategy: | |
matrix: | |
python-version: | |
- "3.11" | |
django-version: | |
- "pinned" | |
# When updating the shards, remember to make the same changes in | |
# .github/workflows/unit-tests-gh-hosted.yml | |
shard_name: | |
- "lms-1" | |
- "lms-2" | |
- "lms-3" | |
- "lms-4" | |
- "lms-5" | |
- "lms-6" | |
- "openedx-1-with-lms" | |
- "openedx-2-with-lms" | |
- "openedx-1-with-cms" | |
- "openedx-2-with-cms" | |
- "cms-1" | |
- "cms-2" | |
- "common-with-lms" | |
- "common-with-cms" | |
- "xmodule-with-lms" | |
- "xmodule-with-cms" | |
mongo-version: | |
- "7.0" | |
# We only need to test older versions of Mongo with modules that directly interface with Mongo (that is: xmodule.modulestore) | |
# This code is left here as an example for future refernce in case we need to reduce the number of shards we're | |
# testing but still have good confidence with older versions of mongo. We use Mongo 4.4 in the example. | |
# | |
# exclude: | |
# - mongo-version: "4.4" | |
# include: | |
# - shard_name: "xmodule-with-cms" | |
# python-version: "3.11" | |
# django-version: "pinned" | |
# mongo-version: "4.4" | |
# - shard_name: "xmodule-with-lms" | |
# python-version: "3.11" | |
# django-version: "pinned" | |
# mongo-version: "4.4" | |
steps: | |
- name: checkout repo | |
uses: actions/checkout@v4 | |
- name: install system requirements | |
run: | | |
sudo apt-get update && sudo apt-get install libmysqlclient-dev libxmlsec1-dev lynx | |
- name: install mongo version | |
run: | | |
if [[ "${{ matrix.mongo-version }}" != "4.4" ]]; then | |
wget -qO - https://www.mongodb.org/static/pgp/server-${{ matrix.mongo-version }}.asc | sudo apt-key add - | |
echo "deb https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/${{ matrix.mongo-version }} multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-${{ matrix.mongo-version }}.list | |
sudo apt-get update && sudo apt-get install -y mongodb-org="${{ matrix.mongo-version }}.*" | |
fi | |
- name: start mongod server for tests | |
run: | | |
sudo mkdir -p /data/db | |
sudo chmod -R a+rw /data/db | |
mongod & | |
- name: Setup Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: install requirements | |
run: | | |
make test-requirements | |
if [[ "${{ matrix.django-version }}" != "pinned" ]]; then | |
pip install "django~=${{ matrix.django-version }}.0" | |
pip check # fail if this test-reqs/Django combination is broken | |
fi | |
- name: list installed package versions | |
run: | | |
pip freeze | |
- name: Setup and run tests | |
uses: ./.github/actions/unit-tests | |
- name: Renaming coverage data file | |
if: (github.repository == 'edx/edx-platform-private') || (github.repository == 'openedx/edx-platform' && (startsWith(github.base_ref, 'open-release') == false)) | |
run: | | |
mv reports/.coverage reports/${{ matrix.shard_name }}.coverage | |
- name: Upload coverage | |
if: (github.repository == 'edx/edx-platform-private') || (github.repository == 'openedx/edx-platform' && (startsWith(github.base_ref, 'open-release') == false)) | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coverage | |
path: reports/${{matrix.shard_name}}.coverage | |
overwrite: true | |
# This job aggregates test results. It's the required check for branch protection. | |
# https://github.com/marketplace/actions/alls-green#why | |
# https://github.com/orgs/community/discussions/33579 | |
success: | |
name: Unit tests successful | |
if: (github.repository == 'edx/edx-platform-private') || (github.repository == 'openedx/edx-platform' && (startsWith(github.base_ref, 'open-release') == false)) | |
needs: | |
- run-tests | |
runs-on: [ "ubuntu-20.04" ] | |
steps: | |
- name: Decide whether the needed jobs succeeded or failed | |
# uses: re-actors/[email protected] | |
uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe | |
with: | |
jobs: ${{ toJSON(needs) }} | |
compile-warnings-report: | |
runs-on: [ "ubuntu-20.04" ] | |
if: (github.repository == 'edx/edx-platform-private') || (github.repository == 'openedx/edx-platform' && (startsWith(github.base_ref, 'open-release') == false)) | |
needs: [ run-tests ] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: collect pytest warnings files | |
uses: actions/download-artifact@v4 | |
with: | |
name: pytest-warnings-json | |
path: test_root/log | |
- name: display structure of downloaded files | |
run: ls -la test_root/log | |
- name: compile warnings report | |
run: | | |
python openedx/core/process_warnings.py --dir-path test_root/log --html-path reports/pytest_warnings/warning_report_all.html | |
- name: save warning report | |
if: success() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: pytest-warning-report-html | |
path: | | |
reports/pytest_warnings/warning_report_all.html | |
overwrite: true | |
# Combine and upload coverage reports. | |
coverage: | |
needs: run-tests | |
if: (github.repository == 'edx/edx-platform-private') || (github.repository == 'openedx/edx-platform' && (startsWith(github.base_ref, 'open-release') == false)) | |
runs-on: [ "ubuntu-20.04" ] | |
strategy: | |
matrix: | |
python-version: | |
- 3.11 | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- name: Setup Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Download all artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: coverage | |
path: reports | |
- name: Install Python dependencies | |
run: | | |
pip install -r requirements/edx/coverage.txt | |
- name: Run coverage | |
run: | | |
coverage combine reports/* | |
coverage report | |
coverage xml | |
- uses: codecov/codecov-action@v4 |