Skip to content

Commit

Permalink
Fix oppia#5885 Only run front end test when front end file changed (o…
Browse files Browse the repository at this point in the history
…ppia#5936)

* Only run front end test when front end file changed

* Change comments according to review

* Front end file change test

* Revert "Front end file change test"

This reverts commit c66e86b.

* Compare against the local branch

* Compare with the branch tip on github

* Front end file change test

* Revert "Front end file change test"

This reverts commit e226e40.

* Front end file change test

* Revert "Front end file change test"

This reverts commit d0f8c78.

* Change words
  • Loading branch information
EvsChen authored and apb7 committed Dec 23, 2018
1 parent 02995f8 commit 156ff89
Showing 1 changed file with 57 additions and 7 deletions.
64 changes: 57 additions & 7 deletions scripts/run_presubmit_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,29 @@
# Run this script from the oppia root folder prior to opening a PR:
# bash scripts/run_presubmit_checks.sh
#
# It runs all the tests, in this order:
# It runs the following tests in all cases.
# - Javascript and Python Linting
# - Frontend Karma unit tests
# - Backend Python tests
#
# Only when frontend files are changed will it run Frontend Karma unit tests.
#
# If any of these tests result in errors, this script will terminate.
#
# Note: The test scripts are arranged in increasing order of time taken. This
# enables a broken build to be detected as quickly as possible.
#
# =====================
# CUSTOMIZATION OPTIONS
# =====================
#
# Set the origin branch to compare against by adding
#
# --branch=your_branch or -b=your_branch
#
# By default, if the current branch tip exists on remote origin,
# the current branch is compared against its tip on GitHub.
# Otherwise it's compared against 'develop'.

if [ -z "$BASH_VERSION" ]
then
echo ""
Expand All @@ -47,11 +61,47 @@ python $(dirname $0)/pre_commit_linter.py || exit 1
echo 'Linting passed.'
echo ''

# Run frontend unit tests.
echo 'Running frontend unit tests'
source $(dirname $0)/run_frontend_tests.sh --run-minified-tests=true || exit 1
echo 'Frontend tests passed.'
echo ''
# Read arguments from the command line.
for i in "$@"
do
case $i in
-b=*|--branch=*)
ORIGIN_BRANCH=${i#*=}
shift
;;
esac
done

CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
# If the current branch exists on remote origin, MATCHED_BRANCH_NUM=1
# else MATCHED_BRANCH_NUM=0
MATCHED_BRANCH_NUM=$(git ls-remote --heads origin $CURRENT_BRANCH | wc -l)
# Set the origin branch to develop if it's not specified.
if [ -n "$ORIGIN_BRANCH" ]; then
BRANCH=$ORIGIN_BRANCH
elif [ $MATCHED_BRANCH_NUM == 1 ]; then
BRANCH=origin/$CURRENT_BRANCH
else
BRANCH=develop
fi

FRONTEND_DIR='core/templates/dev/head'

echo "Comparing the current branch with $BRANCH"

if [ -n "$(git diff --cached --name-only --diff-filter=ACM ${BRANCH} | grep ${FRONTEND_DIR})" ]
then
# Run frontend unit tests.
echo 'Running frontend unit tests'
source $(dirname $0)/run_frontend_tests.sh --run-minified-tests=true || exit 1
echo 'Frontend tests passed.'
echo ''
else
# If files in FRONTEND_DIR were not changed, skip the tests.
echo 'No frontend files were changed.'
echo 'Skipped frontend tests'
fi


# Run backend tests.
echo 'Running backend tests'
Expand Down

0 comments on commit 156ff89

Please sign in to comment.