diff --git a/.github/workflows/formatting.yml b/.github/workflows/formatting.yml index e1be1eb..54382b3 100644 --- a/.github/workflows/formatting.yml +++ b/.github/workflows/formatting.yml @@ -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