Skip to content

Commit 872d07f

Browse files
authored
pr.yml test for disallowed character checks (#5891)
* pr.yml test for disallowed character checks * Update .github/workflows/pr.yml * Update cid-redirects.json * test '>' character break * Update cid-redirects.json Test vertical bar '|' * Update cid-redirects.json * Update cid-redirects.json * test PR checks with line gaps closed * Update cid-redirects.json * Update cid-redirects.json * test new build showing the specific offending characters * Fix pr.yml code, remove old md alt text * rm test failure in cid-redirects * Change pr.yml to ignore code blocks + inline code, only match real text * broken link * Apply suggestion from @kimsauce * Update index.md revert - test * Update cid-redirects.json
1 parent f72252a commit 872d07f

File tree

7 files changed

+150
-68
lines changed

7 files changed

+150
-68
lines changed

.github/workflows/pr.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,88 @@ jobs:
3636
run: yarn install --frozen-lockfile
3737
- name: Build the Docusaurus site
3838
run: yarn build
39+
# --- Disallowed character checks for Pantheon ---
40+
# 1) Fail if any file path in the build output contains disallowed characters
41+
- name: Check build artifact paths for disallowed characters
42+
env:
43+
BUILD_DIR: build
44+
shell: bash
45+
run: |
46+
if [ ! -d "$BUILD_DIR" ]; then
47+
echo "No $BUILD_DIR directory found; skipping path check."
48+
exit 0
49+
fi
50+
# Disallowed chars: " : < > | * ?
51+
OFFENDERS="$(find "$BUILD_DIR" -type f | grep -E '[":<>|*?]')" || true
52+
if [ -n "$OFFENDERS" ]; then
53+
echo "❌ Disallowed characters found in build artifact paths:"
54+
echo "$OFFENDERS"
55+
while IFS= read -r p; do
56+
rel="${p#$(pwd)/}"
57+
[ "$rel" = "$p" ] && rel="$p"
58+
badchars=$(echo "$rel" | grep -oE '[":<>|*?]' | tr -d '\n')
59+
echo "::error file=${rel}::Disallowed character(s) found in build artifact path: [${badchars}] (Pantheon rejects paths containing any of: \" : < > | * ?)"
60+
done <<< "$OFFENDERS"
61+
exit 1
62+
fi
63+
echo "✅ No disallowed characters found in build artifact paths."
64+
# 2) Fail if any Markdown/MDX link target contains disallowed characters (excluding external links).
65+
# Ignores fenced code blocks (```/~~~) and inline code (`...`) to avoid false positives from code samples.
66+
- name: Check Markdown/MDX links for disallowed characters
67+
shell: bash
68+
run: |
69+
FILES="$(git ls-files '*.md' '*.mdx' 2>/dev/null || true)"
70+
if [ -z "$FILES" ]; then
71+
echo "No Markdown/MDX files found; skipping link check."
72+
exit 0
73+
fi
74+
BAD_LINKS=$(
75+
awk '
76+
BEGIN { in_code=0 }
77+
{
78+
raw=$0
79+
80+
# Toggle fenced code blocks starting with ``` or ~~~
81+
if (match(raw, /^\s*(```|~~~)/)) { in_code = !in_code; next }
82+
if (in_code) { next }
83+
84+
# Strip inline code spans so patterns inside don’t trigger
85+
line = raw
86+
gsub(/`[^`]*`/, "", line)
87+
88+
# Find real Markdown links: [text](url)
89+
while (match(line, /\[[^]]+\]\(([^)]+)\)/, m)) {
90+
url=m[1]
91+
92+
# Skip external schemes
93+
if (url ~ /^(https?:|mailto:|tel:)/) { line=substr(line, RSTART+RLENGTH); continue }
94+
95+
# Drop query + fragment
96+
sub(/\?.*$/, "", url)
97+
sub(/#.*/, "", url)
98+
99+
# Disallowed characters in relative link targets: " : < > | * ?
100+
if (url ~ /[":<>|*?]/) {
101+
printf("%s\t%d\t%s\n", FILENAME, FNR, m[0])
102+
}
103+
104+
line=substr(line, RSTART+RLENGTH)
105+
}
106+
}
107+
' $FILES
108+
)
109+
110+
if [ -n "$BAD_LINKS" ]; then
111+
echo "❌ Disallowed characters found in Markdown/MDX link targets:"
112+
echo "$BAD_LINKS"
113+
while IFS=$'\t' read -r file line match; do
114+
[ -z "$file" ] && continue
115+
badchars=$(echo "$match" | grep -oE '[":<>|*?]' | tr -d '\n')
116+
echo "::error file=${file},line=${line}::Disallowed character(s) in Markdown link target: [${badchars}] ${match} (Not allowed: \" : < > | * ?)"
117+
done <<< "$BAD_LINKS"
118+
exit 1
119+
fi
120+
echo "✅ No disallowed characters found in Markdown/MDX link targets."
39121
spellcheck:
40122
runs-on: ubuntu-latest
41123
steps:

0 commit comments

Comments
 (0)