diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9740a21..872d8df 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -37,6 +37,7 @@ jobs: uses: "actions/checkout@v3" - name: "Set up Python" + id: "setup-python" uses: "actions/setup-python@v4" with: # The last listed Python version is the default. @@ -47,13 +48,26 @@ jobs: 3.9 3.10 3.11 - cache: pip - cache-dependency-path: 'requirements/*.txt' + + - 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! @@ -74,7 +88,7 @@ jobs: - name: "Run tox" run: | - python -m tox -m ci-tests + ${{ env.venv-path }}/python -m tox -m ci-tests - name: "Upload coverage data" uses: actions/upload-artifact@v3 diff --git a/changelog.d/20230206_072342_kurtmckee_reduce_ci_usage.rst b/changelog.d/20230206_072342_kurtmckee_reduce_ci_usage.rst new file mode 100644 index 0000000..495307e --- /dev/null +++ b/changelog.d/20230206_072342_kurtmckee_reduce_ci_usage.rst @@ -0,0 +1,12 @@ +Changed +....... + +- Create and cache a virtual environment in CI, as well as the tox environments. + + With a cache hit, this decreases CI total usage from ~15 minutes to ~10 minutes. + It decreases CI duration from ~7 minutes to ~5 minutes. + + The cache keys hash ``requirements/*.txt`` and ``tox.ini``. + GitHub caches are branch-specific, but if no cache is found for the current branch, + the cache for the ``main`` branch will then be checked. + It is anticipated that most branches will therefore have a cache hit.