Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions .github/workflows/format-python.yml

This file was deleted.

71 changes: 71 additions & 0 deletions .github/workflows/python-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
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
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 ":white_check_mark: All Python code is properly formatted."
else
echo "$output"
echo "<details><summary>:rotating_light: Python code is not properly formatted. Click to expand.</summary>" > output.txt
echo "" >> output.txt
echo '```' >> output.txt
echo "$output" >> output.txt
echo '```' >> output.txt
echo "" >> output.txt
echo '</details>' >> output.txt
echo "" >> output.txt
echo 'Please run `ruff format` to format the code.' >> output.txt
gh pr comment ${{ github.event.pull_request.number }} --body-file output.txt
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
output=$(ruff check)
exit_code=$?
if [ $exit_code -eq 0 ]; then
echo "No linting errors found."
gh pr comment ${{ github.event.pull_request.number }} --body ":white_check_mark: No linting errors found in Python code."
else
echo "$output"
echo "<details><summary>:rotating_light: Linting errors found in Python code. Click to expand.</summary>" > output.txt
echo "" >> output.txt
echo '```' >> output.txt
echo "$output" >> output.txt
echo '```' >> output.txt
echo "" >> output.txt
echo '</details>' >> output.txt
echo "" >> output.txt
echo 'Tip: You can run `ruff check --fix` to fix automatically fixable errors.' >> output.txt
gh pr comment ${{ github.event.pull_request.number }} --body-file output.txt
exit 1
fi
Loading