From 93ecb44a4f0b6c1680d822b8752505bc977d00a5 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Sat, 21 Jun 2025 21:27:57 +0200 Subject: [PATCH] Migrate actions to plugwise common gh-actions --- .github/actions/restore-venv/action.yml | 60 --------------- .github/workflows/verify.yml | 98 ++++++++----------------- 2 files changed, 29 insertions(+), 129 deletions(-) delete mode 100644 .github/actions/restore-venv/action.yml diff --git a/.github/actions/restore-venv/action.yml b/.github/actions/restore-venv/action.yml deleted file mode 100644 index 0c920a75f..000000000 --- a/.github/actions/restore-venv/action.yml +++ /dev/null @@ -1,60 +0,0 @@ -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 diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index 725494c2e..4683a4fb4 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -31,6 +31,9 @@ jobs: uses: actions/setup-python@v5 with: python-version: ${{ env.DEFAULT_PYTHON }} + - name: Fetch HA pyproject + id: core-version + run: wget -O ha_pyproject.toml "https://raw.githubusercontent.com/home-assistant/core/refs/heads/dev/pyproject.toml" - name: Compute cache key id: set-key run: echo "cache-key=${{ runner.os }}-venv-cache-${{ env.CACHE_VERSION }}-${{ steps.python.outputs.python-version }}-${{ hashFiles('pyproject.toml', 'requirements_test.txt', '.pre-commit-config.yaml') }}" >> "$GITHUB_OUTPUT" @@ -41,20 +44,13 @@ jobs: needs: cache name: Prepare steps: - - name: Check out committed code - uses: actions/checkout@v4 - - name: Set up Python ${{ env.DEFAULT_PYTHON }} - id: python - uses: actions/setup-python@v5 - with: - python-version: ${{ env.DEFAULT_PYTHON }} - - name: Create or reuse cache + - name: Prepare code checkout and python/pre-commit setup id: cache-reuse - uses: ./.github/actions/restore-venv + uses: plugwise/gh-actions/prepare-python-and-code@v1 with: cache-key: ${{ needs.cache.outputs.cache-key }} - fail-on-miss: false # First time create cache (if not already exists) - python-version: ${{ steps.python.outputs.python-version }} + fail-on-miss: false # First time create cache (if not already exists) + python-version: ${{ env.DEFAULT_PYTHON }} venv-dir: ${{ env.VENV }} precommit-home: ${{ env.PRE_COMMIT_HOME }} @@ -69,17 +65,12 @@ jobs: uses: actions/checkout@v4 with: persist-credentials: false - - name: Set up Python ${{ env.DEFAULT_PYTHON }} - id: python - uses: actions/setup-python@v5 - with: - python-version: ${{ env.DEFAULT_PYTHON }} - - name: Create or reuse cache + - name: Restore cached environment id: cache-reuse - uses: ./.github/actions/restore-venv + uses: plugwise/gh-actions/restore-venv@v1 with: cache-key: ${{ needs.cache.outputs.cache-key }} - python-version: ${{ steps.python.outputs.python-version }} + python-version: ${{ env.DEFAULT_PYTHON }} venv-dir: ${{ env.VENV }} precommit-home: ${{ env.PRE_COMMIT_HOME }} - name: Ruff (with fix) @@ -110,17 +101,12 @@ jobs: steps: - name: Check out committed code uses: actions/checkout@v4 - - name: Set up Python ${{ env.DEFAULT_PYTHON }} - id: python - uses: actions/setup-python@v5 - with: - python-version: ${{ env.DEFAULT_PYTHON }} - - name: Create or reuse cache + - name: Restore cached environment id: cache-reuse - uses: ./.github/actions/restore-venv + uses: plugwise/gh-actions/restore-venv@v1 with: cache-key: ${{ needs.cache.outputs.cache-key }} - python-version: ${{ steps.python.outputs.python-version }} + python-version: ${{ env.DEFAULT_PYTHON }} venv-dir: ${{ env.VENV }} precommit-home: ${{ env.PRE_COMMIT_HOME }} - name: Verify commit @@ -150,18 +136,12 @@ jobs: steps: - name: Check out committed code uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - id: python - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - name: Create or reuse cache + - name: Restore cached environment id: cache-reuse - uses: ./.github/actions/restore-venv + uses: plugwise/gh-actions/restore-venv@v1 with: - cache-key: ${{ needs.cache.outputs.cache-key }}-pytest-matrix-${{ matrix.python-version }} - fail-on-miss: false # First time create cache (if not already exists) - python-version: ${{ matrix.python-version }} + cache-key: ${{ needs.cache.outputs.cache-key }} + python-version: ${{ env.DEFAULT_PYTHON }} venv-dir: ${{ env.VENV }} precommit-home: ${{ env.PRE_COMMIT_HOME }} - name: Run all tests @@ -188,17 +168,12 @@ jobs: uses: actions/checkout@v4 with: persist-credentials: false - - name: Set up Python ${{ env.DEFAULT_PYTHON }} - id: python - uses: actions/setup-python@v5 - with: - python-version: ${{ env.DEFAULT_PYTHON }} - - name: Create or reuse cache + - name: Restore cached environment id: cache-reuse - uses: ./.github/actions/restore-venv + uses: plugwise/gh-actions/restore-venv@v1 with: cache-key: ${{ needs.cache.outputs.cache-key }} - python-version: ${{ steps.python.outputs.python-version }} + python-version: ${{ env.DEFAULT_PYTHON }} venv-dir: ${{ env.VENV }} precommit-home: ${{ env.PRE_COMMIT_HOME }} - name: Run mypy @@ -238,17 +213,12 @@ jobs: steps: - name: Check out committed code uses: actions/checkout@v4 - - name: Set up Python ${{ env.DEFAULT_PYTHON }} - id: python - uses: actions/setup-python@v5 - with: - python-version: ${{ env.DEFAULT_PYTHON }} - - name: Create or reuse cache + - name: Restore cached environment id: cache-reuse - uses: ./.github/actions/restore-venv + uses: plugwise/gh-actions/restore-venv@v1 with: cache-key: ${{ needs.cache.outputs.cache-key }} - python-version: ${{ steps.python.outputs.python-version }} + python-version: ${{ env.DEFAULT_PYTHON }} venv-dir: ${{ env.VENV }} precommit-home: ${{ env.PRE_COMMIT_HOME }} - name: Download all coverage artifacts @@ -275,17 +245,12 @@ jobs: steps: - name: Check out committed code uses: actions/checkout@v4 - - name: Set up Python ${{ env.DEFAULT_PYTHON }} - id: python - uses: actions/setup-python@v5 - with: - python-version: ${{ env.DEFAULT_PYTHON }} - - name: Create or reuse cache + - name: Restore cached environment id: cache-reuse - uses: ./.github/actions/restore-venv + uses: plugwise/gh-actions/restore-venv@v1 with: cache-key: ${{ needs.cache.outputs.cache-key }} - python-version: ${{ steps.python.outputs.python-version }} + python-version: ${{ env.DEFAULT_PYTHON }} venv-dir: ${{ env.VENV }} precommit-home: ${{ env.PRE_COMMIT_HOME }} - name: Install pypa/build @@ -314,17 +279,12 @@ jobs: steps: - name: Check out committed code uses: actions/checkout@v4 - - name: Set up Python ${{ env.DEFAULT_PYTHON }} - id: python - uses: actions/setup-python@v5 - with: - python-version: ${{ env.DEFAULT_PYTHON }} - - name: Create or reuse cache + - name: Restore cached environment id: cache-reuse - uses: ./.github/actions/restore-venv + uses: plugwise/gh-actions/restore-venv@v1 with: cache-key: ${{ needs.cache.outputs.cache-key }} - python-version: ${{ steps.python.outputs.python-version }} + python-version: ${{ env.DEFAULT_PYTHON }} venv-dir: ${{ env.VENV }} precommit-home: ${{ env.PRE_COMMIT_HOME }} - name: Run complexity report (click to view details)