CR: cleanup test_usb.py #2880
Workflow file for this run
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
| # This workflow will install Python dependencies, run tests and lint with a variety of Python versions | |
| # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | |
| name: Latest commit | |
| env: | |
| CACHE_VERSION: 5 | |
| DEFAULT_PYTHON: "3.13" | |
| PRE_COMMIT_HOME: ${{ github.workspace }}/.cache/pre-commit | |
| VENV: venv | |
| on: | |
| schedule: | |
| - cron: "2 4 * * 0" # weekly | |
| workflow_dispatch: | |
| push: | |
| #pull_request: | |
| jobs: | |
| # Determine cache key once | |
| cache: | |
| runs-on: ubuntu-latest | |
| name: Cache identify | |
| outputs: | |
| cache-key: ${{ steps.set-key.outputs.cache-key }} | |
| python-version: ${{ steps.python.outputs.python-version }} # Ensure all runners use THIS minor version | |
| steps: | |
| - name: Check out committed code | |
| uses: actions/checkout@v5 | |
| - name: Set up Python and determine minor version for ${{ env.DEFAULT_PYTHON }} | |
| id: python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ env.DEFAULT_PYTHON }} | |
| - 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_commit.txt', 'requirements_test.txt', '.pre-commit-config.yaml') }}" >> "$GITHUB_OUTPUT" | |
| # Prepare default python version environment | |
| prepare: | |
| runs-on: ubuntu-latest | |
| needs: cache | |
| name: Prepare | |
| steps: | |
| - name: Check out committed code | |
| uses: actions/checkout@v5 | |
| - name: Set up Python ${{ needs.cache.outputs.python-version }} | |
| id: python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ needs.cache.outputs.python-version }} | |
| - name: Create or reuse cache | |
| id: cache-reuse | |
| uses: ./.github/actions/restore-venv | |
| 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 }} | |
| venv-dir: ${{ env.VENV }} | |
| precommit-home: ${{ env.PRE_COMMIT_HOME }} | |
| ruff: | |
| runs-on: ubuntu-latest | |
| name: Ruff check and force | |
| needs: | |
| - cache | |
| - prepare | |
| steps: | |
| - name: Check out committed code | |
| uses: actions/checkout@v5 | |
| with: | |
| persist-credentials: false | |
| - name: Set up Python ${{ needs.cache.outputs.python-version }} | |
| id: python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ needs.cache.outputs.python-version }} | |
| - name: Create or reuse cache | |
| id: cache-reuse | |
| uses: ./.github/actions/restore-venv | |
| with: | |
| cache-key: ${{ needs.cache.outputs.cache-key }} | |
| python-version: ${{ steps.python.outputs.python-version }} | |
| venv-dir: ${{ env.VENV }} | |
| precommit-home: ${{ env.PRE_COMMIT_HOME }} | |
| - name: Ruff (check) | |
| run: | | |
| . venv/bin/activate | |
| ruff check plugwise_usb/ tests/ | |
| - name: If needed, commit ruff changes to the pull request | |
| if: failure() | |
| run: | | |
| . venv/bin/activate | |
| ruff format plugwise_usb/ tests/ | |
| git config --global user.name 'autoruff' | |
| git config --global user.email '[email protected]' | |
| git remote set-url origin https://x-access-token:${{ secrets.PAT_CT_PYPLUSB }}@github.com/$GITHUB_REPOSITORY | |
| git checkout $GITHUB_HEAD_REF | |
| git commit -am "fixup: ${GITHUB_REF##*/} Python code reformatted using Ruff" | |
| git push origin ${GITHUB_REF##*/} | |
| commitcheck: | |
| runs-on: ubuntu-latest | |
| name: Check commit | |
| needs: | |
| - cache | |
| - prepare | |
| - ruff | |
| - shellcheck | |
| - dependencies_check | |
| steps: | |
| - name: Check out committed code | |
| uses: actions/checkout@v5 | |
| - name: Set up Python ${{ needs.cache.outputs.python-version }} | |
| id: python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ needs.cache.outputs.python-version }} | |
| - name: Create or reuse cache | |
| id: cache-reuse | |
| uses: ./.github/actions/restore-venv | |
| with: | |
| cache-key: ${{ needs.cache.outputs.cache-key }} | |
| python-version: ${{ steps.python.outputs.python-version }} | |
| venv-dir: ${{ env.VENV }} | |
| precommit-home: ${{ env.PRE_COMMIT_HOME }} | |
| - name: Verify commit | |
| run: | | |
| . venv/bin/activate | |
| pre-commit run --show-diff-on-failure --color=always --all-files --hook-stage manual pylint | |
| # - name: Biome lint | |
| # run: | | |
| # . venv/bin/activate | |
| # mkdir -p ./tmp && curl -sL "https://github.com/biomejs/biome/releases/download/%40biomejs%2Fbiome%402.0.0/biome-linux-x64" -o ./tmp/biome && chmod +x ./tmp/biome | |
| # pre-commit run --show-diff-on-failure --color=always --all-files --hook-stage manual biome | |
| - name: Lint markdown files | |
| run: | | |
| . venv/bin/activate | |
| pre-commit run --show-diff-on-failure --color=always --all-files --hook-stage manual markdownlint | |
| pytest: | |
| runs-on: ubuntu-latest | |
| name: Run pytest using Python ${{ matrix.python-version }} | |
| needs: | |
| - cache | |
| - prepare | |
| - commitcheck | |
| strategy: | |
| matrix: | |
| python-version: ["3.13"] | |
| steps: | |
| - name: Check out committed code | |
| uses: actions/checkout@v5 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| id: python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Create or reuse cache | |
| id: cache-reuse | |
| uses: ./.github/actions/restore-venv | |
| 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: ${{ steps.python.outputs.python-version }} # Force to installed python minor | |
| venv-dir: ${{ env.VENV }} | |
| precommit-home: ${{ env.PRE_COMMIT_HOME }} | |
| - name: Run all tests | |
| run: | | |
| . venv/bin/activate | |
| pytest --log-level info tests/*.py --cov='.' | |
| - name: Upload coverage artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-${{ matrix.python-version }} | |
| path: .coverage | |
| if-no-files-found: error | |
| include-hidden-files: true | |
| mypy: | |
| if: false # disables the job --> "Code is not up to par for mypy, skipping - see #171" | |
| runs-on: ubuntu-latest | |
| name: Run mypy | |
| needs: | |
| - cache | |
| - prepare | |
| - pytest | |
| steps: | |
| - name: Check out committed code | |
| uses: actions/checkout@v5 | |
| with: | |
| persist-credentials: false | |
| - name: Set up Python ${{ needs.cache.outputs.python-version }} | |
| id: python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ needs.cache.outputs.python-version }} | |
| - name: Create or reuse cache | |
| id: cache-reuse | |
| uses: ./.github/actions/restore-venv | |
| with: | |
| cache-key: ${{ needs.cache.outputs.cache-key }} | |
| python-version: ${{ steps.python.outputs.python-version }} | |
| venv-dir: ${{ env.VENV }} | |
| precommit-home: ${{ env.PRE_COMMIT_HOME }} | |
| - name: Run mypy | |
| run: | | |
| . venv/bin/activate | |
| uv pip list | grep -i mypy | |
| mypy plugwise_usb/ | |
| # Check shellscripts | |
| shellcheck: | |
| name: Shellcheck | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out committed code | |
| uses: actions/checkout@v5 | |
| - name: Run ShellCheck | |
| uses: ludeeus/action-shellcheck@master | |
| # Check for missing python dependencies | |
| dependencies_check: | |
| runs-on: ubuntu-latest | |
| name: Dependency | |
| steps: | |
| - name: Check out committed code | |
| uses: actions/checkout@v5 | |
| - name: Run dependency checker | |
| run: scripts/dependencies_check.sh debug | |
| coverage: | |
| name: Process test coverage | |
| runs-on: ubuntu-latest | |
| needs: | |
| - cache | |
| - prepare | |
| - pytest | |
| # - mypy # Re-instate mypy when we are ready | |
| steps: | |
| - name: Check out committed code | |
| uses: actions/checkout@v5 | |
| - name: Set up Python ${{ needs.cache.outputs.python-version }} | |
| id: python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ needs.cache.outputs.python-version }} | |
| - name: Create or reuse cache | |
| id: cache-reuse | |
| uses: ./.github/actions/restore-venv | |
| with: | |
| cache-key: ${{ needs.cache.outputs.cache-key }} | |
| python-version: ${{ steps.python.outputs.python-version }} | |
| venv-dir: ${{ env.VENV }} | |
| precommit-home: ${{ env.PRE_COMMIT_HOME }} | |
| - name: Download all coverage artifacts | |
| uses: actions/download-artifact@v5 | |
| with: | |
| pattern: coverage-* | |
| merge-multiple: true | |
| path: ${{ github.workspace }}/artifacts | |
| - name: Combine coverage results | |
| run: | | |
| . venv/bin/activate | |
| coverage combine artifacts/.coverage* | |
| #coverage report --fail-under=80 ## plugwise is at 94, set to 80 for plugwise_usb | |
| echo "***" | |
| echo "***" | |
| echo "Coverage is not up to par, skipping" | |
| echo "***" | |
| echo "***" | |
| coverage xml | |
| - name: Upload coverage to Codecov | |
| uses: codecov/codecov-action@v5 | |
| env: | |
| CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | |
| test-publishing: | |
| name: Build and publish Python 🐍 distributions 📦 to TestPyPI | |
| runs-on: ubuntu-latest | |
| environment: testpypi | |
| permissions: | |
| contents: read # Required by actions/checkout | |
| id-token: write # Needed for OIDC-based Trusted Publishing | |
| needs: | |
| - cache | |
| - prepare | |
| - coverage | |
| # - mypy # Re-instate mypy when we are ready | |
| steps: | |
| - name: Check out committed code | |
| uses: actions/checkout@v5 | |
| - name: Prepare uv | |
| run: | | |
| pip install uv | |
| uv venv --seed venv | |
| . venv/bin/activate | |
| uv pip install toml | |
| - name: Check for existing package on TestPyPI | |
| id: check_package | |
| run: | | |
| . venv/bin/activate | |
| PACKAGE_VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])") | |
| PACKAGE_NAME=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['name'])") | |
| echo "Checking for package: $PACKAGE_NAME==$PACKAGE_VERSION" | |
| if curl -s "https://test.pypi.org/pypi/$PACKAGE_NAME/json" | jq -r '.releases | keys[]' | grep -q "^$PACKAGE_VERSION$"; then | |
| echo "Package version already exists. Skipping upload." | |
| echo "should_publish=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "Package version does not exist. Proceeding with upload." | |
| echo "should_publish=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Build | |
| if: steps.check_package.outputs.should_publish == 'true' | |
| run: | | |
| . venv/bin/activate | |
| uv build | |
| - name: Publish distribution 📦 to TestPyPI | |
| if: steps.check_package.outputs.should_publish == 'true' | |
| run: | | |
| . venv/bin/activate | |
| uv publish --publish-url https://test.pypi.org/legacy/ | |
| complexity: | |
| name: Process test complexity | |
| runs-on: ubuntu-latest | |
| needs: | |
| - cache | |
| - prepare | |
| - coverage | |
| steps: | |
| - name: Check out committed code | |
| uses: actions/checkout@v5 | |
| - name: Set up Python ${{ needs.cache.outputs.python-version }} | |
| id: python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ needs.cache.outputs.python-version }} | |
| - name: Create or reuse cache | |
| id: cache-reuse | |
| uses: ./.github/actions/restore-venv | |
| with: | |
| cache-key: ${{ needs.cache.outputs.cache-key }} | |
| python-version: ${{ steps.python.outputs.python-version }} | |
| venv-dir: ${{ env.VENV }} | |
| precommit-home: ${{ env.PRE_COMMIT_HOME }} | |
| - name: Run complexity report (click to view details) | |
| run: | | |
| . venv/bin/activate | |
| echo "Showing complexity higher or equal to 'C'" | |
| radon cc plugwise/ tests/ -s -nc --no-assert |