Skip to content

CVector-Energy/python-test

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 

Repository files navigation

CVector Python Test Action

Test Python projects using ruff, mypy, and pytest. Supports both UV and Poetry — auto-detected from your lock file.

What This Action Does

  1. Installs Python
  2. Detects package manager (UV or Poetry) from lock file
  3. Installs the package manager and syncs dependencies (with caching)
  4. Runs ruff format on source directories (auto-fixes in place)
  5. Runs ruff check --fix on source directories (auto-fixes in place)
  6. If checks fail and repair-token is set, commits and pushes fixes
  7. Runs mypy on source directories
  8. Runs pytest

Inputs

Input Description Required Default
python-version Python version to use No 3.14
package-manager auto, uv, or poetry No auto
uv-version UV version to install No 0.11.2
poetry-version Poetry version to install No 2.3.3
src-dirs Source directories for linting (space-separated) No .
working-directory Directory containing pyproject.toml No .
run-pytest Whether to run pytest No true
repair-token Token for git push. Enables auto-repair on failure. No ""

Usage

Basic Usage (auto-detects UV or Poetry)

steps:
  - name: Checkout
    uses: actions/checkout@v6

  - name: Test
    uses: CVector-Energy/python-test@main

With Custom Python Version

steps:
  - name: Checkout
    uses: actions/checkout@v6

  - name: Test
    uses: CVector-Energy/python-test@main
    with:
      python-version: "3.12"

Matrix Testing

jobs:
  test:
    runs-on: ubuntu-24.04
    strategy:
      matrix:
        python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]

    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: Test
        uses: CVector-Energy/python-test@main
        with:
          python-version: ${{ matrix.python-version }}

With Auto-Repair on Pull Requests

When checks fail, the repair step runs ruff check --fix and ruff format, then commits and pushes the fixes. Use a GitHub App token so the push triggers a new workflow run.

jobs:
  test:
    runs-on: ubuntu-24.04
    permissions:
      contents: write
    steps:
      - name: Create GitHub App Token
        id: app
        if: github.event_name == 'pull_request'
        uses: actions/create-github-app-token@v2
        with:
          app-id: ${{ vars.APP_ID }}
          private-key: ${{ secrets.APP_PRIVATE_KEY }}

      - name: Checkout
        uses: actions/checkout@v6
        with:
          ref: ${{ github.head_ref }}
          token: ${{ steps.app.outputs.token || github.token }}

      - name: Test
        uses: CVector-Energy/python-test@main
        with:
          repair-token: ${{ steps.app.outputs.token }}

Requirements

Your project must have:

  • pyproject.toml with [project] section and requires-python
  • uv.lock (for UV) or poetry.lock (for Poetry)

About

GitHub Action for testing a Python repo using ruff, mypy, and pytest

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors