-
Notifications
You must be signed in to change notification settings - Fork 29
53 lines (46 loc) · 1.83 KB
/
black-format-code.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
49
50
51
52
53
# SPDX-FileCopyrightText: 2017-2023 Contributors to the OpenSTEF project <korte.termijn.prognoses@alliander.com> # noqa E501
#
# SPDX-License-Identifier: MPL-2.0
# Copied from https://github.com/psf/black/actions/runs/17913292/workflow
# GitHub Action that uses Black to reformat the Python code in an incoming pull request.
# If all Python code in the pull request is compliant with Black then this Action
# does nothing. Otherwise, Black is run and its changes are committed to the
# incoming pull request. See https://github.com/cclauss/autoblack for a similar example.
name: Black Format Code
on: [pull_request]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.11']
steps:
# Checkout
- name: Checkout
uses: actions/checkout@v2
# Setup
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
# Install black
- name: Install Black
run: pip install black==23.9.1 pydocstyle==6.1.1 docformatter==1.5.0 toml==0.10.2
# Run black --check
- name: Run black --check . and PydocStyle check
run: |
black --check .
pydocstyle .
# Run black (if needed)
- name: If needed, commit black changes to the pull request
if: failure()
run: |
black .
docformatter openstef --recursive --wrap-summaries 120 --in-place
git config --global user.name 'black'
git config --global user.email 'action@github.com'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
git fetch
git checkout ${{ github.head_ref }}
git commit --signoff -am "Format Python code with Black"
git push