From db5f433258b6ed094369537b193af8773e16d268 Mon Sep 17 00:00:00 2001 From: Patrice Chalin Date: Sat, 8 Jun 2024 08:00:10 -0400 Subject: [PATCH] [CI] Upgrade gulp to v5 --- gulp-src/lint-md.js | 30 +++++++++++++++++++++++++----- package.json | 2 +- scripts/check-markdown-wrapper.sh | 14 ++++++++++++++ 3 files changed, 40 insertions(+), 6 deletions(-) create mode 100755 scripts/check-markdown-wrapper.sh diff --git a/gulp-src/lint-md.js b/gulp-src/lint-md.js index 513c8d37bf49..ee12d51ff5d2 100644 --- a/gulp-src/lint-md.js +++ b/gulp-src/lint-md.js @@ -6,13 +6,17 @@ const markdownlint = require('markdownlint'); const { taskArgs, trimBlankLinesFromArray } = require('./_util'); const fs = require('fs'); -const defaultGlob = '**/*.md'; +const defaultGlobs = [ + '**/*.md', +]; const markdownFiles = [ '!.github/**', '!content-modules/**', + '!examples/**', '!layouts/**', '!node_modules/**', '!scripts/registry-scanner/node_modules/**', + '!tools/examples/**', '!themes/**', '!tmp/**', ]; @@ -121,13 +125,25 @@ function applyFixesToFileContent(content, issue) { return lines.join('\n'); } +function logFiles(debug) { + return through2.obj(function (file, enc, cb) { + if (debug) { console.log('Processing file:', file.path); } + cb(null, file); + }); +} + function lintMarkdown() { const argv = taskArgs().options({ glob: { alias: 'g', - type: 'string', - description: 'Glob of files to run through markdownlint.', - default: defaultGlob, + type: 'array', + description: 'Globs of files to run through markdownlint. List flag more than once for multiple values.', + default: defaultGlobs, + }, + debug: { + type: 'boolean', + description: 'Output debugging information.', + default: false, }, fix: { type: 'boolean', @@ -142,8 +158,12 @@ function lintMarkdown() { } fix = argv.fix; + const globs = [...argv.glob, ...markdownFiles]; + if (argv.debug) { console.log('Globs being used:', globs); } + return gulp - .src([argv.glob, ...markdownFiles]) + .src(globs, { followSymlinks: false }) + .pipe(logFiles(argv.debug)) .pipe(through2.obj(markdownLintFile)) .on('end', () => { const fileOrFiles = 'file' + (numFilesProcessed == 1 ? '' : 's'); diff --git a/package.json b/package.json index 67bdf4829ce2..7acda5cd94ef 100644 --- a/package.json +++ b/package.json @@ -98,7 +98,7 @@ "devDependencies": { "autoprefixer": "^10.4.19", "cspell": "^8.8.4", - "gulp": "^4.0.2", + "gulp": "^5.0.0", "hugo-extended": "0.126.3", "markdown-link-check": "^3.12.2", "markdownlint": "^0.34.0", diff --git a/scripts/check-markdown-wrapper.sh b/scripts/check-markdown-wrapper.sh new file mode 100755 index 000000000000..b74ee5922593 --- /dev/null +++ b/scripts/check-markdown-wrapper.sh @@ -0,0 +1,14 @@ +#!/bin/bash -e +# +# @chalin can't get Gulp 5 to ignore symlinks, so this wrapper creates +# bogus symlink targets to make the check:markdown Gulp task happy. + +symlink_target="content-modules/opentelemetry-go/example" + +if [[ ! -e $symlink_target ]]; then + echo "WARNING: required symlink target does not exist, creating it: $symlink_target" + (set -x; mkdir -p $symlink_target) +fi + +set -x +exec npx gulp lint-md "$@"