|
| 1 | +name: "Restore venv and pre-commit from cache" |
| 2 | +description: "Restores the venv and pre-commit cache or fails" |
| 3 | + |
| 4 | +inputs: |
| 5 | + python-version: |
| 6 | + required: true |
| 7 | + venv-dir: |
| 8 | + required: true |
| 9 | + precommit-home: |
| 10 | + required: true |
| 11 | + cache-key: |
| 12 | + required: true |
| 13 | + |
| 14 | + fail-on-miss: |
| 15 | + required: false |
| 16 | + default: "true" # DefauLt fail if not available |
| 17 | + |
| 18 | +runs: |
| 19 | + using: "composite" |
| 20 | + steps: |
| 21 | + - name: Create or reuse cache |
| 22 | + id: cache-create |
| 23 | + uses: actions/cache@v4 |
| 24 | + with: |
| 25 | + path: | |
| 26 | + ${{ inputs.venv-dir }} |
| 27 | + ${{ inputs.precommit-home }} |
| 28 | + key: ${{ inputs.cache-key }} |
| 29 | + - name: Create Python virtual environment |
| 30 | + if: ${{ steps.cache-create.outputs.cache-hit != 'true' }} |
| 31 | + shell: bash |
| 32 | + run: | |
| 33 | + pip install virtualenv --upgrade |
| 34 | + python -m venv venv |
| 35 | + . venv/bin/activate |
| 36 | + pip install uv |
| 37 | + uv pip install -U pip setuptools wheel |
| 38 | + # 20220124 Mimic setup_test.sh |
| 39 | + 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 |
| 40 | + uv pip install --upgrade pytest-asyncio |
| 41 | + - name: Install pre-commit dependencies |
| 42 | + if: ${{ steps.cache-create.outputs.cache-hit != 'true' }} |
| 43 | + shell: bash |
| 44 | + run: | |
| 45 | + . venv/bin/activate |
| 46 | + pre-commit install-hooks |
| 47 | + - name: Save cache if (purposely) created |
| 48 | + if: ${{ inputs.fail-on-miss == 'false' && steps.cache-create.outputs.cache-hit != 'true' }} |
| 49 | + uses: actions/cache/save@v4 |
| 50 | + with: |
| 51 | + key: ${{ inputs.cache-key }} |
| 52 | + path: | |
| 53 | + ${{ inputs.venv-dir }} |
| 54 | + ${{ inputs.precommit-home }} |
| 55 | + - name: Fail job if Python cache restore failed |
| 56 | + if: ${{ inputs.fail-on-miss == 'true' && steps.cache-create.outputs.cache-hit != 'true' }} |
| 57 | + shell: bash |
| 58 | + run: | |
| 59 | + echo "Failed to restore cache for ${{ inputs.python-version}} virtual environment from cache" |
| 60 | + exit 1 |
0 commit comments