From 36ab71301c5cd4390881ea901bbce7d4da6e5f9f Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Tue, 9 Feb 2021 21:03:54 +0100 Subject: [PATCH] Add CI check for mixed line endings Trigger workflow on all file changes. Closes https://github.com/wxWidgets/wxWidgets/pull/2224 --- .github/workflows/code_checks.yml | 33 +++++++++++++++-------------- misc/scripts/check_mixed_eol.sh | 35 +++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 16 deletions(-) create mode 100755 misc/scripts/check_mixed_eol.sh diff --git a/.github/workflows/code_checks.yml b/.github/workflows/code_checks.yml index fc46f8354c..a81b054153 100644 --- a/.github/workflows/code_checks.yml +++ b/.github/workflows/code_checks.yml @@ -5,25 +5,9 @@ on: push: branches: - master - paths: - - '.github/workflows/code_checks.yml' - - 'docs/**' - - 'include/**' - - 'interface/**' - - 'misc/suppressions/**' - - '**/*.md' - - '!docs/changes*txt' pull_request: branches: - master - paths: - - '.github/workflows/code_checks.yml' - - 'docs/**' - - 'include/**' - - 'interface/**' - - 'misc/suppressions/**' - - '**/*.md' - - '!docs/changes*txt' jobs: check-unix: @@ -66,3 +50,20 @@ jobs: ':!**/*.sln' \ ':!**/*.vcproj' \ ':!**/*.xpm' + + + check-mixed-eol: + runs-on: ubuntu-20.04 + name: Check Mixed EOL + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Install dos2unix + run: | + sudo apt-get install -y dos2unix + + - name: Check for mixed EOL + run: | + ./misc/scripts/check_mixed_eol.sh diff --git a/misc/scripts/check_mixed_eol.sh b/misc/scripts/check_mixed_eol.sh new file mode 100755 index 0000000000..862637a7e5 --- /dev/null +++ b/misc/scripts/check_mixed_eol.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +cd `dirname "$0"`/../.. + +find . \( \ + -path './.git' -prune -o \ + -path './3rdparty' -prune -o \ + -path './src/expat' -prune -o \ + -path './src/jpeg' -prune -o \ + -path './src/png' -prune -o \ + -path './src/tiff' -prune -o \ + -path './src/zlib' -prune \) \ + -o -type f -print0 | +( +while IFS= read -r -d '' file; do + case "$file" in + *.ani | *.bmp | *.chm | *.dia | *.gif | *.gz | *.hlp | *.icns | *.ico | *.jpg | *.mo | *.mpg | *.pcx | *.pdf | *.png | *.pnm | *.tga | *.tif | *.ttf | *.wav | *.zip ) + continue + ;; + esac + + read dos unix mac <<< $(dos2unix --info=dum "$file" | awk '{print $1, $2, $3}') + if [[ "$dos" -eq "0" ]] && [[ "$unix" -eq "0" ]]; then + : + elif [[ "$dos" -eq "0" ]] && [[ "$mac" -eq "0" ]]; then + : + elif [[ "$unix" -eq "0" ]] && [[ "$mac" -eq "0" ]]; then + : + else + echo "$file has mixed EOL" + rc=$((rc+1)) + fi +done +exit $rc +)