2016-09-13 17:45:13 +05:30
|
|
|
|
#!/usr/bin/env bash
|
2021-01-29 00:20:46 +05:30
|
|
|
|
set -o pipefail
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
|
cd "$(dirname "$0")/.." || exit 1
|
2019-12-26 22:10:19 +05:30
|
|
|
|
echo "=> Linting documents at path $(pwd) as $(whoami)..."
|
2020-04-08 14:13:33 +05:30
|
|
|
|
echo
|
|
|
|
|
ERRORCODE=0
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
|
|
# Use long options (e.g. --header instead of -H) for curl examples in documentation.
|
2018-05-09 12:01:36 +05:30
|
|
|
|
echo '=> Checking for cURL short options...'
|
2020-04-08 14:13:33 +05:30
|
|
|
|
echo
|
2018-03-17 18:26:18 +05:30
|
|
|
|
grep --extended-regexp --recursive --color=auto 'curl (.+ )?-[^- ].*' doc/ >/dev/null 2>&1
|
2018-11-20 20:47:30 +05:30
|
|
|
|
if [ $? -eq 0 ]
|
2016-09-13 17:45:13 +05:30
|
|
|
|
then
|
2018-03-17 18:26:18 +05:30
|
|
|
|
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-04-08 14:13:33 +05:30
|
|
|
|
((ERRORCODE++))
|
2016-09-13 17:45:13 +05:30
|
|
|
|
fi
|
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
|
# Test for non-standard spaces (NBSP, NNBSP) in documentation.
|
|
|
|
|
echo '=> Checking for non-standard spaces...'
|
|
|
|
|
echo
|
|
|
|
|
grep --extended-regexp --binary-file=without-match --recursive '[ ]' doc/ >/dev/null 2>&1
|
|
|
|
|
if [ $? -eq 0 ]
|
|
|
|
|
then
|
|
|
|
|
echo '✖ ERROR: Non-standard spaces (NBSP, NNBSP) should not be used in documentation.
|
|
|
|
|
https://docs.gitlab.com/ee/development/documentation/styleguide/index.html#spaces-between-words
|
|
|
|
|
Replace with standard spaces:' >&2
|
|
|
|
|
# Find the spaces, then add color codes with sed to highlight each NBSP or NNBSP in the output.
|
|
|
|
|
grep --extended-regexp --binary-file=without-match --recursive --color=auto '[ ]' doc \
|
|
|
|
|
| sed -e ''/ /s//`printf "\033[0;101m \033[0m"`/'' -e ''/ /s//`printf "\033[0;101m \033[0m"`/''
|
|
|
|
|
((ERRORCODE++))
|
|
|
|
|
fi
|
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
|
# 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-05-09 12:01:36 +05:30
|
|
|
|
echo '=> Checking for CHANGELOG.md duplicate entries...'
|
2020-04-08 14:13:33 +05:30
|
|
|
|
echo
|
2016-11-03 12:29:30 +05:30
|
|
|
|
if [ "${DUPLICATE_CHANGELOG_VERSIONS}" != "" ]
|
|
|
|
|
then
|
|
|
|
|
echo '✖ ERROR: Duplicate versions in CHANGELOG.md:' >&2
|
|
|
|
|
echo "${DUPLICATE_CHANGELOG_VERSIONS}" >&2
|
2020-04-08 14:13:33 +05:30
|
|
|
|
((ERRORCODE++))
|
2016-11-03 12:29:30 +05:30
|
|
|
|
fi
|
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
|
# Make sure no files in doc/ are executable
|
2019-12-21 20:55:43 +05:30
|
|
|
|
EXEC_PERM_COUNT=$(find doc/ -type f -perm 755 | wc -l)
|
2019-12-26 22:10:19 +05:30
|
|
|
|
echo "=> Checking $(pwd)/doc for executable permissions..."
|
2020-04-08 14:13:33 +05:30
|
|
|
|
echo
|
2018-03-17 18:26:18 +05:30
|
|
|
|
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-12-21 20:55:43 +05:30
|
|
|
|
find doc/ -type f -perm 755
|
2020-04-08 14:13:33 +05:30
|
|
|
|
((ERRORCODE++))
|
2018-03-17 18:26:18 +05:30
|
|
|
|
fi
|
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
|
# Do not use 'README.md', instead use 'index.md'
|
2021-01-03 14:25:43 +05:30
|
|
|
|
# Number of 'README.md's as of 2020-10-13
|
|
|
|
|
NUMBER_READMES=36
|
2018-05-09 12:01:36 +05:30
|
|
|
|
FIND_READMES=$(find doc/ -name "README.md" | wc -l)
|
|
|
|
|
echo '=> Checking for new README.md files...'
|
2020-04-08 14:13:33 +05:30
|
|
|
|
echo
|
2019-12-04 20:38:33 +05:30
|
|
|
|
if [ ${FIND_READMES} -ne $NUMBER_READMES ]
|
2018-05-09 12:01:36 +05:30
|
|
|
|
then
|
2019-12-04 20:38:33 +05:30
|
|
|
|
echo
|
2020-07-28 23:09:34 +05:30
|
|
|
|
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-03-13 15:44:24 +05:30
|
|
|
|
echo ' https://docs.gitlab.com/ee/development/documentation/styleguide.html#work-with-directories-and-files'
|
2019-12-04 20:38:33 +05:30
|
|
|
|
echo
|
2020-04-08 14:13:33 +05:30
|
|
|
|
((ERRORCODE++))
|
2018-05-09 12:01:36 +05:30
|
|
|
|
fi
|
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
|
# Run Vale and Markdownlint only on changed files. Only works on merged results
|
|
|
|
|
# pipelines, so first checks if a merged results CI variable is present. If not present,
|
|
|
|
|
# runs test on all files.
|
|
|
|
|
if [ -z "${CI_MERGE_REQUEST_TARGET_BRANCH_SHA}" ]
|
|
|
|
|
then
|
|
|
|
|
MD_DOC_PATH=${MD_DOC_PATH:-doc}
|
|
|
|
|
echo "Merge request pipeline (detached) detected. Testing all files."
|
|
|
|
|
else
|
|
|
|
|
MERGE_BASE=$(git merge-base ${CI_MERGE_REQUEST_TARGET_BRANCH_SHA} ${CI_MERGE_REQUEST_SOURCE_BRANCH_SHA})
|
2021-02-22 17:27:13 +05:30
|
|
|
|
if git diff --name-only "${MERGE_BASE}..${CI_MERGE_REQUEST_SOURCE_BRANCH_SHA}" | grep -E "\.vale|\.markdownlint|lint-doc\.sh"
|
2021-01-29 00:20:46 +05:30
|
|
|
|
then
|
2021-02-22 17:27:13 +05:30
|
|
|
|
MD_DOC_PATH=${MD_DOC_PATH:-doc}
|
|
|
|
|
echo "Vale, Markdownlint, or lint-doc.sh configuration changed. Testing all files."
|
|
|
|
|
else
|
|
|
|
|
MD_DOC_PATH=$(git diff --name-only "${MERGE_BASE}..${CI_MERGE_REQUEST_SOURCE_BRANCH_SHA}" 'doc/*.md')
|
|
|
|
|
if [ -n "${MD_DOC_PATH}" ]
|
|
|
|
|
then
|
|
|
|
|
echo -e "Merged results pipeline detected. Testing only the following files:\n${MD_DOC_PATH}"
|
|
|
|
|
fi
|
2021-01-29 00:20:46 +05:30
|
|
|
|
fi
|
|
|
|
|
fi
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
|
|
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
|
2021-01-29 00:20:46 +05:30
|
|
|
|
docker run -t -v ${PWD}:/gitlab -w /gitlab --rm registry.gitlab.com/gitlab-org/gitlab-docs/lint-markdown:alpine-3.12-vale-2.6.1-markdownlint-0.24.0 ${cmd} ${args}
|
2020-04-08 14:13:33 +05:30
|
|
|
|
else
|
|
|
|
|
echo
|
|
|
|
|
echo " ✖ ERROR: '${cmd}' not found. Install '${cmd}' or Docker to proceed." >&2
|
|
|
|
|
echo
|
|
|
|
|
((ERRORCODE++))
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ $? -ne 0 ]
|
|
|
|
|
then
|
|
|
|
|
echo
|
|
|
|
|
echo " ✖ ERROR: '${cmd}' failed with errors." >&2
|
|
|
|
|
echo
|
|
|
|
|
((ERRORCODE++))
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
echo '=> Linting markdown style...'
|
|
|
|
|
echo
|
2021-01-29 00:20:46 +05:30
|
|
|
|
if [ -z "${MD_DOC_PATH}" ]
|
|
|
|
|
then
|
|
|
|
|
echo "Merged results pipeline detected, but no markdown files found. Skipping."
|
|
|
|
|
else
|
|
|
|
|
run_locally_or_in_docker 'markdownlint' "--config .markdownlint.json ${MD_DOC_PATH}"
|
|
|
|
|
fi
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
|
|
echo '=> Linting prose...'
|
2021-01-29 00:20:46 +05:30
|
|
|
|
run_locally_or_in_docker 'vale' "--minAlertLevel error --output=doc/.vale/vale.tmpl ${MD_DOC_PATH}"
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
|
|
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
|