-
Notifications
You must be signed in to change notification settings - Fork 1.4k
48 lines (48 loc) · 1.86 KB
/
isort_format.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
name: Code Formatter (isort)
on:
pull_request:
paths:
- '**.py'
workflow_dispatch:
jobs:
isort-check:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }} # Checkout the PR branch
fetch-depth: 0 # Fetch all history for all branches and tags
- name: "Setup Python, Poetry and Dependencies"
uses: packetcoders/action-setup-cache-python-poetry@main
with:
python-version: "3.12"
poetry-version: "1.8.2"
install-args: "-E dev" # TODO: change this to --group dev when PR #842 lands
- name: Run isort
id: isort
run: |
output=$(poetry run isort --profile black --check-only --diff . | grep -v "Skipped" || true)
echo "$output"
if [ -n "$output" ]; then
echo "isort_changed=true" >> $GITHUB_OUTPUT
else
echo "isort_changed=false" >> $GITHUB_OUTPUT
fi
continue-on-error: true
- name: Auto-fix with isort and commit
if: steps.isort.outputs.isort_changed == 'true' && !contains(github.event.pull_request.labels.*.name, 'check-only')
run: |
poetry run isort --profile black .
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
if [[ -n $(git status -s) ]]; then
git add -A
git commit -m "Apply isort import ordering"
git push
else
echo "No changes to commit"
fi
- name: Error if 'check-only' label is present and changes are needed
if: steps.isort.outputs.isort_changed == 'true' && contains(github.event.pull_request.labels.*.name, 'check-only')
run: echo "Isort check failed. Please run 'isort .' locally to fix import orders." && exit 1