Skip to content

Commit

Permalink
fix formatting for pull requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobbyperson committed Oct 9, 2024
1 parent dfd1226 commit 87717cc
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions .github/workflows/formatting.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
name: Run formatting
name: Lint and Format

on: push
on: [push, pull_request]

permissions:
contents: write

jobs:
format_code:
lint-and-format:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set Up Python
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: '3.x'

- name: Install Dependencies
- name: Install dependencies
run: |
pip install isort ruff black
pip install isort black ruff
- name: Run isort
run: isort .

- name: Run ruff
run: ruff check . --fix
run: |
isort .
- name: Run black
run: black .
run: |
black .
- name: Check for Uncommitted Changes
id: check_changes
- name: Run ruff
run: |
ruff check . --fix
- name: Commit and push changes if needed
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "changes_detected=true" >> $GITHUB_OUTPUT
git config --local user.name "github-actions[bot]"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
if ! git diff --quiet; then
git add .
git commit -m "Format code with isort, black, and ruff [skip ci]"
git push
else
echo "changes_detected=false" >> $GITHUB_OUTPUT
echo "No changes to commit."
fi
- name: Create Pull Request with Formatting Changes
if: steps.check_changes.outputs.changes_detected == 'true'
uses: peter-evans/create-pull-request@v5
with:
commit-message: "Apply code formatting"
branch: formatting-fixes
title: "Apply code formatting"
body: "This pull request applies code formatting using isort, ruff, and black."
delete-branch: true

0 comments on commit 87717cc

Please sign in to comment.