|
| 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