Skip to content

Commit 39f8784

Browse files
authored
Merge pull request #784 from per1234/check-markdown-platform-specific
Avoid platform-specific code in `markdown:check-links` task
2 parents 32fbff1 + a7443f8 commit 39f8784

File tree

1 file changed

+28
-35
lines changed

1 file changed

+28
-35
lines changed

Taskfile.yml

+28-35
Original file line numberDiff line numberDiff line change
@@ -318,46 +318,39 @@ tasks:
318318
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
319319
markdown:check-links:
320320
desc: Check for broken links
321+
vars:
322+
# The command is defined in a Taskfile variable to allow it to be broken into multiple lines for readability.
323+
# This can't be done in the `cmd` object of the Taskfile because `npx --call` uses the native shell, which causes
324+
# standard newline escaping syntax to not work when the task is run on Windows.
325+
#
326+
# Using -regex instead of -name to avoid Task's behavior of globbing even when quoted on Windows
327+
# The odd method for escaping . in the regex is required for windows compatibility because mvdan.cc/sh gives
328+
# \ characters special treatment on Windows in an attempt to support them as path separators.
329+
#
330+
# prettier-ignore
331+
CHECK_LINKS_COMMAND:
332+
"
333+
find . \
334+
-type d -name \".git\" -prune -o \
335+
-type d -name \".licenses\" -prune -o \
336+
-type d -name \"__pycache__\" -prune -o \
337+
-type d -name \"node_modules\" -prune -o \
338+
-regex \".*[.]md\" \
339+
-exec \
340+
markdown-link-check \
341+
--quiet \
342+
--config \"./.markdown-link-check.json\" \
343+
\\{\\} \
344+
+
345+
"
321346
deps:
322347
- task: docs:generate
323348
- task: npm:install-deps
324349
cmds:
325350
- |
326-
if [[ "{{.OS}}" == "Windows_NT" ]]; then
327-
# npx --call uses the native shell, which makes it too difficult to use npx for this application on Windows,
328-
# so the Windows user is required to have markdown-link-check installed and in PATH.
329-
if ! which markdown-link-check &>/dev/null; then
330-
echo "markdown-link-check not found or not in PATH. Please install: https://github.com/tcort/markdown-link-check#readme"
331-
exit 1
332-
fi
333-
# Default behavior of the task on Windows is to exit the task when the first broken link causes a non-zero
334-
# exit status, but it's better to check all links before exiting.
335-
set +o errexit
336-
STATUS=0
337-
# Using -regex instead of -name to avoid Task's behavior of globbing even when quoted on Windows
338-
# The odd method for escaping . in the regex is required for windows compatibility because mvdan.cc/sh gives
339-
# \ characters special treatment on Windows in an attempt to support them as path separators.
340-
for file in $(find . -regex ".*[.]md"); do
341-
markdown-link-check \
342-
--quiet \
343-
--config "./.markdown-link-check.json" \
344-
"$file"
345-
STATUS=$(( $STATUS + $? ))
346-
done
347-
exit $STATUS
348-
else
349-
npx --package=markdown-link-check --call='
350-
STATUS=0
351-
for file in $(find . -regex ".*[.]md"); do
352-
markdown-link-check \
353-
--quiet \
354-
--config "./.markdown-link-check.json" \
355-
"$file"
356-
STATUS=$(( $STATUS + $? ))
357-
done
358-
exit $STATUS
359-
'
360-
fi
351+
npx \
352+
--package=markdown-link-check \
353+
--call='{{.CHECK_LINKS_COMMAND}}'
361354
362355
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
363356
markdown:fix:

0 commit comments

Comments
 (0)