From 98ceab7de9f78146aacbc9148ddabf1a5e14cb43 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Mon, 7 Nov 2022 08:53:12 +0100 Subject: [PATCH] Update Primer venv caching [ci] (#7708) * Use release version for astroid * Use better cache key * Mirror create environment * Update comments --- .github/workflows/primer_comment.yaml | 3 ++- .github/workflows/primer_run_main.yaml | 12 +++--------- .github/workflows/primer_run_pr.yaml | 12 ++++++++---- pyproject.toml | 3 +-- requirements_test_min.txt | 1 - 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/.github/workflows/primer_comment.yaml b/.github/workflows/primer_comment.yaml index d52b0efe4a..97d546ccb2 100644 --- a/.github/workflows/primer_comment.yaml +++ b/.github/workflows/primer_comment.yaml @@ -50,7 +50,8 @@ jobs: path: venv key: ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{ - env.KEY_PREFIX }}-${{ env.CACHE_VERSION }} + env.KEY_PREFIX }}-${{ env.CACHE_VERSION }}-${{ hashFiles('pyproject.toml', + 'requirements_test.txt', 'requirements_test_min.txt') }} - name: Fail job if Python cache restore failed if: steps.cache-venv.outputs.cache-hit != 'true' run: | diff --git a/.github/workflows/primer_run_main.yaml b/.github/workflows/primer_run_main.yaml index f0aace5ade..4f89b9e6e6 100644 --- a/.github/workflows/primer_run_main.yaml +++ b/.github/workflows/primer_run_main.yaml @@ -37,12 +37,6 @@ jobs: python-version: ${{ matrix.python-version }} check-latest: true - - name: Get latest astroid commit - id: get-astroid-sha - run: | - curl https://api.github.com/repos/PyCQA/astroid/commits | - python -c "import json, sys; print(json.load(sys.stdin)[0]['sha'])" > astroid_sha.txt - # Create a re-usable virtual environment - name: Create Python virtual environment cache id: cache-venv @@ -51,15 +45,15 @@ jobs: path: venv key: ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{ - env.KEY_PREFIX }}-${{ env.CACHE_VERSION }} + env.KEY_PREFIX }}-${{ env.CACHE_VERSION }}-${{ hashFiles('pyproject.toml', + 'requirements_test.txt', 'requirements_test_min.txt') }} - name: Create Python virtual environment + if: steps.cache-venv.outputs.cache-hit != 'true' run: | python -m venv venv . venv/bin/activate python -m pip install -U pip setuptools wheel pip install -U -r requirements_test.txt - # Use bleeding-edge astroid - pip install git+https://github.com/PyCQA/astroid.git # Cache primer packages - name: Get commit string diff --git a/.github/workflows/primer_run_pr.yaml b/.github/workflows/primer_run_pr.yaml index 10c3a2aa00..5acf3791cb 100644 --- a/.github/workflows/primer_run_pr.yaml +++ b/.github/workflows/primer_run_pr.yaml @@ -60,12 +60,16 @@ jobs: path: venv key: ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{ - env.KEY_PREFIX }}-${{ env.CACHE_VERSION }} - - name: Fail job if Python cache restore failed + env.KEY_PREFIX }}-${{ env.CACHE_VERSION }}-${{ hashFiles('pyproject.toml', + 'requirements_test.txt', 'requirements_test_min.txt') }} + # Create environment must match step in 'Primer / Main' + - name: Create Python virtual environment if: steps.cache-venv.outputs.cache-hit != 'true' run: | - echo "Failed to restore Python venv from cache" - exit 1 + python -m venv venv + . venv/bin/activate + python -m pip install -U pip setuptools wheel + pip install -U -r requirements_test.txt # Cache primer packages - name: Download last 'main' run info diff --git a/pyproject.toml b/pyproject.toml index 7de065de1c..cf89aa5d81 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,8 +34,7 @@ requires-python = ">=3.7.2" dependencies = [ "dill>=0.2", "platformdirs>=2.2.0", - # Also upgrade requirements_test_min.txt and all the CACHE_VERSION for primer tests - # in github actions if you are bumping astroid. + # Also upgrade requirements_test_min.txt. # Pinned to dev of second minor update to allow editable installs and fix primer issues, # see https://github.com/PyCQA/astroid/issues/1341 "astroid>=2.12.12,<=2.14.0-dev0", diff --git a/requirements_test_min.txt b/requirements_test_min.txt index f482fd0477..5b94955ef7 100644 --- a/requirements_test_min.txt +++ b/requirements_test_min.txt @@ -1,6 +1,5 @@ -e .[testutils,spelling] # astroid dependency is also defined in pyproject.toml -# You need to increment the CACHE_VERSION for primer tests in github actions too astroid==2.12.12 # Pinned to a specific version for tests typing-extensions~=4.3 py~=1.11.0