|
1 | 1 | # This workflow will install Python dependencies, run tests and lint with a variety of Python versions |
2 | 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions |
3 | 3 |
|
4 | | -name: Test against HA-core using pytest-homeassistant-custom-component |
| 4 | +name: Test against HA-core |
5 | 5 |
|
6 | 6 | env: |
7 | | - CACHE_VERSION: 10 |
| 7 | + CACHE_VERSION: 11 |
8 | 8 | DEFAULT_PYTHON: "3.13" |
| 9 | + PRE_COMMIT_HOME: ~/.cache/pre-commit |
| 10 | + VENV: venv |
| 11 | + |
| 12 | +# Do not run on 'push' (as the flow doesn't have access to the labels) - also disabled workflow_dispatch as such |
| 13 | +# Workaround could be something like |
| 14 | +# - name: Get PR labels |
| 15 | +# run: | |
| 16 | +# PR_LABELS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ |
| 17 | +# "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels") |
| 18 | +# echo "PR Labels: $PR_LABELS" |
9 | 19 |
|
10 | 20 | on: |
11 | | - workflow_dispatch: |
12 | | - push: |
13 | | - schedule: |
14 | | - - cron: "0 0 * * 0" |
15 | | -# pull_request: |
| 21 | + pull_request: |
| 22 | + types: |
| 23 | + - opened |
| 24 | + - synchronize |
| 25 | + - labeled |
| 26 | + - unlabeled |
16 | 27 |
|
17 | 28 | jobs: |
18 | | - # Prepare default python version environment |
19 | | - ha-core-prepare: |
| 29 | + # Determine cache key once |
| 30 | + cache: |
20 | 31 | runs-on: ubuntu-latest |
21 | | - name: Setup for HA-core |
| 32 | + name: Cache identify |
| 33 | + outputs: |
| 34 | + cache-key: ${{ steps.set-key.outputs.cache-key }} |
22 | 35 | steps: |
23 | 36 | - name: Check out committed code |
24 | | - uses: actions/checkout@v4.2.2 |
| 37 | + uses: actions/checkout@v4 |
25 | 38 | - name: Set up Python ${{ env.DEFAULT_PYTHON }} |
26 | 39 | id: python |
27 | | - uses: actions/setup-python@v5.6.0 |
| 40 | + uses: actions/setup-python@v5 |
28 | 41 | with: |
29 | 42 | python-version: ${{ env.DEFAULT_PYTHON }} |
30 | | - - name: Prepare virtual env for testing |
31 | | - run: | |
32 | | - scripts/setup_test.sh |
33 | | - - name: Test |
34 | | - run: | |
35 | | - scripts/tests_and_coverage.sh test_and_coverage |
36 | | - - name: Quality |
| 43 | + - name: Fetch HA pyproject |
| 44 | + id: core-version |
| 45 | + run: wget -O ha_pyproject.toml "https://raw.githubusercontent.com/home-assistant/core/refs/heads/dev/pyproject.toml" |
| 46 | + - name: Compute cache key |
| 47 | + id: set-key |
| 48 | + 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', 'ha_pyproject.toml') }}" >> "$GITHUB_OUTPUT" |
| 49 | + |
| 50 | + # Prepare default python version environment |
| 51 | + prepare: |
| 52 | + runs-on: ubuntu-latest |
| 53 | + needs: cache |
| 54 | + name: Prepare |
| 55 | + steps: |
| 56 | + - name: Prepare code checkout and python/pre-commit setup |
| 57 | + id: cache-reuse |
| 58 | + uses: plugwise/gh-actions/prepare-python-and-code@v1 |
| 59 | + with: |
| 60 | + cache-key: ${{ needs.cache.outputs.cache-key }} |
| 61 | + fail-on-miss: false # First time create cache (if not already exists) |
| 62 | + python-version: ${{ env.DEFAULT_PYTHON }} |
| 63 | + venv-dir: ${{ env.VENV }} |
| 64 | + precommit-home: ${{ env.PRE_COMMIT_HOME }} |
| 65 | + clone-core: "true" |
| 66 | + |
| 67 | + # Prepare default python version environment |
| 68 | + ha-core-release: |
| 69 | + runs-on: ubuntu-latest |
| 70 | + name: Setup for HA-core (release/master) |
| 71 | + needs: |
| 72 | + - cache |
| 73 | + - prepare |
| 74 | + steps: |
| 75 | + - name: Check out committed code |
| 76 | + uses: actions/checkout@v4 |
| 77 | + - name: Restore cached environment |
| 78 | + id: cache-reuse |
| 79 | + uses: plugwise/gh-actions/restore-venv@v1 |
| 80 | + with: |
| 81 | + cache-key: ${{ needs.cache.outputs.cache-key }} |
| 82 | + python-version: ${{ env.DEFAULT_PYTHON }} |
| 83 | + venv-dir: ${{ env.VENV }} |
| 84 | + precommit-home: ${{ env.PRE_COMMIT_HOME }} |
| 85 | + - name: Test through HA-core (master/release) |
| 86 | + id: ha_core_release_tests |
37 | 87 | run: | |
38 | | - scripts/tests_and_coverage.sh linting |
| 88 | + set +e |
| 89 | + GITHUB_ACTIONS="" scripts/core-testing.sh |
| 90 | + EXIT_CODE=$? |
| 91 | + exit $EXIT_CODE |
39 | 92 |
|
40 | 93 | shellcheck: |
41 | 94 | name: Shellcheck |
|
0 commit comments