Skip to content

Commit 7530cab

Browse files
authored
Merge pull request #422 from per1234/unify-markdown-link-check
Avoid platform-specific code in `markdown:check-links` task
2 parents 4eb4e89 + fa253b2 commit 7530cab

File tree

2 files changed

+58
-104
lines changed

2 files changed

+58
-104
lines changed

Taskfile.yml

Lines changed: 30 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -625,65 +625,41 @@ tasks:
625625
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
626626
markdown:check-links:
627627
desc: Check for broken links
628+
vars:
629+
# The command is defined in a Taskfile variable to allow it to be broken into multiple lines for readability.
630+
# This can't be done in the `cmd` object of the Taskfile because `npx --call` uses the native shell, which causes
631+
# standard newline escaping syntax to not work when the task is run on Windows.
632+
#
633+
# Using -regex instead of -name to avoid Task's behavior of globbing even when quoted on Windows
634+
# The odd method for escaping . in the regex is required for windows compatibility because mvdan.cc/sh gives
635+
# \ characters special treatment on Windows in an attempt to support them as path separators.
636+
#
637+
# prettier-ignore
638+
CHECK_LINKS_COMMAND:
639+
"
640+
find . \
641+
-type d -name \".git\" -prune -o \
642+
-type d -name \".licenses\" -prune -o \
643+
-type d -name \"__pycache__\" -prune -o \
644+
-type d -name \"node_modules\" -prune -o \
645+
-path \"./{{.CLANG_FORMAT_GOLDEN_TEST_DATA_FOLDER}}/samples\" -prune -o \
646+
-path \"./{{.CLANG_FORMAT_INPUT_TEST_DATA_FOLDER}}/samples\" -prune -o \
647+
-regex \".*[.]md\" \
648+
-exec \
649+
markdown-link-check \
650+
--quiet \
651+
--config \"./.markdown-link-check.json\" \
652+
\\{\\} \
653+
+
654+
"
628655
deps:
629656
- task: docs:generate
630657
- task: npm:install-deps
631658
cmds:
632659
- |
633-
if [[ "{{.OS}}" == "Windows_NT" ]]; then
634-
# npx --call uses the native shell, which makes it too difficult to use npx for this application on Windows,
635-
# so the Windows user is required to have markdown-link-check installed and in PATH.
636-
if ! which markdown-link-check &>/dev/null; then
637-
echo "markdown-link-check not found or not in PATH."
638-
echo "Please install: https://github.com/tcort/markdown-link-check#readme"
639-
exit 1
640-
fi
641-
# Default behavior of the task on Windows is to exit the task when the first broken link causes a non-zero
642-
# exit status, but it's better to check all links before exiting.
643-
set +o errexit
644-
STATUS=0
645-
# Using -regex instead of -name to avoid Task's behavior of globbing even when quoted on Windows
646-
# The odd method for escaping . in the regex is required for windows compatibility because mvdan.cc/sh gives
647-
# \ characters special treatment on Windows in an attempt to support them as path separators.
648-
for file in $(
649-
find . \
650-
-type d -name '.git' -prune -o \
651-
-type d -name '.licenses' -prune -o \
652-
-type d -name '__pycache__' -prune -o \
653-
-type d -name 'node_modules' -prune -o \
654-
-path './{{.CLANG_FORMAT_GOLDEN_TEST_DATA_FOLDER}}/samples' -prune -o \
655-
-path './{{.CLANG_FORMAT_INPUT_TEST_DATA_FOLDER}}/samples' -prune -o \
656-
-regex ".*[.]md" -print
657-
); do
658-
markdown-link-check \
659-
--quiet \
660-
--config "./.markdown-link-check.json" \
661-
"$file"
662-
STATUS=$(( $STATUS + $? ))
663-
done
664-
exit $STATUS
665-
else
666-
npx --package=markdown-link-check --call='
667-
STATUS=0
668-
for file in $(
669-
find . \
670-
-type d -name '.git' -prune -o \
671-
-type d -name '.licenses' -prune -o \
672-
-type d -name '__pycache__' -prune -o \
673-
-type d -name 'node_modules' -prune -o \
674-
-path './{{.CLANG_FORMAT_GOLDEN_TEST_DATA_FOLDER}}/samples' -prune -o \
675-
-path './{{.CLANG_FORMAT_INPUT_TEST_DATA_FOLDER}}/samples' -prune -o \
676-
-regex ".*[.]md" -print
677-
); do
678-
markdown-link-check \
679-
--quiet \
680-
--config "./.markdown-link-check.json" \
681-
"$file"
682-
STATUS=$(( $STATUS + $? ))
683-
done
684-
exit $STATUS
685-
'
686-
fi
660+
npx \
661+
--package=markdown-link-check \
662+
--call='{{.CHECK_LINKS_COMMAND}}'
687663
688664
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
689665
markdown:fix:

workflow-templates/assets/check-markdown-task/Taskfile.yml

Lines changed: 28 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,61 +10,39 @@ tasks:
1010
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
1111
markdown:check-links:
1212
desc: Check for broken links
13+
vars:
14+
# The command is defined in a Taskfile variable to allow it to be broken into multiple lines for readability.
15+
# This can't be done in the `cmd` object of the Taskfile because `npx --call` uses the native shell, which causes
16+
# standard newline escaping syntax to not work when the task is run on Windows.
17+
#
18+
# Using -regex instead of -name to avoid Task's behavior of globbing even when quoted on Windows
19+
# The odd method for escaping . in the regex is required for windows compatibility because mvdan.cc/sh gives
20+
# \ characters special treatment on Windows in an attempt to support them as path separators.
21+
#
22+
# prettier-ignore
23+
CHECK_LINKS_COMMAND:
24+
"
25+
find . \
26+
-type d -name \".git\" -prune -o \
27+
-type d -name \".licenses\" -prune -o \
28+
-type d -name \"__pycache__\" -prune -o \
29+
-type d -name \"node_modules\" -prune -o \
30+
-regex \".*[.]md\" \
31+
-exec \
32+
markdown-link-check \
33+
--quiet \
34+
--config \"./.markdown-link-check.json\" \
35+
\\{\\} \
36+
+
37+
"
1338
deps:
1439
- task: docs:generate
1540
- task: npm:install-deps
1641
cmds:
1742
- |
18-
if [[ "{{.OS}}" == "Windows_NT" ]]; then
19-
# npx --call uses the native shell, which makes it too difficult to use npx for this application on Windows,
20-
# so the Windows user is required to have markdown-link-check installed and in PATH.
21-
if ! which markdown-link-check &>/dev/null; then
22-
echo "markdown-link-check not found or not in PATH."
23-
echo "Please install: https://github.com/tcort/markdown-link-check#readme"
24-
exit 1
25-
fi
26-
# Default behavior of the task on Windows is to exit the task when the first broken link causes a non-zero
27-
# exit status, but it's better to check all links before exiting.
28-
set +o errexit
29-
STATUS=0
30-
# Using -regex instead of -name to avoid Task's behavior of globbing even when quoted on Windows
31-
# The odd method for escaping . in the regex is required for windows compatibility because mvdan.cc/sh gives
32-
# \ characters special treatment on Windows in an attempt to support them as path separators.
33-
for file in $(
34-
find . \
35-
-type d -name '.git' -prune -o \
36-
-type d -name '.licenses' -prune -o \
37-
-type d -name '__pycache__' -prune -o \
38-
-type d -name 'node_modules' -prune -o \
39-
-regex ".*[.]md" -print
40-
); do
41-
markdown-link-check \
42-
--quiet \
43-
--config "./.markdown-link-check.json" \
44-
"$file"
45-
STATUS=$(( $STATUS + $? ))
46-
done
47-
exit $STATUS
48-
else
49-
npx --package=markdown-link-check --call='
50-
STATUS=0
51-
for file in $(
52-
find . \
53-
-type d -name '.git' -prune -o \
54-
-type d -name '.licenses' -prune -o \
55-
-type d -name '__pycache__' -prune -o \
56-
-type d -name 'node_modules' -prune -o \
57-
-regex ".*[.]md" -print
58-
); do
59-
markdown-link-check \
60-
--quiet \
61-
--config "./.markdown-link-check.json" \
62-
"$file"
63-
STATUS=$(( $STATUS + $? ))
64-
done
65-
exit $STATUS
66-
'
67-
fi
43+
npx \
44+
--package=markdown-link-check \
45+
--call='{{.CHECK_LINKS_COMMAND}}'
6846
6947
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
7048
markdown:fix:

0 commit comments

Comments
 (0)