2016-08-08 08:42:20 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
cd "$(dirname "$0")/.."
|
2019-10-22 05:06:14 -04:00
|
|
|
echo "=> Linting documents at path $(pwd) as $(whoami)..."
|
2020-03-12 17:09:45 -04:00
|
|
|
echo
|
|
|
|
ERRORCODE=0
|
2016-08-08 08:42:20 -04:00
|
|
|
|
|
|
|
# Use long options (e.g. --header instead of -H) for curl examples in documentation.
|
2018-03-26 09:05:33 -04:00
|
|
|
echo '=> Checking for cURL short options...'
|
2020-03-12 17:09:45 -04:00
|
|
|
echo
|
2017-09-25 04:50:06 -04:00
|
|
|
grep --extended-regexp --recursive --color=auto 'curl (.+ )?-[^- ].*' doc/ >/dev/null 2>&1
|
2017-10-03 11:15:40 -04:00
|
|
|
if [ $? -eq 0 ]
|
2016-08-08 08:42:20 -04:00
|
|
|
then
|
2017-09-25 04:50:06 -04:00
|
|
|
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/
|
2020-03-12 17:09:45 -04:00
|
|
|
((ERRORCODE++))
|
2016-08-08 08:42:20 -04:00
|
|
|
fi
|
|
|
|
|
2016-10-16 14:29:45 -04:00
|
|
|
# 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)
|
2018-03-26 09:05:33 -04:00
|
|
|
echo '=> Checking for CHANGELOG.md duplicate entries...'
|
2020-03-12 17:09:45 -04:00
|
|
|
echo
|
2016-08-25 16:48:17 -04:00
|
|
|
if [ "${DUPLICATE_CHANGELOG_VERSIONS}" != "" ]
|
|
|
|
then
|
2016-10-16 14:29:45 -04:00
|
|
|
echo '✖ ERROR: Duplicate versions in CHANGELOG.md:' >&2
|
2016-08-25 16:48:17 -04:00
|
|
|
echo "${DUPLICATE_CHANGELOG_VERSIONS}" >&2
|
2020-03-12 17:09:45 -04:00
|
|
|
((ERRORCODE++))
|
2016-08-25 16:48:17 -04:00
|
|
|
fi
|
|
|
|
|
2017-09-25 04:50:06 -04:00
|
|
|
# Make sure no files in doc/ are executable
|
2019-10-11 02:06:27 -04:00
|
|
|
EXEC_PERM_COUNT=$(find doc/ -type f -perm 755 | wc -l)
|
2019-10-22 05:06:14 -04:00
|
|
|
echo "=> Checking $(pwd)/doc for executable permissions..."
|
2020-03-12 17:09:45 -04:00
|
|
|
echo
|
2017-09-25 04:50:06 -04:00
|
|
|
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
|
2019-10-11 02:06:27 -04:00
|
|
|
find doc/ -type f -perm 755
|
2020-03-12 17:09:45 -04:00
|
|
|
((ERRORCODE++))
|
2017-09-25 04:50:06 -04:00
|
|
|
fi
|
|
|
|
|
2018-03-26 09:05:33 -04:00
|
|
|
# Do not use 'README.md', instead use 'index.md'
|
2020-06-08 17:09:17 -04:00
|
|
|
# Number of 'README.md's as of 2020-05-28
|
2020-07-09 17:09:33 -04:00
|
|
|
NUMBER_READMES=44
|
2018-03-26 09:05:33 -04:00
|
|
|
FIND_READMES=$(find doc/ -name "README.md" | wc -l)
|
|
|
|
echo '=> Checking for new README.md files...'
|
2020-03-12 17:09:45 -04:00
|
|
|
echo
|
2019-09-13 14:06:03 -04:00
|
|
|
if [ ${FIND_READMES} -ne $NUMBER_READMES ]
|
2018-03-26 09:05:33 -04:00
|
|
|
then
|
2019-09-13 14:06:03 -04:00
|
|
|
echo
|
2020-07-10 14:09:45 -04:00
|
|
|
echo ' ✖ ERROR: The number of README.md file(s) has changed. Use index.md instead of README.md.' >&2
|
|
|
|
echo ' ✖ If removing a README.md file, update NUMBER_READMES in lint-doc.sh.' >&2
|
2020-02-06 10:09:11 -05:00
|
|
|
echo ' https://docs.gitlab.com/ee/development/documentation/styleguide.html#work-with-directories-and-files'
|
2019-09-13 14:06:03 -04:00
|
|
|
echo
|
2020-03-12 17:09:45 -04:00
|
|
|
((ERRORCODE++))
|
2018-03-26 09:05:33 -04:00
|
|
|
fi
|
|
|
|
|
2020-03-11 02:10:11 -04:00
|
|
|
MD_DOC_PATH=${MD_DOC_PATH:-doc}
|
2020-03-05 07:07:48 -05:00
|
|
|
|
|
|
|
function run_locally_or_in_docker() {
|
|
|
|
local cmd=$1
|
|
|
|
local args=$2
|
|
|
|
|
|
|
|
if hash ${cmd} 2>/dev/null
|
|
|
|
then
|
|
|
|
$cmd $args
|
|
|
|
elif hash docker 2>/dev/null
|
|
|
|
then
|
|
|
|
docker run -t -v ${PWD}:/gitlab -w /gitlab --rm registry.gitlab.com/gitlab-org/gitlab-docs:lint ${cmd} ${args}
|
|
|
|
else
|
|
|
|
echo
|
|
|
|
echo " ✖ ERROR: '${cmd}' not found. Install '${cmd}' or Docker to proceed." >&2
|
|
|
|
echo
|
2020-03-12 17:09:45 -04:00
|
|
|
((ERRORCODE++))
|
2020-03-05 07:07:48 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $? -ne 0 ]
|
|
|
|
then
|
|
|
|
echo
|
|
|
|
echo " ✖ ERROR: '${cmd}' failed with errors." >&2
|
|
|
|
echo
|
2020-03-12 17:09:45 -04:00
|
|
|
((ERRORCODE++))
|
2020-03-05 07:07:48 -05:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '=> Linting markdown style...'
|
2020-03-12 17:09:45 -04:00
|
|
|
echo
|
2020-03-05 07:07:48 -05:00
|
|
|
run_locally_or_in_docker 'markdownlint' "--config .markdownlint.json ${MD_DOC_PATH}"
|
|
|
|
|
|
|
|
echo '=> Linting prose...'
|
2020-03-11 23:10:15 -04:00
|
|
|
run_locally_or_in_docker 'vale' "--minAlertLevel error ${MD_DOC_PATH}"
|
2020-03-05 07:07:48 -05:00
|
|
|
|
2020-03-12 17:09:45 -04:00
|
|
|
if [ $ERRORCODE -ne 0 ]
|
|
|
|
then
|
|
|
|
echo "✖ ${ERRORCODE} lint test(s) failed. Review the log carefully to see full listing."
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "✔ Linting passed"
|
|
|
|
exit 0
|
|
|
|
fi
|