Skip to content

Commit 26831b3

Browse files
author
Stefan Knorr
committed
GHA: Introduce new workflow to nitpick on trailing spaces and long lines
* This is the hackiest possible implementation, if we agree to do this, it would probably be best to use an own GitHub Action action for it. * I wanted to use "continue-on-error: true" in my steps but while that correctly recognizes all issues, people would not see the evil red X marking the check failed. * Output is not particularly pretty currently. * On longer PRs, the current output may be a bit confusing, because we don't try to give file names/lines that failed. * This only runs on PRs. Running on push would mean running after the damage is already dones. * This will only compare main..my-branch, rather than each commit added to my-branch individually * Checking out the 1.3 GB doc-sle repo for 10 seconds worth of scripts is a bit wasteful. Unfortunately, it would not work easily with any kind of --depth setting. :/ * This workflow fails the line length criteria too.
1 parent afa9813 commit 26831b3

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

.github/workflows/nitpicks.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
name: Nitpicks
3+
4+
on:
5+
pull_request:
6+
paths:
7+
- 'DC-*'
8+
- 'xml/*'
9+
- 'adoc/*'
10+
11+
jobs:
12+
nitpicks:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
fail-fast: false
16+
steps:
17+
- uses: actions/checkout@v2
18+
with:
19+
fetch-depth: 0
20+
- name: Checking out relevant branches
21+
run: |
22+
git checkout $GITHUB_BASE_REF || { echo "There's a Git issue"; exit 1; }
23+
git checkout $GITHUB_HEAD_REF || { echo "There's a Git issue"; exit 1; }
24+
25+
- name: Checking for tabs
26+
run: |
27+
tab=$(git diff -U0 $GITHUB_BASE_REF..$GITHUB_HEAD_REF | sed -n '/^+/ p' | sed -n '/\t/ p' | sed -r -e 's/\t/→/g')
28+
if [[ -n "$tab" ]]; then
29+
echo -e "\nThis pull request introduces tabs (→) on the following lines:"
30+
echo -e "\n$tab\n"
31+
exit 1
32+
else
33+
echo "This looks aight."
34+
exit 0
35+
fi
36+
37+
- name: Checking for Windows/Mac line ends
38+
run: |
39+
lineends=$(git diff -U0 $GITHUB_BASE_REF..$GITHUB_HEAD_REF | sed -n '/^+/ p' | sed -n '/\r/ p' | sed -r -e 's/\r/↲/g')
40+
if [[ -n "$lineends" ]]; then
41+
echo -e "\nThis pull request introduces Windows/Mac line ends (↲) on the following lines:"
42+
echo -e "\n$lineends\n"
43+
exit 1
44+
else
45+
echo "This looks aight."
46+
exit 0
47+
fi
48+
49+
- name: Checking for trailing characters
50+
run: |
51+
trail=$(git diff -U0 $GITHUB_BASE_REF..$GITHUB_HEAD_REF | sed -n '/^+/ p' | sed -n '/[  \t]$/ p' | sed -r -e 's/ *$/•/g' -e 's/\t*$/→/g' -e 's/ *$/⋄/g')
52+
if [[ -n "$trail" ]]; then
53+
echo -e "\nThis pull request introduces trailing spaces (•)/tabs (→)/protected spaces (⋄) on the following lines:"
54+
echo -e "\n$trail\n"
55+
exit 1
56+
else
57+
echo "This looks aight."
58+
exit 0
59+
fi
60+
61+
- name: Checking for long lines
62+
# We exclude screens, there are legitimate reasons for them to be long.
63+
run: |
64+
potential=$(git diff -U1000 $GITHUB_BASE_REF..$GITHUB_HEAD_REF | tr '\n' '\r' | sed -r -e 's,<screen[^>]*/>,,g' -e 's,</screen[^>]*>,⋘,g' -e 's,<screen[^/>]*>[^⋘]*⋘,,g' | tr '\r' '\n' | sed -n '/^+/ p')
65+
len=$(echo -e "$potential" | wc -l)
66+
long=''
67+
for n in $(seq 1 "$len"); do
68+
line=$(echo -e "$potential" | sed -n "$n p")
69+
if [[ $(echo "$line" | wc -c) -gt 91 ]]; then
70+
long+="\n$line"
71+
fi
72+
done
73+
if [[ -n "$long" ]]; then
74+
echo -e "\nThis pull request introduces long lines (80+ characters) in at least the following spots:"
75+
echo -e "$long\n"
76+
exit 1
77+
else
78+
echo "This looks aight."
79+
exit 0
80+
fi

0 commit comments

Comments
 (0)