Skip to content

Commit

Permalink
Port back-end tests from Travis to CircleCI (oppia#6234)
Browse files Browse the repository at this point in the history
* Basic config

* Minor nit

* Test caching mechanism

* Try integration of frontend and backend tests

* Syntax fix

* Add defaults back to each job

* Add checkout for each job

* Add checkout to setup job

* Add anchor for restore_cache

* Add e2e tests accessiblity

* Add third_party_cache and setup_cache key

* Fix cache paths

* Change working dir path

* Use abs paths for cache

* Try specifying chrome version

* Add libappindicator

* Tweak

* Try fixing path and run only e2e tests

* Add lint, frontend and backend tests to config.yml

* Remove lint, frontend and backend tests from travis.yml

* Remove undefined anchor

* Fix yml

* Install dependencies

* Minor tweaks

* Move init hook to Master section in pylintrc

* Test commit: try changing the working dir

* Port backend tests from Travis to CircleCi

* Revert changes made in pylintrc

* Revert changes to Travis and comment out backend and frontend tests' run

* Run frontend and generate coverage

* Install codecov as a dependency

* Add sudo to overcome permission error

* Re-order codecov install

* Add branches to be build and try enabling backend test coverage

* Fix config

* Remove branch section

* Try: lint tests

* Try: lint tests

* Try: Add dependency installation to lint tests job

* Try: Caching

* Try: Caching

* Try: Caching

* Try: Caching

* Try: Caching

* Try: Caching

* Run lint, frontend and backend tests

* Generate date for each job

* Comment out lint test and re-order third party installation

* Fix Travis

* Remove --generate_coverage_report flag from backend tests job

* Add explanation to travis config for commenting checks out

* Re-order dependency install

* Re-order dependency

* Revert: Remove --generate_coverage_report flag from backend tests job

* Remove third party install from lint check
  • Loading branch information
apb7 authored and seanlip committed Feb 24, 2019
1 parent 8cf247b commit 7f41f75
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 12 deletions.
103 changes: 103 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
var_for_docker_image: &docker_image circleci/python:2.7.14-jessie-browsers

anchor_for_job_defaults: &job_defaults
working_directory: /home/circleci/oppia
docker:
- image: *docker_image

anchor_for_installing_dependencies: &install_dependencies
name: Install dependencies
command: |
source scripts/setup.sh || exit 1
source scripts/setup_gae.sh || exit 1
anchor_for_restoring_cache: &restore_cache
keys:
- setup-files-cache-{{ checksum "date" }}
- third-party-cache-{{ checksum "date" }}

version: 2
jobs:
setup:
<<: *job_defaults
steps:
- checkout
- run: date +%F > date
- restore_cache:
<<: *restore_cache
- run:
<<: *install_dependencies
- save_cache:
key: setup-files-cache-{{ checksum "date" }}
paths:
- ../node_modules/
- ../oppia_tools/

lint_tests:
<<: *job_defaults
steps:
- checkout
- run: date +%F > date
- restore_cache:
<<: *restore_cache
- run:
name: Run lint tests
command: |
bash scripts/install_third_party.sh
python scripts/third_party_size_check.py
python scripts/pre_commit_linter.py --path=.
- save_cache:
key: third-party-cache-{{ checksum "date" }}
paths:
- third_party/

frontend_tests:
<<: *job_defaults
steps:
- checkout
- run: date +%F > date
- restore_cache:
<<: *restore_cache
- run:
name: Run frontend tests
command: |
bash -x scripts/run_frontend_tests.sh --run-minified-tests=true
- run:
name: Generate frontend coverage report
command: |
sudo pip install codecov
codecov --file ../karma_coverage_reports/coverage-final.json
when: on_success

backend_tests:
<<: *job_defaults
steps:
- checkout
- run: date +%F > date
- restore_cache:
<<: *restore_cache
- run:
name: Run backend tests
command: |
bash scripts/run_backend_tests.sh --generate_coverage_report --exclude_load_tests
- run:
name: Generate backend coverage report
command: |
sudo pip install codecov
codecov
when: on_success

workflows:
version: 2
circleci_tests:
jobs:
- setup
- lint_tests:
requires:
- setup
- frontend_tests:
requires:
- setup
- backend_tests:
requires:
- setup
31 changes: 19 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ branches:

env:
matrix:
- RUN_LINT=true
- RUN_FRONTEND_TESTS=true
- RUN_BACKEND_TESTS=true REPORT_BACKEND_COVERAGE=false EXCLUDE_LOAD_TESTS=true
# These lines are commented out because these checks are being run on CircleCI
# here: https://circleci.com/gh/oppia/oppia
# - RUN_LINT=true
# - RUN_FRONTEND_TESTS=true
# - RUN_BACKEND_TESTS=true REPORT_BACKEND_COVERAGE=false EXCLUDE_LOAD_TESTS=true
# TODO(sll): Reinstate this when we can get it to run in reasonable time.
# - RUN_BACKEND_TESTS=true REPORT_BACKEND_COVERAGE=true
# TODO(sll): Reinstate this when the load tests are more reliable.
Expand Down Expand Up @@ -98,16 +100,19 @@ install:
- pushd $TRAVIS_BUILD_DIR
- source scripts/setup.sh || exit 1
- source scripts/setup_gae.sh || exit 1
- bash scripts/install_third_party.sh

script:
- if [ "$RUN_LINT" == 'true' ]; then bash scripts/install_third_party.sh; python scripts/third_party_size_check.py; python scripts/pre_commit_linter.py --path=.; fi
# These lines are commented out because these checks are being run on CircleCI
# here: https://circleci.com/gh/oppia/oppia
# - if [ "$RUN_LINT" == 'true' ]; then python scripts/third_party_size_check.py; python scripts/pre_commit_linter.py --path=.; fi
# Travis aborts test run if nothing is printed back to STDOUT for some time.
# -x is used to avoid that.
- if [ "$RUN_FRONTEND_TESTS" == 'true' ]; then travis_retry bash -x scripts/run_frontend_tests.sh --run-minified-tests=true; fi
- if [ "$RUN_BACKEND_TESTS" == 'true' ] && [ "$REPORT_BACKEND_COVERAGE" == 'true' ] && [ "$EXCLUDE_LOAD_TESTS" == 'true' ]; then bash scripts/run_backend_tests.sh --generate_coverage_report --exclude_load_tests; fi
- if [ "$RUN_BACKEND_TESTS" == 'true' ] && [ "$REPORT_BACKEND_COVERAGE" == 'false' ] && [ "$EXCLUDE_LOAD_TESTS" == 'true' ]; then bash scripts/run_backend_tests.sh --exclude_load_tests; fi
- if [ "$RUN_BACKEND_TESTS" == 'true' ] && [ "$REPORT_BACKEND_COVERAGE" == 'true' ] && [ "$EXCLUDE_LOAD_TESTS" == 'false' ]; then bash scripts/run_backend_tests.sh --generate_coverage_report; fi
- if [ "$RUN_BACKEND_TESTS" == 'true' ] && [ "$REPORT_BACKEND_COVERAGE" == 'false' ] && [ "$EXCLUDE_LOAD_TESTS" == 'false' ]; then bash scripts/run_backend_tests.sh; fi
# - if [ "$RUN_FRONTEND_TESTS" == 'true' ]; then travis_retry bash -x scripts/run_frontend_tests.sh --run-minified-tests=true; fi
# - if [ "$RUN_BACKEND_TESTS" == 'true' ] && [ "$REPORT_BACKEND_COVERAGE" == 'true' ] && [ "$EXCLUDE_LOAD_TESTS" == 'true' ]; then bash scripts/run_backend_tests.sh --generate_coverage_report --exclude_load_tests; fi
# - if [ "$RUN_BACKEND_TESTS" == 'true' ] && [ "$REPORT_BACKEND_COVERAGE" == 'false' ] && [ "$EXCLUDE_LOAD_TESTS" == 'true' ]; then bash scripts/run_backend_tests.sh --exclude_load_tests; fi
# - if [ "$RUN_BACKEND_TESTS" == 'true' ] && [ "$REPORT_BACKEND_COVERAGE" == 'true' ] && [ "$EXCLUDE_LOAD_TESTS" == 'false' ]; then bash scripts/run_backend_tests.sh --generate_coverage_report; fi
# - if [ "$RUN_BACKEND_TESTS" == 'true' ] && [ "$REPORT_BACKEND_COVERAGE" == 'false' ] && [ "$EXCLUDE_LOAD_TESTS" == 'false' ]; then bash scripts/run_backend_tests.sh; fi
# Run e2e tests in production mode.
- if [ "$RUN_E2E_TESTS_ACCESSIBILITY" == 'true' ]; then travis_retry bash scripts/run_e2e_tests.sh --suite="accessibility" --prod_env; fi
- if [ "$RUN_E2E_TESTS_ADDITIONAL_EDITOR_AND_PLAYER_FEATURES" == 'true' ]; then travis_retry bash scripts/run_e2e_tests.sh --suite="additionalEditorAndPlayerFeatures" --prod_env; fi
Expand All @@ -132,9 +137,11 @@ script:
# Run e2e tests for mobile in dev mode since the demo explorations and collections are only available in the dev mode and not in production mode.
- if [ "$RUN_E2E_TESTS_MOBILE" == 'true' ]; then travis_retry bash scripts/run_e2e_tests.sh --browserstack; fi

after_success:
- if [ "$RUN_BACKEND_TESTS" == 'true' ] && [ "$REPORT_BACKEND_COVERAGE" == 'true' ]; then codecov; fi
- if [ "$RUN_FRONTEND_TESTS" == 'true' ]; then codecov --file ../karma_coverage_reports/coverage-final.json; fi
# These lines are commented out because these checks are being run on CircleCI
# here: https://circleci.com/gh/oppia/oppia
# after_success:
# - if [ "$RUN_BACKEND_TESTS" == 'true' ] && [ "$REPORT_BACKEND_COVERAGE" == 'true' ]; then codecov; fi
# - if [ "$RUN_FRONTEND_TESTS" == 'true' ]; then codecov --file ../karma_coverage_reports/coverage-final.json; fi

cache:
# Cache Oppia's dependencies.
Expand Down

0 comments on commit 7f41f75

Please sign in to comment.