|
36 | 36 | run: yarn install --frozen-lockfile |
37 | 37 | - name: Build the Docusaurus site |
38 | 38 | 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." |
39 | 121 | spellcheck: |
40 | 122 | runs-on: ubuntu-latest |
41 | 123 | steps: |
|
0 commit comments