Skip to content

Commit cff32e7

Browse files
datapythonistaproost
authored andcommitted
CI: Highlighting flake8 and grep errors in GitHub Actions (pandas-dev#29915)
1 parent c7f397f commit cff32e7

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

ci/code_checks.sh

+8-16
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,13 @@ function invgrep {
3434
#
3535
# This is useful for the CI, as we want to fail if one of the patterns
3636
# that we want to avoid is found by grep.
37-
if [[ "$AZURE" == "true" ]]; then
38-
set -o pipefail
39-
grep -n "$@" | awk -F ":" '{print "##vso[task.logissue type=error;sourcepath=" $1 ";linenumber=" $2 ";] Found unwanted pattern: " $3}'
40-
else
41-
grep "$@"
42-
fi
43-
return $((! $?))
37+
grep -n "$@" | sed "s/^/$INVGREP_PREPEND/" | sed "s/$/$INVGREP_APPEND/" ; EXIT_STATUS=${PIPESTATUS[0]}
38+
return $((! $EXIT_STATUS))
4439
}
4540

46-
if [[ "$AZURE" == "true" ]]; then
47-
FLAKE8_FORMAT="##vso[task.logissue type=error;sourcepath=%(path)s;linenumber=%(row)s;columnnumber=%(col)s;code=%(code)s;]%(text)s"
41+
if [[ "$GITHUB_ACTIONS" == "true" ]]; then
42+
FLAKE8_FORMAT="##[error]%(path)s:%(row)s:%(col)s:%(code):%(text)s"
43+
INVGREP_PREPEND="##[error]"
4844
else
4945
FLAKE8_FORMAT="default"
5046
fi
@@ -199,14 +195,10 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
199195
RET=$(($RET + $?)) ; echo $MSG "DONE"
200196

201197
MSG='Check that no file in the repo contains trailing whitespaces' ; echo $MSG
202-
set -o pipefail
203-
if [[ "$AZURE" == "true" ]]; then
204-
# we exclude all c/cpp files as the c/cpp files of pandas code base are tested when Linting .c and .h files
205-
! grep -n '--exclude=*.'{svg,c,cpp,html,js} --exclude-dir=env -RI "\s$" * | awk -F ":" '{print "##vso[task.logissue type=error;sourcepath=" $1 ";linenumber=" $2 ";] Tailing whitespaces found: " $3}'
206-
else
207-
! grep -n '--exclude=*.'{svg,c,cpp,html,js} --exclude-dir=env -RI "\s$" * | awk -F ":" '{print $1 ":" $2 ":Tailing whitespaces found: " $3}'
208-
fi
198+
INVGREP_APPEND=" <- trailing whitespaces found"
199+
invgrep -RI --exclude=\*.{svg,c,cpp,html,js} --exclude-dir=env "\s$" *
209200
RET=$(($RET + $?)) ; echo $MSG "DONE"
201+
unset INVGREP_APPEND
210202
fi
211203

212204
### CODE ###

0 commit comments

Comments
 (0)