Skip to content

Commit

Permalink
Enable faster test runners.
Browse files Browse the repository at this point in the history
Enable more parallelism in CI tests.
Add caching of venv installation with weekly forced invalidation.
  • Loading branch information
levskaya committed Nov 20, 2022
1 parent 3b27a69 commit 20cca7b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 16 deletions.
44 changes: 30 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.8
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: 3.7
- uses: pre-commit/action@v2.0.3
commit-count:
name: Check commit count
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
# We allow at most 5 commits in a branch to ensure our CI doesn't break.
- name: Check commit count in PR
if: always()
Expand Down Expand Up @@ -65,9 +65,9 @@ jobs:
matrix:
python-version: [3.7, 3.8, 3.9]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install standalone dependencies only
Expand All @@ -79,7 +79,7 @@ jobs:
tests:
name: Run Tests
needs: [cancel-previous, pre-commit, commit-count, test-import]
runs-on: ubuntu-latest
runs-on: ubuntu-20.04-16core
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
Expand All @@ -90,24 +90,40 @@ jobs:
- test-type: pytype
python-version: 3.8
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
id: setup_python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
- name: Get week and year
id: week_year
run: echo "DATE=$(date +%U-%Y)" >> $GITHUB_OUTPUT
- name: Cached virtual environment
id: venv_cache
uses: actions/cache@v3
with:
path: venv
key: pip-${{ steps.setup_python.outputs.python-version }}-${{ steps.week_year.outputs.DATE }}-${{ hashFiles('**/requirements.txt', 'setup.py') }}
- name: Install Dependencies for cache
if: steps.venv_cache.outputs.cache-hit != 'true'
run: |
pip install .
pip install .[testing]
pip install -r docs/requirements.txt
if [ -d "venv" ]; then rm -rf venv; fi
python3 -m venv venv
venv/bin/python3 -m pip install .
venv/bin/python3 -m pip install .[testing]
venv/bin/python3 -m pip install -r docs/requirements.txt
- name: Install Flax
run: |
venv/bin/python3 -m pip install -e .
- name: Test with ${{ matrix.test-type }}
run: |
if [[ "${{ matrix.test-type }}" == "doctest" ]]; then
tests/run_all_tests.sh --no-pytest --no-pytype
tests/run_all_tests.sh --no-pytest --no-pytype --use-venv
elif [[ "${{ matrix.test-type }}" == "pytest" ]]; then
tests/run_all_tests.sh --no-doctest --no-pytype --with-cov
tests/run_all_tests.sh --no-doctest --no-pytype --with-cov --use-venv
elif [[ "${{ matrix.test-type }}" == "pytype" ]]; then
tests/run_all_tests.sh --no-doctest --no-pytest
tests/run_all_tests.sh --no-doctest --no-pytest --use-venv
else
echo "Unknown test type: ${{ matrix.test-type }}"
exit 1
Expand Down
15 changes: 13 additions & 2 deletions tests/run_all_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ PYTEST_OPTS=
RUN_DOCTEST=true
RUN_PYTEST=true
RUN_PYTYPE=true
GH_VENV=false

for flag in "$@"; do
case $flag in
Expand All @@ -24,18 +25,28 @@ case $flag in
--no-pytype)
RUN_PYTYPE=false
;;
--use-venv)
GH_VENV=true
;;
*)
echo "Unknown flag: $flag"
exit 1
;;
esac
done

# Activate cached virtual env for github CI
if $GH_VENV; then
source $(dirname "$0")/../venv/bin/activate
fi

echo "====== test config ======="
echo "PYTEST_OPTS: $PYTEST_OPTS"
echo "RUN_DOCTEST: $RUN_DOCTEST"
echo "RUN_PYTEST: $RUN_PYTEST"
echo "RUN_PYTYPE: $RUN_PYTYPE"
echo "GH_VENV: $GH_VENV"
echo "WHICH PYTHON: $(which python)"
echo "jax: $(python -c 'import jax; print(jax.__version__)')"
echo "flax: $(python -c 'import flax; print(flax.__version__)')"
echo "=========================="
Expand Down Expand Up @@ -99,14 +110,14 @@ fi
if $RUN_PYTYPE; then
echo "=== RUNNING PYTYPE ==="
# Validate types in library code.
pytype --config pytype.cfg flax/
pytype --jobs auto --config pytype.cfg flax/

# Validate types in examples.
for egd in $(find examples -maxdepth 1 -mindepth 1 -type d); do
# use cd to make sure pytpe cache lives in example dir and doesn't name clash
# use *.py to avoid importing configs as a top-level import which leads to import errors
# because config files use relative imports (e.g. from config import ...).
(cd $egd ; pytype --config ../../pytype.cfg "*.py")
(cd $egd ; pytype --jobs auto --config ../../pytype.cfg "*.py")
done
fi

Expand Down

0 comments on commit 20cca7b

Please sign in to comment.