From 6a3a064554e0f680c29c57d5ad3c7e7cd038eef5 Mon Sep 17 00:00:00 2001 From: Kurt McKee Date: Tue, 25 Jul 2023 05:46:38 -0500 Subject: [PATCH] build: reduce CI usage (#83) * CI: Test multiple Pythons per OS * Build a wheel once * CI: Cache virtual environments --- .github/workflows/tests.yml | 44 ++++++++++++++++++++++++------------- requirements/dev.txt | 3 --- requirements/tox.in | 1 - requirements/tox.txt | 3 --- tox.ini | 14 ++++-------- 5 files changed, 33 insertions(+), 32 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 340b880..97a5cf1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -21,7 +21,7 @@ env: jobs: tests: - name: "${{ matrix.python-version }} on ${{ matrix.os }}" + name: "Test on ${{ matrix.os }}" runs-on: "${{ matrix.os }}-latest" strategy: @@ -31,29 +31,43 @@ jobs: - ubuntu - macos - windows - python-version: - - "3.7" - - "3.8" - - "3.9" - - "3.10" - - "3.11" - - "pypy-3.9" steps: - name: "Check out the repo" uses: "actions/checkout@v3" - name: "Set up Python" + id: "setup-python" uses: "actions/setup-python@v4" with: - python-version: "${{ matrix.python-version }}" - cache: pip - cache-dependency-path: 'requirements/*.txt' + # The last listed Python version is the default. + python-version: | + pypy-3.9 + 3.7 + 3.8 + 3.9 + 3.10 + 3.11 + + - name: "Restore cache" + id: "restore-cache" + uses: "actions/cache@v3" + with: + path: | + .tox/ + .venv/ + key: "cache-python-${{ steps.setup-python.outputs.python-version }}-os-${{ runner.os }}-hash-${{ hashFiles('tox.ini', 'requirements/*.txt') }}" + + - name: "Identify venv path" + shell: "bash" + run: "echo 'venv-path=${{ runner.os == 'Windows' && '.venv/Scripts' || '.venv/bin' }}' >> $GITHUB_ENV" - name: "Install dependencies" + if: "steps.restore-cache.outputs.cache-hit == false" run: | - python -m pip install -U setuptools - python -m pip install -r requirements/tox.txt + python -m venv .venv + ${{ env.venv-path }}/python -m pip install -U setuptools + ${{ env.venv-path }}/python -m pip install -r requirements/tox.txt - name: "Install pandoc on Linux" # sudo apt-get pandoc: will install a version from 2018! @@ -72,9 +86,9 @@ jobs: run: | choco install -y -r --no-progress pandoc - - name: "Run tox for ${{ matrix.python-version }}" + - name: "Run tox" run: | - python -m tox + ${{ env.venv-path }}/python -m tox -m ci-tests - name: "Upload coverage data" uses: actions/upload-artifact@v3 diff --git a/requirements/dev.txt b/requirements/dev.txt index c4395d3..ed22365 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -366,9 +366,6 @@ tomlkit==0.11.8 tox==4.6.4 # via # -r requirements/tox.txt - # tox-gh -tox-gh==1.2.0 - # via -r requirements/tox.txt twine==4.0.2 # via -r requirements/quality.txt typed-ast==1.5.5 diff --git a/requirements/tox.in b/requirements/tox.in index 0881b61..d07c121 100644 --- a/requirements/tox.in +++ b/requirements/tox.in @@ -2,4 +2,3 @@ -c constraints.txt tox # Virtualenv management for tests -tox-gh # Run tox environment based on the GitHub action matrix diff --git a/requirements/tox.txt b/requirements/tox.txt index 9305b73..22eb606 100644 --- a/requirements/tox.txt +++ b/requirements/tox.txt @@ -40,9 +40,6 @@ tomli==2.0.1 tox==4.6.4 # via # -r requirements/tox.in - # tox-gh -tox-gh==1.2.0 - # via -r requirements/tox.in typing-extensions==4.7.1 # via # importlib-metadata diff --git a/tox.ini b/tox.ini index 9ba98df..e65ff62 100644 --- a/tox.ini +++ b/tox.ini @@ -6,8 +6,12 @@ envlist = py3{7,11}-no_extras, # And the rest: pypy3, coverage, docs, quality +labels = + ci-tests = py3{7,8,9,10,11},pypy3 [testenv] +package = wheel +wheel_build_env = .pkg deps = -r{toxinidir}/requirements/test.txt extras = @@ -61,13 +65,3 @@ commands = commands = python -m pip install -U pip make upgrade - -[gh] -# https://pypi.org/project/tox-gh/ -python = - 3.7 = py37, py37-no_extras - 3.8 = py38 - 3.9 = py39 - 3.10 = py310 - 3.11 = py311, py311-no_extras - pypy3 = pypy3