From 8628efa0a1437534292ea796dc6d6806395e520a Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 3 Dec 2022 12:40:33 +0000 Subject: [PATCH] github/pr-/push-checks: Attempt non-diff flake8 checks * flake8 6.0.0 dropped support for, the broken, --diff. * We want to only run against python files. We will have 'git diff's for other types of files. * Uses 'git diff -z', 'grep -z -Z' and 'xargs -0' so as to pass NUL-terminated strings around to avoid "special characters in path/filenames" issues. --- .github/workflows/pr-checks.yml | 8 ++++++-- .github/workflows/push-checks.yml | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index e90929bb..70c8dad1 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -85,11 +85,15 @@ jobs: # F63 - 'tests' checking # F7 - syntax errors # F82 - undefined checking - git diff "refs/remotes/${BASE_REPO_OWNER}/${BASE_REF}" -- | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --diff + echo git diff --name-only --diff-filter=d -z "refs/remotes/${BASE_REPO_OWNER}/${BASE_REF}" -- | \ + grep -E -z -Z '\.py$' | \ + xargs -0 flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # Can optionally add `--exit-zero` to the flake8 arguments so that # this doesn't fail the build. # explicitly ignore docstring errors (start with D) - git diff "refs/remotes/${BASE_REPO_OWNER}/${BASE_REF}" -- | flake8 . --count --statistics --diff --extend-ignore D + git diff --name-only --diff-filter=d -z "refs/remotes/${BASE_REPO_OWNER}/${BASE_REF}" -- | \ + grep -E -z -Z '\.py$' | \ + xargs -0 flake8 . --count --statistics --extend-ignore D #################################################################### #################################################################### diff --git a/.github/workflows/push-checks.yml b/.github/workflows/push-checks.yml index b6994b02..a11234ed 100644 --- a/.github/workflows/push-checks.yml +++ b/.github/workflows/push-checks.yml @@ -40,7 +40,20 @@ jobs: DATA=$(jq --raw-output .before $GITHUB_EVENT_PATH) echo "DATA: ${DATA}" + ####################################################################### # stop the build if there are Python syntax errors or undefined names, ignore existing - git diff "$DATA" | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --diff + ####################################################################### + # We need to get just the *filenames* of only *python* files changed. + # Using various -z/-Z/-0 to utilise NUL-terminated strings. + git diff --name-only --diff-filter=d -z "$DATA" | \ + grep -E -z -Z '\.py$' | \ + xargs -0 flake8 --count --select=E9,F63,F7,F82 --show-source --statistics + ####################################################################### + + ####################################################################### # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - git diff "$DATA" | flake8 . --count --statistics --diff + ####################################################################### + git diff --name-only --diff-filter=d -z "$DATA" | \ + grep -E -z -Z '\.py$' | \ + xargs -0 flake8 . --count --statistics + #######################################################################