Feature: Add Ruff GitHub Workflow #1
Workflow file for this run
This file contains 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
name: Ruff Linter and Auto Fix | |
on: [push, pull_request] | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
lint: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.x' | |
- name: Install Ruff | |
run: | | |
python -m pip install --upgrade pip | |
pip install ruff | |
- name: Run Ruff Check and Capture Output | |
id: ruff-check | |
continue-on-error: true | |
run: | | |
echo "Running Ruff check with configuration from .ruff.toml..." | |
ruff_output=$(ruff check . --config ruff.toml || true) | |
echo "$ruff_output" | |
echo 'RUFF_OUTPUT<<EOF' >> $GITHUB_ENV | |
echo "$ruff_output" >> $GITHUB_ENV | |
echo 'EOF' >> $GITHUB_ENV | |
- name: Check if Ruff Found Errors | |
id: check-ruff-errors | |
run: | | |
if [[ "${{ env.RUFF_OUTPUT }}" != *"All checks passed!"* ]]; then | |
echo "Errors found by Ruff." | |
echo "errors_found=true" >> $GITHUB_OUTPUT | |
else | |
echo "No errors found by Ruff." | |
echo "errors_found=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Run Ruff Fix | |
if: steps.check-ruff-errors.outputs.errors_found == 'true' | |
run: | | |
echo "Running Ruff fix..." | |
ruff check . --config ruff.toml --fix || true | |
ruff format || true | |
- name: Create Pull Request for Style Fixes | |
if: steps.check-ruff-errors.outputs.errors_found == 'true' | |
uses: peter-evans/create-pull-request@v5 | |
with: | |
title: 'style fixes by ruff' | |
body: 'This PR contains automated style fixes generated by Ruff.' | |
branch: 'ruff/style-fixes' | |
labels: 'auto-generated' | |
commit-message: 'style fixes by ruff' | |
author: 'github-actions[bot] <github-actions[bot]@users.noreply.github.com>' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |