build: pre-commit autoupdate (#21) #62
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| name: CI | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| workflow_dispatch: | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| lint: | |
| name: Lint | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v7 | |
| - name: Check version consistency (manifest.json vs pyproject.toml) | |
| run: | | |
| MANIFEST_VERSION=$(jq -r '.version' custom_components/dreame_vacuum/manifest.json) | |
| PYPROJECT_VERSION=$(sed -n 's/^version = "\([^"]*\)"/\1/p' pyproject.toml) | |
| if [ "$MANIFEST_VERSION" != "$PYPROJECT_VERSION" ]; then | |
| echo "::error::Version mismatch: manifest.json ($MANIFEST_VERSION) != pyproject.toml ($PYPROJECT_VERSION)" | |
| exit 1 | |
| fi | |
| echo "Version consistent: $MANIFEST_VERSION" | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.11" | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install ruff | |
| - name: Run Ruff linter | |
| run: ruff check custom_components/ tests/ | |
| - name: Run Ruff formatter check | |
| run: ruff format --check custom_components/ tests/ | |
| validate: | |
| name: Validate | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v7 | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.11" | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install "bandit[toml]" | |
| - name: Run Bandit security linter | |
| run: bandit -c pyproject.toml -r custom_components/ | |
| typecheck: | |
| name: Type check (mypy ratchet) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v7 | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.13" | |
| # Reuse the test stack (pytest-homeassistant-custom-component pins a | |
| # Home Assistant compatible with pillow/numpy) plus mypy. Installing | |
| # requirements-dev.txt here is impossible: its pinned pillow/numpy | |
| # conflict with the Home Assistant pin. | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements_test.txt | |
| pip install pillow numpy pybase64 requests pycryptodome python-miio mini-racer paho-mqtt | |
| pip install mypy types-requests | |
| # Only the modules opted-in via [tool.mypy] in pyproject.toml are checked; | |
| # the rest stay under the blanket ignore. Grow the ratchet there, not here. | |
| - name: Run mypy | |
| run: mypy custom_components/dreame_vacuum | |
| test: | |
| name: Test (Python ${{ matrix.python-version }}) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 20 | |
| permissions: | |
| contents: read | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| python-version: ["3.12", "3.13"] | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v7 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements_test.txt | |
| pip install pillow numpy pybase64 requests pycryptodome python-miio mini-racer paho-mqtt | |
| - name: Run tests with coverage | |
| run: pytest tests/ -v --cov=custom_components/dreame_vacuum --cov-report=xml --cov-report=term-missing | |
| - name: Upload coverage to Codecov | |
| if: matrix.python-version == '3.12' | |
| uses: codecov/codecov-action@v7 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| files: ./coverage.xml | |
| fail_ci_if_error: false | |
| pre-commit: | |
| name: Pre-commit (prek) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v7 | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.13" | |
| cache: pip | |
| - name: Install prek | |
| run: python -m pip install prek | |
| - name: Cache prek hooks | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.cache/prek | |
| key: prek-${{ runner.os }}-${{ hashFiles('.pre-commit-config.yaml') }} | |
| restore-keys: prek-${{ runner.os }}- | |
| - name: Run prek | |
| run: prek run --all-files --show-diff-on-failure --color=always |