From 9baec86270374d7ebcb54cbdf3750542f7a60bbd Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Sat, 14 May 2022 15:32:53 +0100 Subject: [PATCH] try speeding up ci using caching and rearranging jobs (#3974) * try speeding up ci using caching and rearranging jobs * fix job references * cache lint and docs install * tweak caching * tweak caching to avoid conflicts * correct use of runner.os * bump * stop skipping steps depending on cache * prevent hypothesis flakeyness * try skipping install steps again * remove skipping install :-( --- .github/workflows/ci.yml | 117 +++++++++++++++++--------- .github/workflows/upload-previews.yml | 2 +- tests/test_hypothesis_plugin.py | 2 +- 3 files changed, 81 insertions(+), 40 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9900407..8388979 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,20 @@ jobs: with: python-version: 3.9 + - uses: actions/cache@v3 + id: cache + with: + path: | + ${{ env.pythonLocation }} + .mypy_cache + key: > + lint + ${{ runner.os }} + ${{ env.pythonLocation }} + ${{ hashFiles('tests/requirements-linting.txt') }} + - name: install + if: steps.cache.outputs.cache-hit != 'true' run: | make install-linting pip freeze @@ -54,9 +67,22 @@ jobs: - name: set up python uses: actions/setup-python@v3 with: - python-version: 3.8 + python-version: 3.9 + + - uses: actions/cache@v3 + id: cache + with: + path: ${{ env.pythonLocation }} + key: > + docs-build + ${{ runner.os }} + ${{ env.pythonLocation }} + ${{ hashFiles('setup.py') }} + ${{ hashFiles('requirements.txt') }} + ${{ hashFiles('docs/requirements.txt') }} - name: install + if: steps.cache.outputs.cache-hit != 'true' run: make install-docs - name: build site @@ -68,8 +94,8 @@ jobs: name: docs path: site - test-linux: - name: test py${{ matrix.python-version }} on linux + test-linux-compiled: + name: test py${{ matrix.python-version }} on linux compiled runs-on: ubuntu-latest strategy: fail-fast: false @@ -87,10 +113,20 @@ jobs: with: python-version: ${{ matrix.python-version }} + - uses: actions/cache@v3 + id: cache + with: + path: ${{ env.pythonLocation }} + key: > + test-linux-compiled + ${{ runner.os }} + ${{ env.pythonLocation }} + ${{ hashFiles('setup.py') }} + ${{ hashFiles('requirements.txt') }} + ${{ hashFiles('tests/requirements-testing.txt') }} + - name: install - run: | - make install-testing - pip freeze + run: make install-testing - name: compile run: | @@ -101,32 +137,11 @@ jobs: - run: mkdir coverage - - name: test compiled and deps + - name: test run: make test env: - COVERAGE_FILE: coverage/.coverage.linux-py${{ matrix.python-version }}-cY-dY - CONTEXT: linux-py${{ matrix.python-version }}-compiled-yes-deps-yes - - - name: uninstall deps - run: pip uninstall -y cython email-validator devtools python-dotenv - - - name: test compiled without deps - run: make test - env: - COVERAGE_FILE: coverage/.coverage.linux-py${{ matrix.python-version }}-cY-dN - CONTEXT: linux-py${{ matrix.python-version }}-compiled-yes-deps-no - - - name: remove compiled binaries - run: | - rm -r pydantic/*.so pydantic/*.c pydantic/__pycache__ - ls -alh - ls -alh pydantic/ - - - name: test uncompiled without deps - run: make test - env: - COVERAGE_FILE: coverage/.coverage.linux-py${{ matrix.python-version }}-cN-dN - CONTEXT: linux-py${{ matrix.python-version }}-compiled-no-deps-no + COVERAGE_FILE: coverage/.coverage.linux-py${{ matrix.python-version }}-compiled + CONTEXT: linux-py${{ matrix.python-version }}-compiled - name: store coverage files uses: actions/upload-artifact@v3 @@ -134,13 +149,16 @@ jobs: name: coverage path: coverage - test-windows-mac: + test-not-compiled: name: test py${{ matrix.python-version }} on ${{ matrix.os }} strategy: fail-fast: false matrix: - os: [macos, windows] + os: [ubuntu, macos, windows] python-version: ['3.7', '3.8', '3.9', '3.10'] + include: + - os: ubuntu + env: PYTHON: ${{ matrix.python-version }} OS: ${{ matrix.os }} @@ -156,16 +174,39 @@ jobs: with: python-version: ${{ matrix.python-version }} + - uses: actions/cache@v3 + id: cache + with: + path: ${{ env.pythonLocation }} + key: > + test-not-compiled + ${{ runner.os }} + ${{ env.pythonLocation }} + ${{ hashFiles('setup.py') }} + ${{ hashFiles('requirements.txt') }} + ${{ hashFiles('tests/requirements-testing.txt') }} + - name: install run: make install-testing + - run: pip freeze + - run: mkdir coverage - - name: test + - name: test with deps run: make test env: - COVERAGE_FILE: coverage/.coverage.${{ matrix.os }}-py${{ matrix.python-version }} - CONTEXT: ${{ matrix.os }}-py${{ matrix.python-version }} + COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}-with-deps + CONTEXT: ${{ runner.os }}-py${{ matrix.python-version }}-with-deps + + - name: uninstall deps + run: pip uninstall -y cython email-validator devtools python-dotenv + + - name: test without deps + run: make test + env: + COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}-without-deps + CONTEXT: ${{ runner.os }}-py${{ matrix.python-version }}-without-deps - name: store coverage files uses: actions/upload-artifact@v3 @@ -215,7 +256,7 @@ jobs: path: coverage coverage-combine: - needs: [test-linux, test-windows-mac, test-old-mypy] + needs: [test-linux-compiled, test-not-compiled, test-old-mypy] runs-on: ubuntu-latest steps: @@ -233,7 +274,7 @@ jobs: - run: pip install coverage - - run: ls -la + - run: ls -la coverage - run: coverage combine coverage - run: coverage report - run: coverage html --show-contexts @@ -263,7 +304,7 @@ jobs: build: name: build py3.${{ matrix.python-version }} on ${{ matrix.platform || matrix.os }} - needs: [lint, test-linux, test-windows-mac, test-old-mypy, test-fastapi] + needs: [lint, test-linux-compiled, test-not-compiled, test-old-mypy, test-fastapi] if: "success() && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/master')" strategy: fail-fast: false diff --git a/.github/workflows/upload-previews.yml b/.github/workflows/upload-previews.yml index 0bec378..2ebcf4b 100644 --- a/.github/workflows/upload-previews.yml +++ b/.github/workflows/upload-previews.yml @@ -16,7 +16,7 @@ jobs: steps: - uses: actions/setup-python@v3 with: - python-version: '3.8' + python-version: '3.9' - run: pip install smokeshow diff --git a/tests/test_hypothesis_plugin.py b/tests/test_hypothesis_plugin.py index 95dc59c..ad35388 100644 --- a/tests/test_hypothesis_plugin.py +++ b/tests/test_hypothesis_plugin.py @@ -108,7 +108,7 @@ def gen_models(): @pytest.mark.parametrize('model', gen_models()) -@settings(suppress_health_check={HealthCheck.too_slow}) +@settings(suppress_health_check={HealthCheck.too_slow}, deadline=None) @given(data=st.data()) def test_can_construct_models_with_all_fields(data, model): # The value of this test is to confirm that Hypothesis knows how to provide