Run Ruff linting for Python code quality and style enforcement.
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 }}| 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 |
None
- Restore Cache: Restores dependencies if cache key provided
- Add to PATH: Adds
.venv/binto PATH for ruff access - Run Ruff Check: Executes
ruff checkwith optional custom config - Run Ruff Format Check: Executes
ruff format --checkto verify formatting
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 }}jobs:
ruff:
uses: whisller/forge-ci/.github/workflows/forge-ci-python-tools-ruff.yml@v1
with:
ruff-config: 'config/ruff.toml'jobs:
ruff:
uses: whisller/forge-ci/.github/workflows/forge-ci-python-tools-ruff.yml@v1Ruff 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"]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.txtProblem: 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"