forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move unit tests to github actions on self-hosted runners (opene…
- Loading branch information
Showing
5 changed files
with
161 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
name: unit-tests | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
run-tests: | ||
runs-on: [ self-hosted ] | ||
strategy: | ||
matrix: | ||
python-version: ['3.8'] | ||
django-version: ["3.2"] | ||
test_module: [ | ||
"lms/djangoapps/badges/ lms/djangoapps/branding/ lms/djangoapps/bulk_email/ lms/djangoapps/bulk_enroll/ lms/djangoapps/bulk_user_retirement/ lms/djangoapps/ccx/ lms/djangoapps/certificates/ lms/djangoapps/commerce/", | ||
"lms/djangoapps/course_api/ lms/djangoapps/course_blocks/ lms/djangoapps/course_goals/ lms/djangoapps/course_home_api/ lms/djangoapps/course_wiki/ lms/djangoapps/coursewarehistoryextended/ lms/djangoapps/dashboard/ lms/djangoapps/debug/", | ||
"lms/djangoapps/courseware/", | ||
"lms/djangoapps/discussion/ lms/djangoapps/edxnotes/ lms/djangoapps/email_marketing/ lms/djangoapps/experiments/", | ||
"lms/djangoapps/gating/ lms/djangoapps/grades/ lms/djangoapps/instructor/ lms/djangoapps/instructor_analytics/", | ||
"lms/djangoapps/instructor_task/ lms/djangoapps/learner_dashboard/ lms/djangoapps/lms_initialization/ lms/djangoapps/lms_xblock/ lms/djangoapps/lti_provider/ lms/djangoapps/mailing/ lms/djangoapps/mobile_api/ lms/djangoapps/monitoring/ lms/djangoapps/program_enrollments/ lms/djangoapps/rss_proxy/ lms/djangoapps/static_template_view/ lms/djangoapps/staticbook/ lms/djangoapps/support/ lms/djangoapps/survey/ lms/djangoapps/teams/ lms/djangoapps/tests/ lms/djangoapps/verify_student/ lms/envs/ lms/lib/ lms/tests.py", | ||
"openedx/core/djangoapps/ace_common/ openedx/core/djangoapps/cors_csrf/ openedx/core/djangoapps/agreements/ openedx/core/djangoapps/api_admin/ openedx/core/djangoapps/auth_exchange/ openedx/core/djangoapps/bookmarks/ openedx/core/djangoapps/cache_toolbox/ openedx/core/djangoapps/catalog/ openedx/core/djangoapps/ccxcon/ openedx/core/djangoapps/commerce/ openedx/core/djangoapps/common_initialization/ openedx/core/djangoapps/common_views/ openedx/core/djangoapps/config_model_utils/ openedx/core/djangoapps/content/ openedx/core/djangoapps/content_libraries/ openedx/core/djangoapps/contentserver/ openedx/core/djangoapps/cookie_metadata/ openedx/core/djangoapps/course_apps/ openedx/core/djangoapps/course_date_signals/ openedx/core/djangoapps/course_groups/ openedx/core/djangoapps/coursegraph/ openedx/core/djangoapps/courseware_api/ openedx/core/djangoapps/crawlers/ openedx/core/djangoapps/credentials/ openedx/core/djangoapps/credit/ openedx/core/djangoapps/dark_lang/ openedx/core/djangoapps/debug/ openedx/core/djangoapps/demographics/ openedx/core/djangoapps/discussions/ openedx/core/djangoapps/django_comment_common/ openedx/core/djangoapps/embargo/ openedx/core/djangoapps/enrollments/ openedx/core/djangoapps/external_user_ids/", | ||
"openedx/core/djangoapps/geoinfo/ openedx/core/djangoapps/header_control/ openedx/core/djangoapps/heartbeat/ openedx/core/djangoapps/lang_pref/ openedx/core/djangoapps/models/ openedx/core/djangoapps/monkey_patch/ openedx/core/djangoapps/oauth_dispatch/ openedx/core/djangoapps/olx_rest_api/ openedx/core/djangoapps/password_policy/ openedx/core/djangoapps/plugin_api/ openedx/core/djangoapps/plugins/ openedx/core/djangoapps/profile_images/ openedx/core/djangoapps/programs/ openedx/core/djangoapps/safe_sessions/ openedx/core/djangoapps/schedules/ openedx/core/djangoapps/self_paced/ openedx/core/djangoapps/service_status/ openedx/core/djangoapps/session_inactivity_timeout/ openedx/core/djangoapps/signals/ openedx/core/djangoapps/site_configuration/ openedx/core/djangoapps/system_wide_roles/ openedx/core/djangoapps/theming/ openedx/core/djangoapps/user_api/ openedx/core/djangoapps/user_authn/ openedx/core/djangoapps/util/ openedx/core/djangoapps/verified_track_content/ openedx/core/djangoapps/video_config/ openedx/core/djangoapps/video_pipeline/ openedx/core/djangoapps/waffle_utils/ openedx/core/djangoapps/xblock/ openedx/core/djangoapps/xmodule_django/ openedx/core/djangoapps/zendesk_proxy/ openedx/core/djangolib/ openedx/core/lib/ openedx/core/tests/ openedx/core/tests/ openedx/features/ openedx/testing/ openedx/tests/", | ||
"cms/djangoapps/api/ cms/djangoapps/cms_user_tasks/ cms/djangoapps/course_creators/ cms/djangoapps/export_course_metadata/ cms/djangoapps/maintenance/ cms/djangoapps/models/ cms/djangoapps/pipeline_js/ cms/djangoapps/xblock_config/ cms/envs/ cms/lib/", | ||
"cms/djangoapps/contentstore/", | ||
"common/djangoapps/", | ||
"common/lib/", | ||
] | ||
|
||
|
||
name: python ${{ matrix.python-version }},django ${{ matrix.django-version }} ${{ matrix.test_module }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: start mongodb service | ||
run: | | ||
sudo /etc/init.d/mongodb start | ||
- name: set top-level module name | ||
run: | | ||
echo "module_name=$(echo '${{ matrix.test_module }}' | awk -F '/' '{print $1}')" >> $GITHUB_ENV | ||
- name: set settings path | ||
run: | | ||
echo "settings_path=$(if [ '${{ env.module_name }}' = 'cms' ]; then echo 'cms.envs.test'; else echo 'lms.envs.test' ; fi)" >> $GITHUB_ENV | ||
# - name: set pytest randomly option | ||
# run: | | ||
# echo "pytest_randomly_option=$(if [ '${{ env.module_name }}' = 'cms' ] || [ '${{ env.module_name }}' = 'common' ]; then echo '-p no:randomly'; else echo '' ; fi)" >> $GITHUB_ENV | ||
|
||
- name: install requirements | ||
run: | | ||
sudo pip install -r requirements/pip.txt | ||
sudo pip install -r requirements/edx/testing.txt | ||
sudo pip install "django~=${{ matrix.django-version }}.0" | ||
- name: run tests | ||
run: | | ||
python -Wd -m pytest -p no:randomly --ds=${{ env.settings_path }} ${{ matrix.test_module }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
name: verify unit tests count | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
collect-and-verify: | ||
runs-on: [ self-hosted ] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: install requirements | ||
run: | | ||
sudo pip install -r requirements/pip.txt | ||
sudo pip install -r requirements/edx/testing.txt | ||
- name: collect tests from all modules | ||
run: | | ||
echo "root_cms_unit_tests_count=$(pytest --collect-only --ds=cms.envs.test cms/ -q | head -n -2 | wc -l)" >> $GITHUB_ENV | ||
echo "root_lms_unit_tests_count=$(pytest --collect-only --ds=lms.envs.test lms/ openedx/ common/djangoapps/ common/lib/ -q | head -n -2 | wc -l)" >> $GITHUB_ENV | ||
- name: get GHA unit test paths | ||
run: | | ||
echo "cms_unit_test_paths=$(python scripts/gha_unit_tests_collector.py --cms-only)" >> $GITHUB_ENV | ||
echo "lms_unit_test_paths=$(python scripts/gha_unit_tests_collector.py --lms-only)" >> $GITHUB_ENV | ||
- name: collect tests from GHA unit test shards | ||
run: | | ||
echo "cms_unit_tests_count=$(pytest --collect-only --ds=cms.envs.test ${{ env.cms_unit_test_paths }} -q | head -n -2 | wc -l)" >> $GITHUB_ENV | ||
echo "lms_unit_tests_count=$(pytest --collect-only --ds=lms.envs.test ${{ env.lms_unit_test_paths }} -q | head -n -2 | wc -l)" >> $GITHUB_ENV | ||
- name: add unit tests count | ||
run: | | ||
echo "root_all_unit_tests_count=$((${{ env.root_cms_unit_tests_count }}+${{ env.root_lms_unit_tests_count }}))" >> $GITHUB_ENV | ||
echo "shards_all_unit_tests_count=$((${{ env.cms_unit_tests_count }}+${{ env.lms_unit_tests_count }}))" >> $GITHUB_ENV | ||
- name: print unit tests count | ||
run: | | ||
echo CMS unit tests from root: ${{ env.root_cms_unit_tests_count }} | ||
echo LMS unit tests from root: ${{ env.root_lms_unit_tests_count }} | ||
echo CMS unit tests from shards: ${{ env.cms_unit_tests_count }} | ||
echo LMS unit tests from shards: ${{ env.lms_unit_tests_count }} | ||
echo All root unit tests count: ${{ env.root_all_unit_tests_count }} | ||
echo All shards unit tests count: ${{ env.shards_all_unit_tests_count }} | ||
- name: verify unit tests count | ||
if: ${{ env.root_all_unit_tests_count != env.shards_all_unit_tests_count }} | ||
run: | | ||
echo "::error title='Unit test modules in unit-tests.yml workflow are outdated'::unit tests running in unit-tests workflow don't match the count for unit tests for entire edx-platform suite, please update the test_module under matrix to add any missing apps and match the count" | ||
exit 1 |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import sys | ||
import os | ||
import yaml | ||
import argparse | ||
|
||
|
||
def get_all_unit_test_modules(): | ||
unit_tests_yml = f'{os.getcwd()}/.github/workflows/unit-tests.yml' | ||
with open(unit_tests_yml) as file: | ||
unit_test_workflow_yaml = yaml.safe_load(file) | ||
|
||
return unit_test_workflow_yaml['jobs']['run-tests']['strategy']['matrix']['test_module'] | ||
|
||
|
||
def get_modules_except_cms(): | ||
all_unit_test_modules = get_all_unit_test_modules() | ||
return [module for module in all_unit_test_modules if not module.startswith('cms')] | ||
|
||
|
||
def get_cms_modules(): | ||
all_unit_test_modules = get_all_unit_test_modules() | ||
return [module for module in all_unit_test_modules if module.startswith('cms')] | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--cms-only", action="store_true", default="") | ||
parser.add_argument("--lms-only", action="store_true", default="") | ||
|
||
argument = parser.parse_args() | ||
|
||
if argument.lms_only: | ||
modules = get_modules_except_cms() | ||
elif argument.cms_only: | ||
modules = get_cms_modules() | ||
else: | ||
modules = get_all_unit_test_modules() | ||
|
||
unit_test_paths = ' '.join(modules) | ||
sys.stdout.write(unit_test_paths) |