diff --git a/.gitlab/ci/docs.gitlab-ci.yml b/.gitlab/ci/docs.gitlab-ci.yml index 18954e7b8e0a020cac970c1b3d3b070438208b3c..ee0784fe0d9a42d9897e132b4fd47376120fc19e 100644 --- a/.gitlab/ci/docs.gitlab-ci.yml +++ b/.gitlab/ci/docs.gitlab-ci.yml @@ -65,6 +65,7 @@ docs-lint markdown: - .default-retry - .docs:rules:docs-lint - .docs-markdown-lint-image + - .yarn-cache stage: lint needs: [] script: diff --git a/doc/.markdownlint/require_helper.js b/doc/.markdownlint/require_helper.js deleted file mode 100644 index 7d06cf67419fdfaa903a5ebc1c985be4ec64d437..0000000000000000000000000000000000000000 --- a/doc/.markdownlint/require_helper.js +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Look up the global node modules directory. - * - * Because we install markdownlint packages globally - * in the Docker image where this runs, we need to - * provide the path to the global install location - * when referencing global functions from our own node - * modules. - * - * Image: - * https://gitlab.com/gitlab-org/gitlab-docs/-/blob/main/dockerfiles/gitlab-docs-lint-markdown.Dockerfile - */ -const { execSync } = require('child_process'); -module.exports.globalPath = execSync('yarn global dir').toString().trim() + '/node_modules/'; diff --git a/doc/.markdownlint/rules/tabs_blank_lines.js b/doc/.markdownlint/rules/tabs_blank_lines.js index e0e2c1a0a9b910ee85018a941847aaf4594a0f97..8a9e9c2434e1f2a8c4aa69c8712c1e2aca13315a 100644 --- a/doc/.markdownlint/rules/tabs_blank_lines.js +++ b/doc/.markdownlint/rules/tabs_blank_lines.js @@ -1,9 +1,4 @@ -const { globalPath } = require('../require_helper'); -const { - forEachLine, - getLineMetadata, - isBlankLine, -} = require(`${globalPath}/markdownlint-rule-helpers`); +const { forEachLine, getLineMetadata, isBlankLine } = require(`markdownlint-rule-helpers`); module.exports = { names: ['tabs-blank-lines'], diff --git a/doc/.markdownlint/rules/tabs_title_markup.js b/doc/.markdownlint/rules/tabs_title_markup.js index 9c1de1e630d7750a832c5cfb96f17e70dfdec00f..0461ac8385f3a3c0239d9d217ed161d336af8f83 100644 --- a/doc/.markdownlint/rules/tabs_title_markup.js +++ b/doc/.markdownlint/rules/tabs_title_markup.js @@ -1,5 +1,4 @@ -const { globalPath } = require('../require_helper'); -const { forEachLine, getLineMetadata } = require(`${globalPath}/markdownlint-rule-helpers`); +const { forEachLine, getLineMetadata } = require(`markdownlint-rule-helpers`); module.exports = { names: ['tabs-title-markup'], diff --git a/doc/.markdownlint/rules/tabs_title_text.js b/doc/.markdownlint/rules/tabs_title_text.js index 672aa70f5624427a05d90c749ceccf650f990cd5..beb329231b1f5ff481546152cc596c7499971339 100644 --- a/doc/.markdownlint/rules/tabs_title_text.js +++ b/doc/.markdownlint/rules/tabs_title_text.js @@ -1,9 +1,4 @@ -const { globalPath } = require('../require_helper'); -const { - forEachLine, - getLineMetadata, - isBlankLine, -} = require(`${globalPath}/markdownlint-rule-helpers`); +const { forEachLine, getLineMetadata, isBlankLine } = require(`markdownlint-rule-helpers`); module.exports = { names: ['tabs-title-text'], diff --git a/lib/tasks/lint.rake b/lib/tasks/lint.rake index 62d31803f6ee52186c218602901a4e35be666dd1..6e50e417776da3d717b6b09878a051985d6bb030 100644 --- a/lib/tasks/lint.rake +++ b/lib/tasks/lint.rake @@ -34,6 +34,11 @@ unless Rails.env.production? exit(1) end + desc "GitLab | Lint | Lint docs Markdown files" + task :markdown do + sh "./scripts/lint-doc.sh" + end + desc "GitLab | Lint | Run several lint checks" task :all do status = 0 diff --git a/scripts/lint-doc.sh b/scripts/lint-doc.sh index 68dfac95ef6a77781a53f14d54e6d2213404f412..1c934c07608d98393a935363e43f583c8c2681c1 100755 --- a/scripts/lint-doc.sh +++ b/scripts/lint-doc.sh @@ -119,19 +119,24 @@ else fi fi -function run_locally_or_in_docker() { +function run_locally_or_in_container() { local cmd=$1 local args=$2 if hash ${cmd} 2>/dev/null then $cmd $args - elif hash docker 2>/dev/null + # When using software like Rancher Desktop, both nerdctl and docker binaries are available + # but only one is configured. To check which one to use, we need to probe each runtime + elif (hash nerdctl 2>/dev/null) && (nerdctl info 2>&1 1>/dev/null) then - docker run -t -v ${PWD}:/gitlab -w /gitlab --rm registry.gitlab.com/gitlab-org/gitlab-docs/lint-markdown:alpine-3.16-vale-2.20.1-markdownlint-0.32.2 ${cmd} ${args} + nerdctl run -t -v "${PWD}:/gitlab" -w /gitlab --rm registry.gitlab.com/gitlab-org/gitlab-docs/lint-markdown:alpine-3.16-vale-2.20.1-markdownlint-0.32.2 ${cmd} ${args} + elif (hash docker 2>/dev/null) && (docker info 2>&1 1>/dev/null) + then + docker run -t -v "${PWD}:/gitlab" -w /gitlab --rm registry.gitlab.com/gitlab-org/gitlab-docs/lint-markdown:alpine-3.16-vale-2.20.1-markdownlint-0.32.2 ${cmd} ${args} else echo - echo " ✖ ERROR: '${cmd}' not found. Install '${cmd}' or Docker to proceed." >&2 + echo " ✖ ERROR: '${cmd}' not found. Install '${cmd}' or a container runtime (Docker/Nerdctl) to proceed." >&2 echo ((ERRORCODE++)) fi @@ -151,11 +156,19 @@ 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.yml ${MD_DOC_PATH} --rules doc/.markdownlint/rules" + yarn markdownlint --config .markdownlint.yml ${MD_DOC_PATH} --rules doc/.markdownlint/rules + + if [ $? -ne 0 ] + then + echo + echo '✖ ERROR: Markdownlint failed with errors.' >&2 + echo + ((ERRORCODE++)) + fi fi echo '=> Linting prose...' -run_locally_or_in_docker 'vale' "--minAlertLevel error --output=doc/.vale/vale.tmpl ${MD_DOC_PATH}" +run_locally_or_in_container 'vale' "--minAlertLevel error --output=doc/.vale/vale.tmpl ${MD_DOC_PATH}" if [ $ERRORCODE -ne 0 ] then