Skip to content

Commit a93eaee

Browse files
committed
Add CI to check trailing whitespace
1 parent 21ea60d commit a93eaee

3 files changed

Lines changed: 74 additions & 1 deletion

File tree

.github/workflows/build_and_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and Test Pluto
1+
name: Build and test Pluto
22

33
on:
44
push:
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Check trailing whitespaces
2+
3+
on:
4+
push:
5+
branches: [master]
6+
paths-ignore:
7+
- '**.png'
8+
pull_request:
9+
branches: [master]
10+
paths-ignore:
11+
- '**.png'
12+
13+
14+
jobs:
15+
check-trailing-whitespace:
16+
name: Check trailing whitespaces
17+
runs-on: [self-hosted]
18+
steps:
19+
- uses: actions/checkout@v2
20+
21+
# Choose the git commit to diff against for the purposes of diff-check.
22+
# Since this workflow is triggered on both pushes and pull requests, we
23+
# have to determine if the pull request target branch is set (which it
24+
# will only be on the PR triggered flow). If it's not, then compare
25+
# against the last commit.
26+
- name: choose-commit
27+
if: ${{ always() }}
28+
env:
29+
# Base ref is the target branch, in text form (not hash)
30+
PR_BASE: ${{ github.base_ref }}
31+
run: |
32+
# Determine diff commit name.
33+
if [[ -z "$PR_BASE" ]]; then
34+
DIFF_COMMIT_NAME="HEAD^"
35+
else
36+
DIFF_COMMIT_NAME="$PR_BASE"
37+
fi
38+
echo "DIFF_COMMIT_NAME=$DIFF_COMMIT_NAME" >> $GITHUB_ENV
39+
40+
# Since we did a shallow fetch for this repo, we must fetch the commit
41+
# upon which we be diff'ing. The last step set the ref name in the
42+
# $DIFF_COMMIT_NAME environment variable. When running the fetch, resolve
43+
# it to the commit hash and pass that hash along to subsequent steps.
44+
- name: git fetch base commit
45+
continue-on-error: true
46+
run: |
47+
if [[ ! "$DIFF_COMMIT_NAME" == *"HEAD"* ]]; then
48+
git fetch --recurse-submodules=no origin $DIFF_COMMIT_NAME
49+
DIFF_COMMIT_SHA=$( git rev-parse origin/$DIFF_COMMIT_NAME )
50+
else
51+
DIFF_COMMIT_SHA=$( git rev-parse $DIFF_COMMIT_NAME )
52+
fi
53+
echo "DIFF_COMMIT=$DIFF_COMMIT_SHA" >> $GITHUB_ENV
54+
55+
# Run 'git diff --check', comparing against the target commit hash. If
56+
# diff check fixed anything, fail and output a patch.
57+
- name: diff-check
58+
shell: bash
59+
working-directory: ${{github.workspace}}
60+
run: |
61+
git diff --ignore-submodules --check $DIFF_COMMIT
62+
echo "git diff --check found no whitespace problems"
63+
exit 0
64+
65+
# Cancel workflows when new commit is pushed to a branch other than master.
66+
concurrency:
67+
# Use github.run_id on master branch.
68+
# Use github.event.pull_request.number on pull requests, so it's unique per pull request.
69+
# Use github.ref on other branches, so it's unique per branch.
70+
group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/master' && github.run_id || github.event.pull_request.number || github.ref }}
71+
cancel-in-progress: true

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ test](https://github.com/bondhugula/pluto/actions/workflows/build_and_test.yml/b
5454

5555
[![Check format with clang-format](https://github.com/bondhugula/pluto/actions/workflows/clang_format.yml/badge.svg)](https://github.com/bondhugula/pluto/actions/workflows/clang_format.yml)
5656

57+
[![Find trailing whitespace](https://github.com/bondhugula/pluto/actions/workflows/find_trailing_whitespace.yml/badge.svg)](https://github.com/bondhugula/pluto/actions/workflows/find_trailing_whitespace.yml)
58+
5759
## License
5860

5961
Pluto and libpluto are available under the MIT LICENSE. Please see the file

0 commit comments

Comments
 (0)