diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b9552f9bdbcd7c1cabb6186a6a261ca6ea3988cc..2a3a81849853b25eb5987d3ebc209e9448725966 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -34,6 +34,13 @@ Lint changed md-files: doc.zih.tu-dresden.de/util/lint-changes.sh only: [ merge_requests ] +Check spelling for changed md-files: + stage: test + script: + - docker run --rm -w /src -e CI_MERGE_REQUEST_TARGET_BRANCH_NAME "${DOCKER_IMAGE}" + doc.zih.tu-dresden.de/util/check-spelling-changes.sh + only: [ merge_requests ] + Check links for changed md-files: stage: test script: diff --git a/doc.zih.tu-dresden.de/util/check-spelling-changes.sh b/doc.zih.tu-dresden.de/util/check-spelling-changes.sh new file mode 100755 index 0000000000000000000000000000000000000000..d0849ac80a97a40ad6ffc99fee6e1cfd68155ae8 --- /dev/null +++ b/doc.zih.tu-dresden.de/util/check-spelling-changes.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +set -euo pipefail + +scriptpath=${BASH_SOURCE[0]} +basedir=`dirname "$scriptpath"` +basedir=`dirname "$basedir"` +wordlistfile=$basedir/wordlist.aspell + +function getNumberOfAspellOutputLines(){ + cat - | aspell -p "$wordlistfile" --ignore 2 -l en_US list | sort -u | wc -l +} + +branch="preview" +if [ -n "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" ]; then + branch="origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" +fi + +any_fails=false + +source_hash=`git merge-base HEAD "$branch"` +files=$(git diff --name-only "$source_hash") +for f in $files; do + if [ "${f: -3}" == ".md" ]; then + previous_count=`git show "$source_hash:$f" | getNumberOfAspellOutputLines` + current_count=`cat "$f" | getNumberOfAspellOutputLines` + if [ $current_count -gt $previous_count ]; then + echo "-- File $f" + echo "Change increases spelling mistake count (from $previous_count to $current_count)" + any_fails=true + fi + fi +done + +if [ "$any_fails" == true ]; then + exit 1 +fi