Skip to content

Commit 74e2385

Browse files
nehagupclaude
andcommitted
fix: address all 9 Copilot review comments on IndexNow step
- Upgrade actions/checkout@v2 → v4 (comment 1) - Use built sitemap instead of git diff file mapping (comments 2-6) Avoids unreliable path→URL mapping due to frontmatter id/slug, versioned doc prefixes, and index page edge cases - Move IndexNow key to secret with hardcoded fallback (comments 7-8) - Replace ::warning:: with descriptive log + response body (comment 9) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Neha Gupta <gneha21@yahoo.in>
1 parent 5656f33 commit 74e2385

1 file changed

Lines changed: 25 additions & 38 deletions

File tree

.github/workflows/main.yml

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ jobs:
2121
# Steps represent a sequence of tasks that will be executed as part of the job
2222
steps:
2323
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
24-
- uses: actions/checkout@v2
25-
with:
26-
fetch-depth: 2
24+
- uses: actions/checkout@v4
2725

2826
- name: Set Node.js 22.x
2927
uses: actions/setup-node@v3
@@ -56,56 +54,45 @@ jobs:
5654
cache: "public, max-age:86400"
5755
private: true
5856

59-
- name: Submit changed docs URLs to IndexNow
57+
- name: Submit docs URLs to IndexNow
58+
env:
59+
INDEXNOW_KEY: ${{ secrets.INDEXNOW_KEY }}
6060
run: |
6161
set -e
6262
63-
# Get markdown files changed in this push
64-
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD -- '*.md' '*.mdx' || true)
65-
66-
if [ -z "$CHANGED_FILES" ]; then
67-
echo "No docs content changed, skipping IndexNow"
63+
# Use the built sitemap as the source of truth for URLs.
64+
# This avoids unreliable file-path-to-URL mapping (frontmatter id/slug
65+
# overrides, versioned doc prefixes, index pages).
66+
SITEMAP="build/docs/sitemap.xml"
67+
if [ ! -f "$SITEMAP" ]; then
68+
echo "Sitemap not found at $SITEMAP, skipping IndexNow"
6869
exit 0
6970
fi
7071
71-
# Map changed file paths to live URLs
72-
URLS=""
73-
while IFS= read -r file; do
74-
slug=""
75-
if [[ "$file" == versioned_docs/version-4.0.0/* ]]; then
76-
slug="${file#versioned_docs/version-4.0.0/}"
77-
elif [[ "$file" == docs/* ]]; then
78-
slug="${file#docs/}"
79-
else
80-
continue
81-
fi
82-
slug="${slug%.md}"
83-
slug="${slug%.mdx}"
84-
slug="${slug%/index}"
85-
if [ -n "$slug" ]; then
86-
URLS="${URLS}https://keploy.io/docs/${slug}/
87-
"
88-
fi
89-
done <<< "$CHANGED_FILES"
90-
91-
URLS=$(echo "$URLS" | sort -u | head -100)
72+
URLS=$(grep -oP '<loc>\K[^<]+' "$SITEMAP" | head -100)
9273
9374
if [ -z "$URLS" ]; then
94-
echo "No mappable URLs found, skipping"
75+
echo "No URLs found in sitemap, skipping"
9576
exit 0
9677
fi
9778
98-
URL_COUNT=$(echo "$URLS" | grep -c .)
99-
echo "Submitting $URL_COUNT changed docs URLs to IndexNow"
100-
echo "$URLS"
79+
URL_COUNT=$(echo "$URLS" | wc -l)
80+
echo "Submitting $URL_COUNT docs URLs to IndexNow"
10181
82+
# IndexNow key is public by design (hosted at keploy.io/{key}.txt),
83+
# but stored as a secret for easy rotation.
84+
KEY="${INDEXNOW_KEY:-9ded60b43b8b40578588fc42b04c3e5d}"
10285
JSON_URLS=$(echo "$URLS" | jq -R -s 'split("\n") | map(select(length > 0))')
10386
104-
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X POST "https://api.indexnow.org/indexnow" \
87+
RESPONSE_FILE=$(mktemp)
88+
HTTP_CODE=$(curl -s -o "$RESPONSE_FILE" -w "%{http_code}" -X POST "https://api.indexnow.org/indexnow" \
10589
-H "Content-Type: application/json" \
106-
-d "{\"host\":\"keploy.io\",\"key\":\"9ded60b43b8b40578588fc42b04c3e5d\",\"urlList\":$JSON_URLS}")
90+
-d "{\"host\":\"keploy.io\",\"key\":\"$KEY\",\"urlList\":$JSON_URLS}")
10791
10892
echo "IndexNow response: $HTTP_CODE"
10993
if [ "$HTTP_CODE" -ge 400 ]; then
110-
echo "::warning::IndexNow submission returned HTTP $HTTP_CODE"
111-
fi
94+
echo "IndexNow submission returned HTTP $HTTP_CODE — will not block deployment."
95+
echo "Verify the key file is hosted at https://keploy.io/${KEY}.txt"
96+
cat "$RESPONSE_FILE"
97+
fi
98+
rm -f "$RESPONSE_FILE"

0 commit comments

Comments
 (0)