From 50e7a5dc8355c7a0874cb0bf1138785330b526d2 Mon Sep 17 00:00:00 2001 From: Stefan Knorr Date: Tue, 15 Jun 2021 15:45:16 +0200 Subject: [PATCH] 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. :/ --- .github/workflows/nitpicks.yml | 80 ++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 .github/workflows/nitpicks.yml diff --git a/.github/workflows/nitpicks.yml b/.github/workflows/nitpicks.yml new file mode 100644 index 0000000000..33b87c3faf --- /dev/null +++ b/.github/workflows/nitpicks.yml @@ -0,0 +1,80 @@ +--- +name: Nitpicks + +on: + pull_request: + paths: + - 'DC-*' + - 'xml/*' + - 'adoc/*' + +jobs: + trailing-space: + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Checking out relevant branches + run: | + git checkout $GITHUB_BASE_REF || { echo "There's a Git issue"; exit 1; } + git checkout $GITHUB_HEAD_REF || { echo "There's a Git issue"; exit 1; } + + - name: Picking on nits + run: | + tab=$(git diff -U0 $GITHUB_BASE_REF..$GITHUB_HEAD_REF | sed -n '/^+/ p' | sed -n '/\t/ p' | sed -r -e 's/\t/→/g') + if [[ -n "$tab" ]]; then + echo -e "\nThis pull request introduces tabs (→) on the following lines:" + echo -e "\n$tab\n" + exit 1 + else + echo "This looks aight." + exit 0 + fi + + - name: Checking for Windows/Mac line ends + run: | + lineends=$(git diff -U0 $GITHUB_BASE_REF..$GITHUB_HEAD_REF | sed -n '/^+/ p' | sed -n '/\r/ p' | sed -r -e 's/\r/↲/g') + if [[ -n "$lineends" ]]; then + echo -e "\nThis pull request introduces Windows/Mac line ends (↲) on the following lines:" + echo -e "\n$lineends\n" + exit 1 + else + echo "This looks aight." + exit 0 + fi + + - name: Checking for trailing characters + run: | + 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') + if [[ -n "$trail" ]]; then + echo -e "\nThis pull request introduces trailing spaces (•)/tabs (→)/protected spaces (⋄) on the following lines:" + echo -e "\n$trail\n" + exit 1 + else + echo "This looks aight." + exit 0 + fi + + - name: Checking for long lines + # We exclude screens, there are legitimate reasons for them to be long. + run: | + potential=$(git diff -U1000 $GITHUB_BASE_REF..$GITHUB_HEAD_REF | tr '\n' '\r' | sed -r -e 's,]*/>,,g' -e 's,]*>,⋘,g' -e 's,]*>[^⋘]*⋘,,g' | tr '\r' '\n' | sed -n '/^+/ p') + len=$(echo -e "$potential" | wc -l) + long='' + for n in $(seq 1 "$len"); do + line=$(echo -e "$potential" | sed -n "$n p") + if [[ $(echo "$line" | wc -c) -gt 91 ]]; then + long+="\n$line" + fi + done + if [[ -n "$long" ]]; then + echo -e "\nThis pull request introduces long lines (80+ characters) in at least the following spots:" + echo -e "$long\n" + exit 1 + else + echo "This looks aight." + exit 0 + fi