Skip to content

Commit

Permalink
Remove cache of Python .venv as it added complexity (#12)
Browse files Browse the repository at this point in the history
ci: Remove cache of Python `.venv` as it added complexity
  • Loading branch information
nbolton authored Oct 24, 2024
1 parent 9e3f14d commit 52d7f3f
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 85 deletions.
51 changes: 12 additions & 39 deletions .github/actions/init-python/action.yml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 0 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
7 changes: 0 additions & 7 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/lint-clang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ jobs:

- name: Setup Python venv
uses: ./.github/actions/init-python
with:
cache-key: "lint-clang"

- name: Install dependencies
run: |
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/lint-cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ jobs:

- name: Setup Python venv
uses: ./.github/actions/init-python
with:
cache-key: "lint-cmake"

- name: Install dependencies
run: |
Expand Down
7 changes: 0 additions & 7 deletions .github/workflows/sonarcloud-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
7 changes: 0 additions & 7 deletions .github/workflows/valgrind-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down

0 comments on commit 52d7f3f

Please sign in to comment.