Skip to content

Create code_formatter.yml #1

Create code_formatter.yml

Create code_formatter.yml #1

name: Code Formatter
on:
push:
branches:
- main
jobs:
push_format:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install Black
run: pip install black
- name: Run Black
run: black .
- name: Check for changes
id: changes
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "::set-output name=has_changes::true"
else
echo "::set-output name=has_changes::false"
fi
- name: Commit changes
if: steps.changes.outputs.has_changes == 'true'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add --all
git commit -m "Automatic code formatting with black"
- name: Create Pull Request
if: steps.changes.outputs.has_changes == 'true'
uses: peter-evans/create-pull-request@v5
with:
delete-branch: true
body: "Automatic code formatting with black"
title: "Automatic code formatting"
commit-message: "Automatic code formatting with black"
branch: formatter/main