Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/actions/restore-venv/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: "Restore venv and pre-commit from cache"
description: "Restores the venv and pre-commit cache or fails"

inputs:
python-version:
required: true
venv-dir:
required: true
precommit-home:
required: true
cache-key:
required: true

fail-on-miss:
required: false
default: "true" # DefauLt fail if not available

runs:
using: "composite"
steps:
- name: Create or reuse cache
id: cache-create
uses: actions/cache@v4
with:
path: |
${{ inputs.venv-dir }}
${{ inputs.precommit-home }}
key: ${{ inputs.cache-key }}
- name: Create Python virtual environment
if: ${{ steps.cache-create.outputs.cache-hit != 'true' }}
shell: bash
run: |
pip install virtualenv --upgrade
python -m venv venv
. venv/bin/activate
pip install uv
uv pip install -U pip setuptools wheel
# 20220124 Mimic setup_test.sh
uv pip install --upgrade -r requirements_commit.txt -r requirements_test.txt -c https://raw.githubusercontent.com/home-assistant/core/dev/homeassistant/package_constraints.txt -r https://raw.githubusercontent.com/home-assistant/core/dev/requirements_test.txt -r https://raw.githubusercontent.com/home-assistant/core/dev/requirements_test_pre_commit.txt
uv pip install --upgrade pytest-asyncio
- name: Install pre-commit dependencies
if: ${{ steps.cache-create.outputs.cache-hit != 'true' }}
shell: bash
run: |
. venv/bin/activate
pre-commit install-hooks
- name: Save cache if (purposely) created
if: ${{ inputs.fail-on-miss == 'false' && steps.cache-create.outputs.cache-hit != 'true' }}
uses: actions/cache/save@v4
with:
key: ${{ inputs.cache-key }}
path: |
${{ inputs.venv-dir }}
${{ inputs.precommit-home }}
- name: Fail job if Python cache restore failed
if: ${{ inputs.fail-on-miss == 'true' && steps.cache-create.outputs.cache-hit != 'true' }}
shell: bash
run: |
echo "Failed to restore cache for ${{ inputs.python-version}} virtual environment from cache"
exit 1
Loading
Loading