Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add whitespace check #1881

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
68 changes: 68 additions & 0 deletions .github/workflows/whitespace.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
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}"
if [[ $line =~ ^-[^-] ]]; then
file_line=$(echo "$line" | cut -c 2-)
echo "Whitespace issue: ${file_line}"
fi
done <<< "$(git diff --check $base_commit ${{ github.sha }} | grep '^-[^-]')"

if [ -n "${log}" ]; then
delimiter=$(openssl rand -hex 8)
echo "text<<${delimiter}" >> $GITHUB_OUTPUT
echo -e "${log}" >> $GITHUB_OUTPUT
echo "${delimiter}" >> $GITHUB_OUTPUT
exit 2
fi
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@ More information can be found in the [Wiki][22].
[20]: https://code.visualstudio.com/
[21]: https://github.com/coq-community/vscoq

[22]: https://github.com/HoTT/HoTT/wiki
[22]: https://github.com/HoTT/HoTT/wiki
14 changes: 14 additions & 0 deletions etc/fix_end_newlines.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# This command fixes the end-of-file newlines for all files in the repository.

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 "Adding newline to file: $file"
echo >> "$file"
git add "$file"
fi
fi
done < <(git ls-files)
5 changes: 5 additions & 0 deletions etc/fix_trailing_whitespace.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

# This command removes trailing whitespace from all files in the repository.

git grep -l -z -E '\s+$' | xargs -0 sed -i 's/\s\+$//'
1 change: 1 addition & 0 deletions theories/Basics.v
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ Require Export Basics.Tactics.

Require Export Basics.Nat.
Require Export Basics.Numeral.

2 changes: 1 addition & 1 deletion theories/Cubical.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Require Export Cubical.DPath.
Require Export Cubical.PathSquare.
Require Export Cubical.DPathSquare.
Require Export Cubical.PathCube.
Require Export Cubical.DPathCube.
Require Export Cubical.DPathCube.
2 changes: 1 addition & 1 deletion theories/Diagrams/ParallelPair.v
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ Proof.
srapply Build_Cocone.
1: intros []; [exact (q o f) | exact q].
intros [] [] []; [reflexivity | exact Hq].
Defined.
Defined.
2 changes: 1 addition & 1 deletion theories/Diagrams/Span.v
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ Section Span.
+ exact g.
Defined.

End Span.
End Span.
2 changes: 1 addition & 1 deletion theories/Spaces/Int.v
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Require Export HoTT.Spaces.Int.Core.
Require Export HoTT.Spaces.Int.Spec.
Require Export HoTT.Spaces.Int.Equiv.
Require Export HoTT.Spaces.Int.LoopExp.
Require Export HoTT.Spaces.Int.LoopExp.
2 changes: 1 addition & 1 deletion theories/Spaces/Pos.v
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Require Export HoTT.Spaces.Pos.Core.
Require Export HoTT.Spaces.Pos.Spec.
Require Export HoTT.Spaces.Pos.Spec.
Loading