detect trailing whitespace in a CI job (#1268)

This commit is contained in:
Paul Dreik 2020-11-03 20:41:19 +01:00 committed by GitHub
parent 23b4bc93aa
commit 9f78559cc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,33 @@
name: Detect trailing whitespace
on: [pull_request]
jobs:
whitespace:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Remove whitespace and check the diff
run: |
set -eu
scripts/remove_trailing_whitespace.sh
git diff >whitespace.patch
if [ $(wc -c <whitespace.patch) -ne 0 ] ; then
echo " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! "
echo "You have trailing whitespace, please download the artifact"
echo "and apply with git apply <whitespace.patch or"
echo "run scripts/remove_trailing_whitespace.sh locally."
echo " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! "
exit 1
else
echo "no trailing whitespace found, good!"
fi
- name: Archive whitespace patch
uses: actions/upload-artifact@v2
if: always()
with:
name: whitespace-patch
path: |
whitespace.patch
if-no-files-found: ignore

View File

@ -0,0 +1,19 @@
#!/bin/sh
#
# removes trailing whitespace from source files and other
set -eu
# go to the git root dir
cd "$(git rev-parse --show-toplevel)"
#make a list of all files (null separated, to handle whitespace)
git ls-tree -r HEAD --name-only -z >all_files.null.txt
for suffix in cpp cmake h hpp js md py rb sh ; do
echo "removing trailing whitespace from files with suffix $suffix"
cat all_files.null.txt | grep -z '\.'$suffix'$' |xargs -n1 --null sed -i 's/[ \t]*$//'
done
rm all_files.null.txt
echo "done!"