Skip to content

Latest commit

 

History

History
129 lines (93 loc) · 2.78 KB

File metadata and controls

129 lines (93 loc) · 2.78 KB

forge-ci-python-tools-ruff

Run Ruff linting for Python code quality and style enforcement.

Usage

jobs:
  lint:
    uses: whisller/forge-ci/.github/workflows/forge-ci-python-tools-ruff.yml@v1
    with:
      dependencies-cache-key: ${{ needs.dependencies.outputs.dependencies-cache-key }}

Inputs

Input Type Required Default Description
python-version string No '3.12' Python version to use
working-directory string No '.' Working directory for linting
dependencies-cache-key string No '' Cache key from dependency-manager job
ruff-config string No '' Path to custom ruff config file
runs-on string No 'ubuntu-latest' Runner to use

Outputs

None

Behavior

  1. Restore Cache: Restores dependencies if cache key provided
  2. Add to PATH: Adds .venv/bin to PATH for ruff access
  3. Run Ruff Check: Executes ruff check with optional custom config
  4. Run Ruff Format Check: Executes ruff format --check to verify formatting

Examples

With Cached Dependencies

jobs:
  dependencies:
    uses: whisller/forge-ci/.github/workflows/forge-ci-python-tools-dependency-manager.yml@v1

  ruff:
    needs: dependencies
    uses: whisller/forge-ci/.github/workflows/forge-ci-python-tools-ruff.yml@v1
    with:
      dependencies-cache-key: ${{ needs.dependencies.outputs.dependencies-cache-key }}

With Custom Config

jobs:
  ruff:
    uses: whisller/forge-ci/.github/workflows/forge-ci-python-tools-ruff.yml@v1
    with:
      ruff-config: 'config/ruff.toml'

Standalone (No Cache)

jobs:
  ruff:
    uses: whisller/forge-ci/.github/workflows/forge-ci-python-tools-ruff.yml@v1

Configuration

Ruff configuration in pyproject.toml:

[tool.ruff]
line-length = 100
target-version = "py312"

[tool.ruff.lint]
select = ["E", "F", "I", "N", "W"]
ignore = ["E501"]

Or separate ruff.toml:

line-length = 100
target-version = "py312"

[lint]
select = ["E", "F", "I", "N", "W"]

Troubleshooting

Ruff Not Found

Problem: ruff: command not found

Cause: Ruff not installed in dependencies.

Solution: Add ruff to dev dependencies:

# Poetry
poetry add --group dev ruff

# uv
uv add --dev ruff

# venv
echo "ruff>=0.1.0" >> requirements-dev.txt

Format Check Fails

Problem: ruff format --check fails with "would reformat".

Solution: Run ruff format locally and commit:

ruff format .
git add .
git commit -m "style: format code with ruff"

See Also