Skip to content

Commit ecf4db2

Browse files
authored
fix: resolve 'Invalid path to URI' warnings in link checker (#1546)
## Description This PR fixes the "Invalid path to URI" warnings that were appearing in the link checker workflow, as seen in [run #17112628120](https://github.com/wandb/docs/actions/runs/17112628120/job/48537193784#step:5:91). ## Problem The link checker was encountering relative links like `/guides/hosting/hosting-options/self-managed/` in the markdown files but couldn't resolve them without a base URL. This caused many warnings in the workflow output. ## Solution 1. **Added `--base-url` parameter** to lychee so it can properly resolve relative paths 2. **Dynamic base URL detection**: - For main branch: Uses production URL `https://docs.wandb.ai` - For PR branches: Uses Cloudflare branch preview URL (e.g., `https://branch-name.docodile.pages.dev`) 3. **Proper branch name conversion** to match Cloudflare's format: - 28 character limit - Lowercase - Special characters replaced with hyphens - Leading/trailing hyphens removed 4. **Retry logic** for checking preview URL availability (new PRs may take time to deploy) 5. **Clear reporting** of which base URL was used in the workflow summary ## Benefits - ✅ Eliminates "Invalid path to URI" warnings - ✅ Checks links against the correct environment: - PR branches check against their preview deployment - Main branch checks against production - ✅ Better visibility with base URL shown in workflow summary - ✅ More accurate link checking for PRs (checks against PR's changes, not production) ## Testing The workflow now: 1. Detects if it's running on main or a PR branch 2. Constructs the appropriate Cloudflare preview URL for PRs 3. Tests if the preview is accessible (with retries) 4. Falls back to production URL if preview isn't ready 5. Uses the determined base URL for all link checking This ensures relative links are properly resolved and checked against the appropriate environment.
1 parent 4c15e4b commit ecf4db2

1 file changed

Lines changed: 61 additions & 1 deletion

File tree

.github/workflows/linkcheck.yml

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,69 @@ jobs:
2323
- name: Ensure lychee output dir
2424
run: mkdir -p lychee
2525

26+
- name: Determine base URL
27+
id: base-url
28+
run: |
29+
# Default to production URL
30+
BASE_URL="https://docs.wandb.ai"
31+
32+
# If we're on a PR branch, try to use Cloudflare preview URL
33+
if [[ "${{ github.event_name }}" == "pull_request" ]] || [[ "${{ github.ref }}" != "refs/heads/main" ]]; then
34+
# Extract branch name
35+
BRANCH_NAME="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}"
36+
37+
# Convert branch name to Cloudflare format:
38+
# 1. Take first 28 chars of branch name (Cloudflare limit)
39+
# 2. Convert to lowercase
40+
# 3. Replace non-alphanumeric chars with hyphens
41+
# 4. Remove leading/trailing hyphens
42+
# 5. Collapse multiple hyphens
43+
PREVIEW_BRANCH=$(echo "$BRANCH_NAME" | \
44+
cut -c1-28 | \
45+
tr '[:upper:]' '[:lower:]' | \
46+
sed 's/[^a-z0-9]/-/g' | \
47+
sed 's/^-*//' | \
48+
sed 's/-*$//' | \
49+
sed 's/--*/-/g')
50+
51+
# Cloudflare branch preview URL format
52+
PREVIEW_URL="https://${PREVIEW_BRANCH}.docodile.pages.dev"
53+
54+
echo "Branch name: $BRANCH_NAME"
55+
echo "Preview branch slug: $PREVIEW_BRANCH"
56+
echo "Testing preview URL: $PREVIEW_URL"
57+
58+
# Test if preview URL is accessible (with retries for new PRs)
59+
for i in {1..3}; do
60+
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 "$PREVIEW_URL" || echo "000")
61+
if [[ "$HTTP_CODE" =~ ^(200|301|302|304)$ ]]; then
62+
BASE_URL="$PREVIEW_URL"
63+
echo "✓ Using Cloudflare branch preview URL: $BASE_URL"
64+
break
65+
else
66+
echo "Attempt $i: Preview returned $HTTP_CODE"
67+
if [[ $i -lt 3 ]]; then
68+
echo "Waiting 5 seconds before retry..."
69+
sleep 5
70+
fi
71+
fi
72+
done
73+
74+
if [[ "$BASE_URL" == "https://docs.wandb.ai" ]]; then
75+
echo "⚠️ Cloudflare preview not accessible after retries, using production URL"
76+
fi
77+
else
78+
echo "Running on main branch, using production URL"
79+
fi
80+
81+
echo "base_url=$BASE_URL" >> $GITHUB_OUTPUT
82+
2683
- name: Link Checker
2784
id: lychee
2885
uses: lycheeverse/lychee-action@v2
2986
with:
3087
token: ${{ secrets.GITHUB_TOKEN }}
31-
args: "--accept 200,429,403 --user-agent 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)' --scheme https --scheme http --max-concurrency 5 --max-retries 1 --retry-wait-time 2 --verbose --no-progress --require-https 'content/**/*.md' 'content/**/*.html' 'https://docs.wandb.ai/guides/' 'https://docs.wandb.ai/ref/' 'https://docs.wandb.ai/tutorials/' 'https://docs.wandb.ai/support/'"
88+
args: "--accept 200,429,403 --user-agent 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)' --scheme https --scheme http --max-concurrency 5 --max-retries 1 --retry-wait-time 2 --verbose --no-progress --require-https --base-url '${{ steps.base-url.outputs.base_url }}' 'content/**/*.md' 'content/**/*.html' 'https://docs.wandb.ai/guides/' 'https://docs.wandb.ai/ref/' 'https://docs.wandb.ai/tutorials/' 'https://docs.wandb.ai/support/'"
3289
output: ./lychee/out.json
3390
format: json
3491
fail: false
@@ -132,6 +189,9 @@ jobs:
132189
echo "## Link Check Summary" >> $GITHUB_STEP_SUMMARY
133190
echo "" >> $GITHUB_STEP_SUMMARY
134191
192+
echo "🔗 **Base URL:** ${{ steps.base-url.outputs.base_url }}" >> $GITHUB_STEP_SUMMARY
193+
echo "" >> $GITHUB_STEP_SUMMARY
194+
135195
if [[ "${{ steps.fix.outputs.has_changes }}" == "true" ]]; then
136196
echo "✅ Created PR #${{ steps.cpr.outputs.pull-request-number }} with auto-fixed links" >> $GITHUB_STEP_SUMMARY
137197
elif [[ "${{ steps.fix.outputs.has_report }}" == "true" ]]; then

0 commit comments

Comments
 (0)