pr.yml test for disallowed character checks #26468
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Pull Request Checks | |
| permissions: | |
| contents: read | |
| pull-requests: read | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| merge_group: | |
| types: | |
| - checks_requested | |
| env: | |
| CI: true | |
| NODE_ENV: production | |
| NODE_OPTIONS: "--max-old-space-size=8192 --max-http-header-size=8192" | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: '20.x' | |
| cache: 'yarn' | |
| - name: Docusaurus Webpack cache | |
| uses: actions/cache@v3 | |
| with: | |
| path: node_modules/.cache | |
| key: ${{ runner.os }}-webpack-cache-${{ hashFiles('yarn.lock') }} | |
| - name: Install dependencies | |
| run: yarn install --frozen-lockfile | |
| - name: Build the Docusaurus site | |
| run: yarn build | |
| # --- NEW: Disallowed character checks for Pantheon --- | |
| # 1) Fail if any file path in the build output contains disallowed characters | |
| - name: Check build artifact paths for disallowed characters | |
| env: | |
| BUILD_DIR: build | |
| shell: bash | |
| run: | | |
| if [ ! -d "$BUILD_DIR" ]; then | |
| echo "No $BUILD_DIR directory found; skipping path check." | |
| exit 0 | |
| fi | |
| # Disallowed chars: " : < > | * ? | |
| OFFENDERS="$(find "$BUILD_DIR" -type f | grep -E '[" :<>|*?]')" || true | |
| if [ -n "$OFFENDERS" ]; then | |
| echo "❌ Disallowed characters found in build artifact paths:" | |
| echo "$OFFENDERS" | |
| while IFS= read -r p; do | |
| rel="${p#$(pwd)/}" | |
| [ "$rel" = "$p" ] && rel="$p" | |
| # Detect and print which character(s) caused it | |
| badchars=$(echo "$rel" | grep -oE '[" :<>|*?]' | tr -d '\n') | |
| echo "::error file=${rel}::Disallowed character(s) found in build artifact path: [${badchars}] (Pantheon rejects paths containing any of: \" : < > | * ?)" | |
| done <<< "$OFFENDERS" | |
| exit 1 | |
| fi | |
| echo "✅ No disallowed characters found in build artifact paths." | |
| # 2) Fail if any Markdown/MDX link target contains disallowed characters (excluding external links) | |
| - name: Check Markdown/MDX links for disallowed characters | |
| shell: bash | |
| run: | | |
| FILES="$(git ls-files '*.md' '*.mdx' 2>/dev/null || true)" | |
| if [ -z "$FILES" ]; then | |
| echo "No Markdown/MDX files found; skipping link check." | |
| exit 0 | |
| fi | |
| BAD_LINKS=$( | |
| awk ' | |
| { | |
| line=$0 | |
| while (match(line, /\]\(([^)]+)\)/, m)) { | |
| url=m[1] | |
| # skip external schemes | |
| if (url ~ /^(https?:|mailto:|tel:)/) { line=substr(line, RSTART+RLENGTH); continue } | |
| # drop query + fragment | |
| sub(/\?.*$/, "", url) | |
| sub(/#.*/, "", url) | |
| # flag if contains disallowed characters: " : < > | * ? | |
| if (url ~ /[" :<>|*?]/) { | |
| printf("%s\t%d\t%s\n", FILENAME, FNR, m[0]) | |
| } | |
| line=substr(line, RSTART+RLENGTH) | |
| } | |
| } | |
| ' $FILES | |
| ) | |
| if [ -n "$BAD_LINKS" ]; then | |
| echo "❌ Disallowed characters found in Markdown/MDX link targets:" | |
| echo "$BAD_LINKS" | |
| # Emit GitHub annotations for each finding (including exact bad char(s)) | |
| while IFS=$'\t' read -r file line match; do | |
| [ -z "$file" ] && continue | |
| badchars=$(echo "$match" | grep -oE '[" :<>|*?]' | tr -d '\n') | |
| echo "::error file=${file},line=${line}::Disallowed character(s) in Markdown link target: [${badchars}] ${match} (Not allowed: \" : < > | * ?)" | |
| done <<< "$BAD_LINKS" | |
| exit 1 | |
| fi | |
| echo "✅ No disallowed characters found in Markdown/MDX link targets." | |
| spellcheck: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: codespell-project/actions-codespell@master | |
| name: Check spelling | |
| with: | |
| skip: "*.svg,*.js,*.map,*.css,*.scss" | |
| ignore_words_list: "aks,atleast,cros,ddress,delink,fiel,ist,nd,ot,pullrequest,ser,shttp,wast,fo,seldomly,delt,cruzer,plack,secur,te,nginx,Nginx,notin" | |
| path: docs |