From 52d7f3f91b6cbadc4968332c09e5e1f89e8446c0 Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Thu, 24 Oct 2024 14:07:54 +0100 Subject: [PATCH] Remove cache of Python .venv as it added complexity (#12) ci: Remove cache of Python `.venv` as it added complexity --- .github/actions/init-python/action.yml | 51 ++++++----------------- .github/workflows/ci.yml | 21 ---------- .github/workflows/codeql-analysis.yml | 7 ---- .github/workflows/lint-clang.yml | 2 - .github/workflows/lint-cmake.yml | 2 - .github/workflows/sonarcloud-analysis.yml | 7 ---- .github/workflows/valgrind-analysis.yml | 7 ---- 7 files changed, 12 insertions(+), 85 deletions(-) diff --git a/.github/actions/init-python/action.yml b/.github/actions/init-python/action.yml index e6f5f5d5b08..4719fd1772f 100644 --- a/.github/actions/init-python/action.yml +++ b/.github/actions/init-python/action.yml @@ -1,50 +1,23 @@ -name: "Setup Python venv" -description: "Creates and caches a Python virtual environment" - -inputs: - cache: - description: "Cache Python venv" - default: true - - setup: - description: "Setup Python venv" - default: true +# Important: Do not be tempted to cache the .venv dir (Python virtual environment). +# When the runner environment changes (e.g. Python is upgraded), the venv will need to be +# re-created. Trying to upgrade a venv can be complex and it's usually more practical re-create it. +# We don't save much time anyway by caching the venv so it's not worth the added complexity. - python-bin: - description: "Python binary to use" - default: "python3" - - cache-key: - description: "Cache key (note: hash is appended)" - required: true +name: "Setup Python venv" +description: "Creates a Python virtual environment (venv)" runs: using: "composite" steps: - - name: Check cache key - if: ${{ inputs.cache }} - run: | - if [ -z "${{ inputs.cache-key }}" ]; then - echo "Cache key is required" - exit 1 - fi - shell: bash - - - name: Cache Python venv - if: ${{ inputs.cache }} - uses: actions/cache@v4 - with: - path: .venv - key: python-venv-${{ inputs.cache-key }}-${{ hashFiles('scripts/pyproject.toml') }} - - # Use bash if to make output clearer in case of skipping. - name: Setup Python venv run: | - if [ "${{ inputs.setup }}" = "true" ]; then - echo "Setting up Python venv" - ${{ inputs.python-bin }} -m venv .venv + if [ "${{ runner.os }}" == "Windows" ]; then + python=python else - echo "Skipping Python venv setup" + python=python3 fi + + echo "Setting up Python venv, bin=$python" + $python -m venv .venv shell: bash diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 52b58825412..76c31315d64 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -132,13 +132,6 @@ jobs: ${{ env.LOCALAPPDATA }}/vcpkg key: vcpkg-${{ runner.os }}-${{ hashFiles('vcpkg.json', 'vcpkg-configuration.json') }} - # Should only restore the .venv directory from cache. - - name: Init Python venv - uses: ./.github/actions/init-python - with: - cache-key: ci-${{ matrix.target.name }} - setup: false - - name: Cache deps dir uses: actions/cache@v4 with: @@ -220,13 +213,6 @@ jobs: - name: Get version uses: ./.github/actions/get-version - # Should only restore the .venv directory from cache. - - name: Setup Python venv - uses: ./.github/actions/init-python - with: - cache-key: ci-${{ matrix.target.name }} - setup: false - - name: Cache deps dir uses: actions/cache@v4 with: @@ -299,13 +285,6 @@ jobs: - name: Checkout uses: actions/checkout@v4 - # Should only restore the .venv directory from cache. - - name: Setup Python venv - uses: ./.github/actions/init-python - with: - cache-key: ci-${{ matrix.distro.name }} - setup: false - - name: Get version uses: ./.github/actions/get-version diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 62ec2b1e1b8..a5efc75797f 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -27,13 +27,6 @@ jobs: - name: Config Git safe dir run: git config --global --add safe.directory $GITHUB_WORKSPACE - # Should only restore the .venv directory from cache. - - name: Init Python venv - uses: ./.github/actions/init-python - with: - cache-key: "codeql" - setup: false - - name: Install dependencies run: ./scripts/install_deps.py env: diff --git a/.github/workflows/lint-clang.yml b/.github/workflows/lint-clang.yml index d8abad28689..2e7a97f0c96 100644 --- a/.github/workflows/lint-clang.yml +++ b/.github/workflows/lint-clang.yml @@ -15,8 +15,6 @@ jobs: - name: Setup Python venv uses: ./.github/actions/init-python - with: - cache-key: "lint-clang" - name: Install dependencies run: | diff --git a/.github/workflows/lint-cmake.yml b/.github/workflows/lint-cmake.yml index 5a4679004e5..e3288a5c6d5 100644 --- a/.github/workflows/lint-cmake.yml +++ b/.github/workflows/lint-cmake.yml @@ -15,8 +15,6 @@ jobs: - name: Setup Python venv uses: ./.github/actions/init-python - with: - cache-key: "lint-cmake" - name: Install dependencies run: | diff --git a/.github/workflows/sonarcloud-analysis.yml b/.github/workflows/sonarcloud-analysis.yml index 131b909e84e..b3fc246d4b9 100644 --- a/.github/workflows/sonarcloud-analysis.yml +++ b/.github/workflows/sonarcloud-analysis.yml @@ -33,13 +33,6 @@ jobs: - name: Config Git safe dir run: git config --global --add safe.directory $GITHUB_WORKSPACE - # Should only restore the .venv directory from cache. - - name: Init Python venv - uses: ./.github/actions/init-python - with: - cache-key: "sonarcloud" - setup: false - - name: Install dependencies run: | ./scripts/install_deps.py && diff --git a/.github/workflows/valgrind-analysis.yml b/.github/workflows/valgrind-analysis.yml index cfa74cb20f2..dcfa05621c4 100644 --- a/.github/workflows/valgrind-analysis.yml +++ b/.github/workflows/valgrind-analysis.yml @@ -17,13 +17,6 @@ jobs: - name: Config Git safe dir run: git config --global --add safe.directory $GITHUB_WORKSPACE - # Should only restore the .venv directory from cache. - - name: Init Python venv - uses: ./.github/actions/init-python - with: - cache-key: "valgrind" - setup: false - - name: Install dependencies run: | ./scripts/install_deps.py &&