lint-doc.sh 2.2 KB
Newer Older
1 2 3 4 5
#!/usr/bin/env bash

cd "$(dirname "$0")/.."

# Use long options (e.g. --header instead of -H) for curl examples in documentation.
6
echo '=> Checking for cURL short options...'
7
grep --extended-regexp --recursive --color=auto 'curl (.+ )?-[^- ].*' doc/ >/dev/null 2>&1
8
if [ $? -eq 0 ]
9
then
10 11 12
  echo '✖ ERROR: Short options for curl should not be used in documentation!
         Use long options (e.g., --header instead of -H):' >&2
  grep --extended-regexp --recursive --color=auto 'curl (.+ )?-[^- ].*' doc/
13 14 15
  exit 1
fi

16 17
# Ensure that the CHANGELOG.md does not contain duplicate versions
DUPLICATE_CHANGELOG_VERSIONS=$(grep --extended-regexp '^## .+' CHANGELOG.md | sed -E 's| \(.+\)||' | sort -r | uniq -d)
18
echo '=> Checking for CHANGELOG.md duplicate entries...'
19 20
if [ "${DUPLICATE_CHANGELOG_VERSIONS}" != "" ]
then
21
  echo '✖ ERROR: Duplicate versions in CHANGELOG.md:' >&2
22 23 24 25
  echo "${DUPLICATE_CHANGELOG_VERSIONS}" >&2
  exit 1
fi

26
# Make sure no files in doc/ are executable
27
EXEC_PERM_COUNT=$(find doc/ app/ -type f -perm 755 | wc -l)
28
echo '=> Checking for executable permissions...'
29 30 31
if [ "${EXEC_PERM_COUNT}" -ne 0 ]
then
  echo '✖ ERROR: Executable permissions should not be used in documentation! Use `chmod 644` to the files in question:' >&2
32
  find doc/ app/ -type f -perm 755
33 34 35
  exit 1
fi

36 37
# Do not use 'README.md', instead use 'index.md'
# Number of 'README.md's as of 2018-03-26
38
NUMBER_READMES_CE=43
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
NUMBER_READMES_EE=46
FIND_READMES=$(find doc/ -name "README.md" | wc -l)
echo '=> Checking for new README.md files...'
if [ "${CI_PROJECT_NAME}" == 'gitlab-ce' ]
then
  if [ ${FIND_READMES} -ne ${NUMBER_READMES_CE} ]
  then
    echo
    echo '  ✖ ERROR: New README.md file(s) detected, prefer index.md over README.md.' >&2
    echo '  https://docs.gitlab.com/ee/development/writing_documentation.html#location-and-naming-documents'
    echo
    exit 1
  fi
elif [ "${CI_PROJECT_NAME}" == 'gitlab-ee' ]
then
  if [ ${FIND_READMES} -ne $NUMBER_READMES_EE ]
  then
    echo
    echo '  ✖ ERROR: New README.md file(s) detected, prefer index.md over README.md.' >&2
    echo '  https://docs.gitlab.com/ee/development/writing_documentation.html#location-and-naming-documents'
    echo
    exit 1
  fi
fi

64 65
echo "✔ Linting passed"
exit 0