File tree Expand file tree Collapse file tree 2 files changed +37
-2
lines changed
Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change 7676 if [[ -n "${{ env.FILES }}" ]]; then
7777 cpplint --recursive --quiet ${{ env.FILES }}
7878 fi
79+
80+ black :
81+ runs-on : ubuntu-latest
82+ steps :
83+ - uses : actions/checkout@v4
84+ with :
85+ fetch-depth : 0
86+
87+ - name : Get changed Python files
88+ uses : tj-actions/changed-files@v45
89+ id : changed-files
90+ with :
91+ files : " **/*.py"
92+ separator : " "
93+
94+ - uses : actions/setup-python@v5
95+ with :
96+ python-version : 3.12
97+
98+ - uses : psf/black@stable
99+ env :
100+ # Black will fail if no arguments are provided.
101+ # In that case check a directory without any python files.
102+ FILES : ${{ steps.changed-files.outputs.all_changed_files || '.github' }}
103+ with :
104+ options : " --check --diff"
105+ src : ${{ env.FILES }}
Original file line number Diff line number Diff line change @@ -40,8 +40,8 @@ clean: stop_bash
4040cleanall : clean
4141 -docker inspect --type=image $(IMAGE_NAME ) > /dev/null 2>&1 && docker image rm $(IMAGE_NAME )
4242
43- .PHONY : lint markdownlint cpplint
44- lint : markdownlint cpplint
43+ .PHONY : lint markdownlint cpplint black
44+ lint : markdownlint cpplint black
4545
4646CHANGED_MD_FILES = $(call get_changed_files,\.md$$)
4747markdownlint :
@@ -60,6 +60,14 @@ cpplint: # Runs locally, requires cpplint installed
6060 cpplint --recursive --quiet $(CHANGED_CPP_FILES ) ; \
6161 fi
6262
63+ CHANGED_PY_FILES = $(call get_changed_files,\.py$$)
64+ black :
65+ @echo " Checking Python files ..."
66+ @if [ " $( CHANGED_PY_FILES) " ]; then \
67+ docker run --rm -v $(PWD ) :/data --workdir=/data pyfound/black:latest \
68+ black --check --diff $(CHANGED_PY_FILES ) ; \
69+ fi
70+
6371# Get a list of files that changed in the current branch and match the given pattern
6472define get_changed_files # $(1 ) : pattern
6573$(shell git diff --name-only HEAD $(shell git merge-base HEAD main) | grep "$(1)" | tr '\n' ' ')
You can’t perform that action at this time.
0 commit comments