Skip to content

🔧 Implement Ruff as required check instead of Black creating a commit re-formatting code #100

🔧 Implement Ruff as required check instead of Black creating a commit re-formatting code

🔧 Implement Ruff as required check instead of Black creating a commit re-formatting code #100

Workflow file for this run

name: Ensure formatted code
on:
pull_request:
types: [ opened, edited, reopened, synchronize, ready_for_review ]
workflow_dispatch:
permissions:
contents: read
pull-requests: write
jobs:
format_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install ruff
run: pip install ruff
- name: Check formatting for Python code
env:
GH_TOKEN: ${{ github.token }}
run: |
set +e
format_output=$(ruff format --check)
exit_code=$?
if [ $exit_code -eq 0 ]; then
echo "All Python code is properly formatted."
gh pr comment ${{ github.event.pull_request.number }} --body "All Python code is properly formatted."
else
echo "$format_output"
echo "Some Python code is not properly formatted."
echo "Please run 'ruff format' to format the code."
gh pr comment ${{ github.event.pull_request.number }} --body "Error: \\\`\\\`\\\`\n${format_output}\n\\\`\\\`\\\`"
exit 1
fi
# lint:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - name: Install ruff
# run: pip install ruff
# - name: Lint Python code
# env:
# GH_TOKEN: ${{ github.token }}
# run: |
# set +e
# check_output=$(ruff check)
# exit_code=$?
# if [ $exit_code -eq 0 ]; then
# echo "All Python code is properly formatted."
# gh pr comment ${{ github.event.pull_request.number }} --body "No linting errors found."
# else
# echo "$check_output" > check_output.txt
# echo "Some Python code has linting errors." >> check_output.txt
# echo "Please run 'ruff check --fix' to fix the errors." >> check_output.txt
# gh pr comment ${{ github.event.pull_request.number }} --body "```\n$(cat check_output.txt)\n```"
# exit 1
# fi