From 69cba5f5dfa73e43436b610621119bc4171d9e34 Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto Date: Thu, 8 Dec 2022 18:07:39 +0100 Subject: [PATCH 1/3] Add `rake lint:markdown` to call docs related lint command --- lib/tasks/lint.rake | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/tasks/lint.rake b/lib/tasks/lint.rake index 62d31803f6ee52..6e50e417776da3 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 -- GitLab From 03647af1d4196deff8c53e3b99dd3b664b6db688 Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto Date: Thu, 8 Dec 2022 18:09:05 +0100 Subject: [PATCH 2/3] Allow both Docker and Nerdctl container runtimes for lint-doc.sh --- scripts/lint-doc.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/scripts/lint-doc.sh b/scripts/lint-doc.sh index 68dfac95ef6a77..a0d703cd13ec1f 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 is to use we need to probe each runtime + elif (hash nerdctl 2>/dev/null) && (nerdctl info 2>&1 1>/dev/null) + then + 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,11 @@ 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" + run_locally_or_in_container 'markdownlint' "--config .markdownlint.yml ${MD_DOC_PATH} --rules doc/.markdownlint/rules" 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 -- GitLab From 5d2c33ae573b28f6e1221c0910ad4b8a747d8a06 Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto Date: Thu, 8 Dec 2022 18:09:39 +0100 Subject: [PATCH 3/3] markdownlint should always be run from yarn --- .gitlab/ci/docs.gitlab-ci.yml | 1 + doc/.markdownlint/require_helper.js | 14 -------------- doc/.markdownlint/rules/tabs_blank_lines.js | 7 +------ doc/.markdownlint/rules/tabs_title_markup.js | 3 +-- doc/.markdownlint/rules/tabs_title_text.js | 7 +------ scripts/lint-doc.sh | 16 ++++++++++++---- 6 files changed, 16 insertions(+), 32 deletions(-) delete mode 100644 doc/.markdownlint/require_helper.js diff --git a/.gitlab/ci/docs.gitlab-ci.yml b/.gitlab/ci/docs.gitlab-ci.yml index 18954e7b8e0a02..ee0784fe0d9a42 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 7d06cf67419fdf..00000000000000 --- 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 e0e2c1a0a9b910..8a9e9c2434e1f2 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 9c1de1e630d775..0461ac8385f3a3 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 672aa70f562442..beb329231b1f5f 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/scripts/lint-doc.sh b/scripts/lint-doc.sh index a0d703cd13ec1f..1c934c07608d98 100755 --- a/scripts/lint-doc.sh +++ b/scripts/lint-doc.sh @@ -127,13 +127,13 @@ function run_locally_or_in_container() { then $cmd $args # When using software like Rancher Desktop, both nerdctl and docker binaries are available - # but only one is configured. To check which one is to use we need to probe each runtime + # 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 - 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} + 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} + 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 a container runtime (Docker/Nerdctl) to proceed." >&2 @@ -156,7 +156,15 @@ if [ -z "${MD_DOC_PATH}" ] then echo "Merged results pipeline detected, but no markdown files found. Skipping." else - run_locally_or_in_container '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...' -- GitLab