-
Notifications
You must be signed in to change notification settings - Fork 159
47 lines (39 loc) · 1.52 KB
/
autoblack.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
name: autoblack
on: [pull_request]
env:
PYTHON_VERSION: "3.12.1"
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install poetry using pipx
run: |
pipx install poetry
pipx ensurepath
- uses: actions/setup-python@v5
with:
python-version: "3.12.1"
cache: "poetry"
- name: Install dependencies
run: |
poetry config virtualenvs.in-project true
poetry install --no-interaction --no-root --only linting
- name: Run Black autoformatter
run: poetry run black .
- name: If needed, commit black changes to the pull request
run: |
git config user.name "$(git log -n 1 --pretty=format:%an)"
git config user.email "$(git log -n 1 --pretty=format:%ae)"
# short-circuit if we have no changes, otherwise attempt to commit and push
# should only fail on forks, in which case contributors will need to manually run black, commit, and push
git diff-index --quiet HEAD || (echo "Attempting to commit changes" && git commit -am 'lint with black' && git push -f)
- name: Run black --check
run: poetry run black --check .