Skip to content

Commit 9f0a389

Browse files
authored
Add tab detection to CI tests. (#6099)
* Add tab detection to CI tests. * Improve diffing.
1 parent fa0ec67 commit 9f0a389

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

.github/workflows/tab-finder.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Find tabs in modified text files
2+
name: Tab finder
3+
on: [push, pull_request]
4+
env:
5+
MAIN_BRANCH: dev
6+
jobs:
7+
build:
8+
name: Tab finder
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout Code
12+
uses: actions/checkout@v2
13+
with:
14+
fetch-depth: 0 # needed to get the full history
15+
- name: Fetch upstream
16+
run: |
17+
# Fetch the main upstream branch to find the common ancestor
18+
git config --global user.name "Nemo" # required on some servers
19+
git remote add upstream https://github.com/AliceO2Group/AliceO2.git || exit 1
20+
git fetch upstream ${{ env.MAIN_BRANCH }} || exit 1
21+
- name: Find tabs
22+
run: |
23+
# Find tabs in modified text files and show where they are
24+
status=0
25+
# Get the common ancestor of the current branch and the main upstream branch
26+
BASE_COMMIT=$(git merge-base HEAD upstream/${{ env.MAIN_BRANCH }})
27+
# loop over changed files
28+
echo "Diffing against: $BASE_COMMIT"
29+
for f in $(git diff --diff-filter d --name-only $BASE_COMMIT); do
30+
# ignore binary files
31+
file -bi "$f" | grep -q "charset=binary" && continue
32+
# find tabs in file
33+
echo "Scanning file: $f"
34+
if grep -q -P "\t" "$f"; then
35+
status=1
36+
echo "Found some tabs:"
37+
# print out where the tabs are
38+
grep -P -n -C 1 "\t" "$f"
39+
fi
40+
done
41+
exit $status

0 commit comments

Comments
 (0)