Skip to content

Commit be8a2bd

Browse files
authored
Merge pull request #155 from per1234/unify-markdown-link-check
Avoid platform-specific code in markdown:check-links task
2 parents 0f5a14c + 1949cae commit be8a2bd

File tree

1 file changed

+28
-49
lines changed

1 file changed

+28
-49
lines changed

Taskfile.yml

Lines changed: 28 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -188,60 +188,39 @@ tasks:
188188
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
189189
markdown:check-links:
190190
desc: Check for broken links
191+
vars:
192+
# The command is defined in a Taskfile variable to allow it to be broken into multiple lines for readability.
193+
# This can't be done in the `cmd` object of the Taskfile because `npx --call` uses the native shell, which causes
194+
# standard newline escaping syntax to not work when the task is run on Windows.
195+
#
196+
# Using -regex instead of -name to avoid Task's behavior of globbing even when quoted on Windows
197+
# The odd method for escaping . in the regex is required for windows compatibility because mvdan.cc/sh gives
198+
# \ characters special treatment on Windows in an attempt to support them as path separators.
199+
#
200+
# prettier-ignore
201+
CHECK_LINKS_COMMAND:
202+
"
203+
find . \
204+
-type d -name \".git\" -prune -o \
205+
-type d -name \".licenses\" -prune -o \
206+
-type d -name \"__pycache__\" -prune -o \
207+
-type d -name \"node_modules\" -prune -o \
208+
-regex \".*[.]md\" \
209+
-exec \
210+
markdown-link-check \
211+
--quiet \
212+
--config \"./.markdown-link-check.json\" \
213+
\\{\\} \
214+
+
215+
"
191216
deps:
192217
- task: docs:generate
193218
- task: npm:install-deps
194219
cmds:
195220
- |
196-
if [[ "{{.OS}}" == "Windows_NT" ]]; then
197-
# npx --call uses the native shell, which makes it too difficult to use npx for this application on Windows,
198-
# so the Windows user is required to have markdown-link-check installed and in PATH.
199-
if ! which markdown-link-check &>/dev/null; then
200-
echo "markdown-link-check not found or not in PATH. Please install: https://github.com/tcort/markdown-link-check#readme"
201-
exit 1
202-
fi
203-
# Default behavior of the task on Windows is to exit the task when the first broken link causes a non-zero
204-
# exit status, but it's better to check all links before exiting.
205-
set +o errexit
206-
STATUS=0
207-
# Using -regex instead of -name to avoid Task's behavior of globbing even when quoted on Windows
208-
# The odd method for escaping . in the regex is required for windows compatibility because mvdan.cc/sh gives
209-
# \ characters special treatment on Windows in an attempt to support them as path separators.
210-
for file in $(
211-
find . \
212-
-type d -name '.git' -prune -o \
213-
-type d -name '.licenses' -prune -o \
214-
-type d -name '__pycache__' -prune -o \
215-
-type d -name 'node_modules' -prune -o \
216-
-regex ".*[.]md" -print
217-
); do
218-
markdown-link-check \
219-
--quiet \
220-
--config "./.markdown-link-check.json" \
221-
"$file"
222-
STATUS=$(( $STATUS + $? ))
223-
done
224-
exit $STATUS
225-
else
226-
npx --package=markdown-link-check --call='
227-
STATUS=0
228-
for file in $(
229-
find . \
230-
-type d -name '.git' -prune -o \
231-
-type d -name '.licenses' -prune -o \
232-
-type d -name '__pycache__' -prune -o \
233-
-type d -name 'node_modules' -prune -o \
234-
-regex ".*[.]md" -print
235-
); do
236-
markdown-link-check \
237-
--quiet \
238-
--config "./.markdown-link-check.json" \
239-
"$file"
240-
STATUS=$(( $STATUS + $? ))
241-
done
242-
exit $STATUS
243-
'
244-
fi
221+
npx \
222+
--package=markdown-link-check \
223+
--call='{{.CHECK_LINKS_COMMAND}}'
245224
246225
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
247226
markdown:fix:

0 commit comments

Comments
 (0)