Files
semantica/.github/workflows/format.yml
T

75 lines
2.0 KiB
YAML

name: Format Code
# Automatically formats code with black and isort
# Runs on: pull requests or manual trigger
on:
pull_request:
branches: [main, develop]
push:
branches: [main, develop]
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
format:
name: Format Code
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install black isort
- name: Check formatting
if: github.event_name == 'pull_request'
run: |
black --check semantica/ || exit 1
isort --check-only semantica/ || exit 1
- name: Format with black
if: github.event_name != 'pull_request'
run: black semantica/
- name: Sort imports with isort
if: github.event_name != 'pull_request'
run: isort semantica/
- name: Check for changes
if: github.event_name != 'pull_request'
id: verify-changed-files
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "changed=false" >> $GITHUB_OUTPUT
fi
- name: Create Pull Request
if: github.event_name != 'pull_request' && steps.verify-changed-files.outputs.changed == 'true'
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "style: Auto-format code with black and isort"
title: "Auto-format code"
body: |
This PR automatically formats code using black and isort.
**Changes:**
- Code formatted with black
- Imports sorted with isort
branch: auto-format-code
delete-branch: true