Speed up and simplify github workflows (#1128)

- Enable parallel tests in the CI with pytest-xdist
- Migrate to the official `astral-sh/setup-uv` github action
- Call `pre-commit` run as a single job in CI instead of relisting each
check
- Use `uv` version 0.4.16
- Fix bug with pre-commit cache
- Update `publish.yml` to use  `astral-sh/setup-uv`
This commit is contained in:
Steven B.
2024-09-27 10:27:53 +01:00
committed by GitHub
parent 1ab08f454f
commit 038b6993ca
8 changed files with 67 additions and 87 deletions

View File

@@ -8,7 +8,7 @@ on:
workflow_dispatch: # to allow manual re-runs
env:
UV_VERSION: 0.4.5
UV_VERSION: 0.4.16
jobs:
linting:
@@ -20,7 +20,8 @@ jobs:
python-version: ["3.12"]
steps:
- uses: "actions/checkout@v4"
- name: "Checkout source files"
uses: "actions/checkout@v4"
- name: Setup environment
uses: ./.github/actions/setup
with:
@@ -28,31 +29,10 @@ jobs:
cache-pre-commit: true
uv-version: ${{ env.UV_VERSION }}
uv-install-options: "--all-extras"
- name: "Check supported device md files are up to date"
- name: "Run pre-commit checks"
run: |
uv run pre-commit run generate-supported --all-files
- name: "Linting and code formating (ruff)"
run: |
uv run pre-commit run ruff --all-files
- name: "Typing checks (mypy)"
run: |
source .venv/bin/activate
pre-commit run mypy --all-files
- name: "Run trailing-whitespace"
run: |
uv run pre-commit run trailing-whitespace --all-files
- name: "Run end-of-file-fixer"
run: |
uv run pre-commit run end-of-file-fixer --all-files
- name: "Run check-docstring-first"
run: |
uv run pre-commit run check-docstring-first --all-files
- name: "Run debug-statements"
run: |
uv run pre-commit run debug-statements --all-files
- name: "Run check-ast"
run: |
uv run pre-commit run check-ast --all-files
uv run pre-commit run --all-files --verbose
tests:
@@ -83,6 +63,13 @@ jobs:
- os: ubuntu-latest
python-version: "3.10"
extras: true
# Exclude pypy on windows due to significant performance issues
# running pytest requires ~12 min instead of 2 min on other platforms
- os: windows-latest
python-version: "pypy-3.9"
- os: windows-latest
python-version: "pypy-3.10"
steps:
- uses: "actions/checkout@v4"
@@ -95,11 +82,11 @@ jobs:
- name: "Run tests (no coverage)"
if: ${{ startsWith(matrix.python-version, 'pypy') }}
run: |
uv run pytest
uv run pytest -n auto
- name: "Run tests (with coverage)"
if: ${{ !startsWith(matrix.python-version, 'pypy') }}
run: |
uv run pytest --cov kasa --cov-report xml
uv run pytest -n auto --cov kasa --cov-report xml
- name: "Upload coverage to Codecov"
if: ${{ !startsWith(matrix.python-version, 'pypy') }}
uses: "codecov/codecov-action@v4"

View File

@@ -4,7 +4,8 @@ on:
types: [published]
env:
UV_VERSION: 0.4.5
UV_VERSION: 0.4.16
PYTHON_VERSION: 3.12
jobs:
build-n-publish:
@@ -14,16 +15,19 @@ jobs:
id-token: write
steps:
- uses: actions/checkout@master
- name: Checkout source files
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: "3.x"
python-version: ${{ env.PYTHON_VERSION }}
- name: Install uv
run: |-
pipx install uv==${{ env.UV_VERSION }} --python "${{ steps.setup-python.outputs.python-path }}"
- name: Build a binary wheel and a source tarball
run: uv build
- name: Publish release on pypi
uses: pypa/gh-action-pypi-publish@release/v1