forked from AliceO2Group/Run3AnalysisValidation
-
Notifications
You must be signed in to change notification settings - Fork 0
65 lines (65 loc) · 2.7 KB
/
space-checker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
---
# Find bad spacing in modified text files
name: Space checker
on: [push, pull_request]
permissions: {}
env:
MAIN_BRANCH: master
jobs:
build:
name: Space checker
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
fetch-depth: 0 # needed to get the full history
- name: Fetch upstream
run: |
# Fetch the main upstream branch to find the common ancestor
git config --global user.name "Nemo" # required on some servers
git remote add upstream https://github.com/AliceO2Group/Run3Analysisvalidation.git || exit 1
git fetch upstream ${{ env.MAIN_BRANCH }} || exit 1
- name: Find bad spacing
run: |
# Find tabs and trailing whitespaces in modified text files and show where they are
status_tab=0
status_trail=0
# Get the common ancestor of the current branch and the main upstream branch
BASE_COMMIT=$(git merge-base HEAD upstream/${{ env.MAIN_BRANCH }})
echo "Diffing against: $BASE_COMMIT"
# loop over changed files
for f in $(git diff --diff-filter d --name-only "$BASE_COMMIT"); do
# ignore binary files
file -bi "$f" | grep -q "charset=binary" && continue
echo "Scanning file: $f"
# find tabs
if grep -q -P "\t" "$f"; then
status_tab=1
echo "::error::Found some tabs:"
# print out where they are
#grep -P -n "\t" "$f"
awk 'i=index($0, "\t") {printf "%i (col. %i): %s\n", NR, i, $0}' "$f"
fi
# find trailing whitespaces
if grep -q " $" "$f"; then
status_trail=2
echo "::error::Found some trailing whitespaces:"
# print out where they are
grep -n " $" "$f"
fi
done
status=$((status_tab + status_trail))
if [ "$status" -ne 0 ]; then
# shellcheck disable=2028
echo "::warning::Fix the errors in your editor (or with a command)
Command tips:
- Get list of files you changed: git diff --diff-filter d --name-only \$(git merge-base HEAD upstream/${{ env.MAIN_BRANCH }})
- Replace each tab with two spaces: sed -i 's/\\t/ /g' <files>
- Remove trailing whitespaces: sed -i 's/[[:space:]]*$//' <files>"
echo "::warning::To avoid these errors, configure your editor to:
- Emit spaces when the Tab key is pressed.
- Display whitespace characters.
- Replace tabs with spaces and remove trailing whitespaces when a file is saved."
fi
exit $status