Browse Source

Clean up

pull/7657/head
Richard Tibbles 12 months ago
parent
commit
1afb3be56a
  1. 3
      .github/workflows/pre-commit.yml
  2. 22
      .github/workflows/tox.yml
  3. 22
      test/conditional/test_build.sh
  4. 149
      test/if.sh
  5. 80
      tox.ini

3
.github/workflows/pre-commit.yml

@ -3,7 +3,8 @@ name: Linting
on: [push, pull_request]
jobs:
Linting:
linting:
name: All file linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

22
.github/workflows/tox.yml

@ -17,14 +17,7 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: pip cache
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements/*.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
- name: Install tox
run: |
python -m pip install --upgrade pip
pip install tox
@ -32,7 +25,7 @@ jobs:
uses: actions/cache@v2
with:
path: ${{ github.workspace }}/.tox/py${{ matrix.python-version }}
key: ${{ runner.os }}-tox-py${{ matrix.python-version }}-${{ hashFiles('**/requirements/*.txt') }}
key: ${{ runner.os }}-tox-py${{ matrix.python-version }}-${{ hashFiles('requirements/*.txt') }}
restore-keys: |
${{ runner.os }}-tox-py${{ matrix.python-version }}
- name: Test with tox
@ -65,14 +58,7 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: 3.5
- name: pip cache
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements/*.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
- name: Install tox
run: |
python -m pip install --upgrade pip
pip install tox
@ -80,7 +66,7 @@ jobs:
uses: actions/cache@v2
with:
path: ${{ github.workspace }}/.tox/py${{ matrix.python-version }}
key: ${{ runner.os }}-tox-py${{ matrix.python-version }}-${{ hashFiles('**/requirements/*.txt') }}
key: ${{ runner.os }}-tox-py${{ matrix.python-version }}-${{ hashFiles('requirements/*.txt') }}
restore-keys: |
${{ runner.os }}-tox-py${{ matrix.python-version }}
- name: Test with tox

22
test/conditional/test_build.sh

@ -1,22 +0,0 @@
#!/bin/bash
set -e
PREVIOUS_CWD=`pwd`
# Goto location of this script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$DIR/../../"
# Install build deps
pip install -r requirements/build.txt
pip install -r requirements/test.txt
# Build .whl
yarn install
make dist > /dev/null
pip install dist/kolibri*.whl
cd "$PREVIOUS_CWD"
exit 0

149
test/if.sh

@ -1,149 +0,0 @@
#!/bin/bash
# This script is invoked by Travis testing and inspects
# the changeset that's being built.
#
# Usage:
#
# if.sh <label> && something_else
#
# The intention is to be able to ONLY test certain aspects
# when special conditions are satisfied.
#
# Notes:
# JS tests are expected to be very fast
# We shouldn't skip tests when it affects Coverage negatively
# We can possibly do tests based on which branch is pushed to
#
# https://github.com/learningequality/kolibri/issues/27
#
# What changes are analyzed?
#
# For this script, we should mainly use Travis' env
# $TRAVIS_COMMIT_RANGE. The reason is simple: You cannot tell what
# changes have been implemented since last test, thus if your
# condtion should fire or not.
#
# Definition:
# TRAVIS_COMMIT_RANGE: The range of commits that were included in
# the push or pull request.
#
# https://docs.travis-ci.com/user/environment-variables/
set -e
# Goto location of this script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $DIR
# Traceback utility for Bash
. "$DIR/traceback.sh"
LABEL="$1"
FORCE_RUN="$2"
# Set by Travis CI
commit="$TRAVIS_COMMIT"
current_branch="$TRAVIS_BRANCH"
git_changeset=""
if [ "$TRAVIS_BRANCH" == "" ]
then
# The changeset is $TRAVIS_COMMIT_RANGE
# echo "Using TRAVIS_COMMIT_RANGE as changeset"
git_changeset=`git show --name-only --no-notes --oneline $TRAVIS_COMMIT_RANGE`
else
# The changeset is the diff between PR and branch that the PR is made
# against.
# echo "Using git log $TRAVIS_BRANCH..HEAD as changeset"
# Because Travis' git clone does not contain the upstream branch being
# PR'ed against, we need to explicitly fetch it and compare the FETCH_HEAD
# in which it's stored with the detached head.
git fetch origin $TRAVIS_BRANCH
git_changeset=`git log FETCH_HEAD --oneline --name-only`
fi
# echo "Travis branch / branch merging into: $TRAVIS_BRANCH"
# echo "Git change set:\n\n$git_changeset"
function match_changes {
if ! [ "$FORCE_RUN" == "" ]
then
return 0
fi
# Usage: match_changes "match1" "match2"
# if branch should always be tested
if [ "$TRAVIS_PULL_REQUEST" == "false" ]
then
for branch in releases/*
do
if echo "$current_branch" | grep -q "$branch"
then
# echo "Always testing $branch, so not skipping $LABEL..."
return 0
fi
done
fi
# Loop through all arguments
for pattern_to_match
do
if echo "$git_changeset" | grep -q "$pattern_to_match"
then
# echo "Conditional match for pattern '$pattern_to_match'"
return 0
fi
done
# No matches
return 1
}
# If something changes that's related to our sdist packaging
# or installation mechanism, then we build and install.
if [[ "$LABEL" == "setup_changed" ]]
then
# Match with commit messages containing "[ setup ]"
# Match commits changing requirements.txt
# Match commits changing setup.py
if match_changes "\[\s*setup\s*\]" \
"^setup\.py" \
"^requirements" \
"^Makefile" \
"^MANIFEST*" \
&& true # <- because of set -e
then
. conditional/test_build.sh
fi
fi
# If something changes that's related to our sdist packaging
# or installation mechanism, then we build and install.
if [[ "$LABEL" == "requirements_changed" ]]
then
# Match with commit messages containing "[ license ]"
# Match commits changing requirements.txt
if match_changes "\[\s*license\s*\]" \
"^requirements" \
&& true # <- because of set -e
then
echo "Requirements changed, checking license info..."
. conditional/test_licenses.sh
fi
fi
# No matches
echo "[ OK ] Skipping conditional test '$LABEL'"
exit 0

80
tox.ini

@ -1,5 +1,5 @@
[tox]
envlist = py{2.7,3.4,3.5,3.6,3.7,3.8}, docs, postgres, cext, nocext
envlist = py{2.7,3.4,3.5,3.6,3.7,3.8}, postgres
[testenv]
usedevelop = True
@ -13,17 +13,12 @@ setenv =
KOLIBRI_RUN_MODE = tox
SKIP_PY_CHECK = 1
basepython =
licenses: python2.7
py2.7: python2.7
py3.4: python3.4
py3.5: python3.5
py3.6: python3.6
py3.7: python3.7
py3.8: python3.8
docs: python3.5
nocext: python2.7
cext: python2.7
timely_shutdown_no_zombies: python3.6
deps =
-r{toxinidir}/requirements/test.txt
-r{toxinidir}/requirements/base.txt
@ -35,67 +30,6 @@ commands =
# Fail if the log is longer than 200 lines (something erroring or very noisy got added)
sh -c "if [ `cat {env:KOLIBRI_HOME}/logs/kolibri.txt | wc -l` -gt 200 ] ; then echo 'Log too long' && echo '' && tail -n 20 {env:KOLIBRI_HOME}/logs/kolibri.txt && exit 1 ; fi"
# Running w/o C extensions is slow, so we just do a
# limited amount of testing
# This briefly tests our static deps etc w/o cexts
[testenv:nocext]
passenv = TOX_ENV
setenv =
PYTHONPATH = "{toxinidir}:{toxinidir}/kolibri/dist"
deps =
-r{toxinidir}/requirements/test.txt
-r{toxinidir}/requirements/build.txt
commands =
# Ensure that for this Python version, we can actually compile ALL files
# in the kolibri directory
python -m compileall -q kolibri -x py2only
# Until we have staged builds, we will be running this in each and every
# environment even though builds should be done in Py 2.7
make staticdeps
# Start and stop kolibri
coverage run -p kolibri start --port=8081
coverage run -p kolibri stop
# Run just tests in test/
py.test --cov=kolibri --cov-report= --cov-append --color=no test/
# This briefly tests our static deps etc WITH cexts
[testenv:cext]
passenv = TOX_ENV
setenv =
PYTHONPATH = "{toxinidir}:{toxinidir}/kolibri/dist"
deps =
-r{toxinidir}/requirements/test.txt
-r{toxinidir}/requirements/build.txt
commands =
# Ensure that for this Python version, we can actually compile ALL files
# in the kolibri directory
python -m compileall -q kolibri -x py2only
# Until we have staged builds, we will be running this in each and every
# environment even though builds should be done in Py 2.7
make staticdeps
make staticdeps-cext
# Start and stop kolibri
coverage run -p kolibri start --port=8081
coverage run -p kolibri stop
# Run just tests in test/
py.test --cov=kolibri --cov-report= --cov-append --color=no test/
[testenv:timely_shutdown_no_zombies]
passenv = TOX_ENV
whitelist_externals =
fuser
sleep
deps =
-r{toxinidir}/requirements/test.txt
-r{toxinidir}/requirements/base.txt
commands =
- fuser 8082/tcp -k
# ensure kolibri stops within 20 seconds 10 times in a row
{toxinidir}/test/ensure_kolibri_stops_within_time.sh 20 10 8082
{toxinidir}/test/ensure_no_kolibris_running_on_port.sh 8082
[testenv:postgres]
passenv = TOX_ENV
setenv =
@ -113,15 +47,3 @@ deps =
commands =
py.test {posargs:--cov=kolibri --color=no}
# rm -rf {env:KOLIBRI_HOME}
[testenv:docs]
deps =
-r{toxinidir}/requirements/docs.txt
commands =
make docs
[testenv:licenses]
whitelist_externals =
{toxinidir}/test/if.sh
commands =
{toxinidir}/test/if.sh "requirements_changed"

Loading…
Cancel
Save