|
21 | 21 | # Steps represent a sequence of tasks that will be executed as part of the job |
22 | 22 | steps: |
23 | 23 | # 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 |
27 | 25 |
|
28 | 26 | - name: Set Node.js 22.x |
29 | 27 | uses: actions/setup-node@v3 |
@@ -56,56 +54,45 @@ jobs: |
56 | 54 | cache: "public, max-age:86400" |
57 | 55 | private: true |
58 | 56 |
|
59 | | - - name: Submit changed docs URLs to IndexNow |
| 57 | + - name: Submit docs URLs to IndexNow |
| 58 | + env: |
| 59 | + INDEXNOW_KEY: ${{ secrets.INDEXNOW_KEY }} |
60 | 60 | run: | |
61 | 61 | set -e |
62 | 62 |
|
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" |
68 | 69 | exit 0 |
69 | 70 | fi |
70 | 71 |
|
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) |
92 | 73 |
|
93 | 74 | if [ -z "$URLS" ]; then |
94 | | - echo "No mappable URLs found, skipping" |
| 75 | + echo "No URLs found in sitemap, skipping" |
95 | 76 | exit 0 |
96 | 77 | fi |
97 | 78 |
|
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" |
101 | 81 |
|
| 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}" |
102 | 85 | JSON_URLS=$(echo "$URLS" | jq -R -s 'split("\n") | map(select(length > 0))') |
103 | 86 |
|
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" \ |
105 | 89 | -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}") |
107 | 91 |
|
108 | 92 | echo "IndexNow response: $HTTP_CODE" |
109 | 93 | 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