Lint and Auto-fix Code #2
Workflow file for this run
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
name: Lint and Auto-fix Code | |
on: | |
push: | |
branches: | |
- main # Run on pushes to the main branch (you can specify other branches as needed) | |
pull_request: | |
branches: | |
- main # Optionally run on pull requests targeting the main branch | |
jobs: | |
lint: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.x' # Specify the Python version you're using | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install black isort | |
- name: Run Black (Auto-fix) | |
run: | | |
black . | |
- name: Run Isort (Auto-fix) | |
run: | | |
isort . | |
- name: Commit changes if any | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git add . | |
git diff-index --quiet HEAD || git commit -m "Auto-format: black and isort" || echo "No changes to commit" | |
- name: Push changes back to repository | |
uses: ad-m/[email protected] | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} |