Skip to content

ci: add whitespace check #40

ci: add whitespace check

ci: add whitespace check #40

Workflow file for this run

name: Whitespace Check
on:
pull_request:
push:
branches:
- master
jobs:
whitespace-check:
runs-on: ubuntu-latest
steps:
- name: Set commit count
shell: bash
run: echo "COMMIT_DEPTH=$((1 + ${{ github.event.pull_request.commits }}))" >> $GITHUB_ENV
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: ${{ env.COMMIT_DEPTH }}
# TODO: reintroduce this check when the library is cleaned up
# - name: Check for trailing whitespace
# run: |
# TRAILING_WHITESPACE=$(git grep -l -z -E '\s+$' | xargs -0 sed -n '/\s$/p')
# if [ -n "$TRAILING_WHITESPACE" ]; then
# echo "Trailing whitespace found. Please fix with:\
# bash ./etc/fix_trailing_whitespace.sh"
# exit 1
# fi
- name: Check that every file ends correctly
run: |
while IFS= read -r file; do
# Check if the file is a regular file
if [ -f "$file" ]; then
if [ -n "$(tail -c 1 "$file")" ]; then
echo "File $file does not end with a newline. Please fix with:\
bash ./etc/fix_end_newlines.sh"
exit 1
fi
fi
done < <(git ls-files)
# Get the repo with the commits(+1) in the series.
# Process `git log --check` output to extract just the check errors.
- name: git log --check
id: check_out
run: |
log=
base_commit=$(git rev-parse FETCH_HEAD)
while IFS= read -r line; do
log="${log}\n${line}"
echo "::error file=${line%%:*},line=${line#*:}::Whitespace issue: ${line}"
done <<< "$(git diff --check $base_commit ${{ github.sha }} | grep '^-[^-]')"
if [ -n "${log}" ]; then
echo -e "Whitespace issues found in the following file(s) and line number(s):\n${log}" >> $GITHUB_OUTPUT
exit 2
fi