-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dfd1226
commit 87717cc
Showing
1 changed file
with
28 additions
and
28 deletions.
There are no files selected for viewing
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
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 |