From bf6ed10a79384ee9240d5555c17f3ffd5cbdf704 Mon Sep 17 00:00:00 2001 From: rht Date: Wed, 22 Nov 2023 22:51:48 -0500 Subject: [PATCH] ci: Speed up pip install by caching deps install output Based on the benchmark, it speeds up by about 2x for the Ubuntu instances. While extracting the cache tarball for the Windows instance could be further sped up, with a `tar` binary that supports `zstd`. See https://github.com/rht/mesa/pull/12. The cache should be automatically cleared every month. Or alternatively, create a lockfile (either via Poetry of `pip-tools`) that is automatically updated via Dependabot. Regardless, this is out of the scope of this PR. --- .github/workflows/build_lint.yml | 24 +++++++++++++++++++++--- tests/read_requirements.py | 8 ++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 tests/read_requirements.py diff --git a/.github/workflows/build_lint.yml b/.github/workflows/build_lint.yml index 3ba7340b2d3..9101ba05b00 100644 --- a/.github/workflows/build_lint.yml +++ b/.github/workflows/build_lint.yml @@ -50,12 +50,30 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} + - if: ${{ runner.os == 'Windows' }} + # This is needed so that restoring cache on Windows is fast. + # See until https://github.com/actions/cache/issues/752 is resolved. + name: Use GNU tar + shell: cmd + run: | + echo "Adding GNU tar to PATH" + echo C:\Program Files\Git\usr\bin>>"%GITHUB_PATH%" - uses: actions/cache@v3 with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('Pipfile.lock') }} + path: ${{ env.pythonLocation }} + key: ${{ runner.os }}-pip-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }} - name: Install dependencies - run: pip install wheel && pip install .[dev] + # Only if the cache misses + # Based on https://github.com/pypa/pip/issues/8049#issuecomment-633845028 + # read_requirements.py should be removed once + # https://github.com/pypa/pip/issues/11440 is resolved. + if: steps.cache.outputs.cache-hit != 'true' + run: | + pip install toml + python tests/read_requirements.py > requirements.txt + pip install -r requirements.txt + - name: Install Mesa + run: pip install --no-deps . - name: Test with pytest run: pytest --cov=mesa tests/ --cov-report=xml - if: matrix.os == 'ubuntu' diff --git a/tests/read_requirements.py b/tests/read_requirements.py new file mode 100644 index 00000000000..83ccfd95219 --- /dev/null +++ b/tests/read_requirements.py @@ -0,0 +1,8 @@ +import toml + +# This file reads the pyproject.toml and prints out the +# dependencies and dev dependencies. +# It is located in tests/ folder so as not to pollute the root repo. +c = toml.load("pyproject.toml") +print("\n".join(c["project"]["dependencies"])) +print("\n".join(c["project"]["optional-dependencies"]["dev"]))