From 552e72c1aa61bf00fccc1d2c4925889fd1aadcec Mon Sep 17 00:00:00 2001 From: David Dieulivol Date: Fri, 23 Dec 2022 08:54:37 +0000 Subject: [PATCH] Revert "Merge branch 'brodock/improve-docs-lint' into 'master'" This reverts merge request !106469 --- .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 +++++- lib/tasks/lint.rake | 5 ---- scripts/lint-doc.sh | 25 +++++--------------- 7 files changed, 34 insertions(+), 28 deletions(-) create mode 100644 doc/.markdownlint/require_helper.js diff --git a/.gitlab/ci/docs.gitlab-ci.yml b/.gitlab/ci/docs.gitlab-ci.yml index 84d810e7db7b37..02fc58f8580376 100644 --- a/.gitlab/ci/docs.gitlab-ci.yml +++ b/.gitlab/ci/docs.gitlab-ci.yml @@ -65,7 +65,6 @@ 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 new file mode 100644 index 00000000000000..7d06cf67419fdf --- /dev/null +++ b/doc/.markdownlint/require_helper.js @@ -0,0 +1,14 @@ +/** + * 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 8a9e9c2434e1f2..e0e2c1a0a9b910 100644 --- a/doc/.markdownlint/rules/tabs_blank_lines.js +++ b/doc/.markdownlint/rules/tabs_blank_lines.js @@ -1,4 +1,9 @@ -const { forEachLine, getLineMetadata, isBlankLine } = require(`markdownlint-rule-helpers`); +const { globalPath } = require('../require_helper'); +const { + forEachLine, + getLineMetadata, + isBlankLine, +} = require(`${globalPath}/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 0461ac8385f3a3..9c1de1e630d775 100644 --- a/doc/.markdownlint/rules/tabs_title_markup.js +++ b/doc/.markdownlint/rules/tabs_title_markup.js @@ -1,4 +1,5 @@ -const { forEachLine, getLineMetadata } = require(`markdownlint-rule-helpers`); +const { globalPath } = require('../require_helper'); +const { forEachLine, getLineMetadata } = require(`${globalPath}/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 beb329231b1f5f..672aa70f562442 100644 --- a/doc/.markdownlint/rules/tabs_title_text.js +++ b/doc/.markdownlint/rules/tabs_title_text.js @@ -1,4 +1,9 @@ -const { forEachLine, getLineMetadata, isBlankLine } = require(`markdownlint-rule-helpers`); +const { globalPath } = require('../require_helper'); +const { + forEachLine, + getLineMetadata, + isBlankLine, +} = require(`${globalPath}/markdownlint-rule-helpers`); module.exports = { names: ['tabs-title-text'], diff --git a/lib/tasks/lint.rake b/lib/tasks/lint.rake index 6e50e417776da3..62d31803f6ee52 100644 --- a/lib/tasks/lint.rake +++ b/lib/tasks/lint.rake @@ -34,11 +34,6 @@ 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 1c934c07608d98..68dfac95ef6a77 100755 --- a/scripts/lint-doc.sh +++ b/scripts/lint-doc.sh @@ -119,24 +119,19 @@ else fi fi -function run_locally_or_in_container() { +function run_locally_or_in_docker() { local cmd=$1 local args=$2 if hash ${cmd} 2>/dev/null 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 to use, we need to probe each runtime - elif (hash nerdctl 2>/dev/null) && (nerdctl info 2>&1 1>/dev/null) + elif hash docker 2>/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} + 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 + echo " ✖ ERROR: '${cmd}' not found. Install '${cmd}' or Docker to proceed." >&2 echo ((ERRORCODE++)) fi @@ -156,19 +151,11 @@ if [ -z "${MD_DOC_PATH}" ] then echo "Merged results pipeline detected, but no markdown files found. Skipping." else - 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 + run_locally_or_in_docker 'markdownlint' "--config .markdownlint.yml ${MD_DOC_PATH} --rules doc/.markdownlint/rules" fi echo '=> Linting prose...' -run_locally_or_in_container 'vale' "--minAlertLevel error --output=doc/.vale/vale.tmpl ${MD_DOC_PATH}" +run_locally_or_in_docker 'vale' "--minAlertLevel error --output=doc/.vale/vale.tmpl ${MD_DOC_PATH}" if [ $ERRORCODE -ne 0 ] then -- GitLab