|
| 1 | +name: IndexNow ping |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["pages-build-deployment"] |
| 6 | + types: [completed] |
| 7 | + branches: [main] |
| 8 | + |
| 9 | + # Manual trigger from the Actions tab |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + |
| 15 | +jobs: |
| 16 | + ping: |
| 17 | + if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }} |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - name: Fetch sitemap and extract URLs |
| 21 | + id: sitemap |
| 22 | + run: | |
| 23 | + set -euo pipefail |
| 24 | + curl -sSL --fail https://github-store.org/sitemap.xml -o /tmp/sitemap.xml |
| 25 | + # Extract <loc> values, drop XML tags, dedupe |
| 26 | + grep -oE '<loc>[^<]+' /tmp/sitemap.xml | sed 's|<loc>||' | sort -u > /tmp/urls.txt |
| 27 | + echo "url_count=$(wc -l < /tmp/urls.txt)" >> "$GITHUB_OUTPUT" |
| 28 | + echo "Found $(wc -l < /tmp/urls.txt) URLs in sitemap" |
| 29 | + head -20 /tmp/urls.txt |
| 30 | +
|
| 31 | + - name: Build IndexNow payload |
| 32 | + id: payload |
| 33 | + run: | |
| 34 | + set -euo pipefail |
| 35 | + # Cap at 10000 URLs per IndexNow spec |
| 36 | + head -10000 /tmp/urls.txt > /tmp/capped.txt |
| 37 | + # Build JSON urlList array |
| 38 | + python3 - <<'PY' |
| 39 | + import json |
| 40 | + urls = [line.strip() for line in open('/tmp/capped.txt') if line.strip()] |
| 41 | + payload = { |
| 42 | + "host": "github-store.org", |
| 43 | + "key": "f4cd4cc41b59e8c28b7290262164e680", |
| 44 | + "keyLocation": "https://github-store.org/f4cd4cc41b59e8c28b7290262164e680.txt", |
| 45 | + "urlList": urls, |
| 46 | + } |
| 47 | + with open('/tmp/payload.json', 'w') as f: |
| 48 | + json.dump(payload, f) |
| 49 | + print(f"Built payload with {len(urls)} URLs") |
| 50 | + PY |
| 51 | +
|
| 52 | + - name: Submit to IndexNow |
| 53 | + run: | |
| 54 | + set -euo pipefail |
| 55 | + status=$(curl -sS -o /tmp/response.txt -w "%{http_code}" \ |
| 56 | + -X POST "https://api.indexnow.org/IndexNow" \ |
| 57 | + -H "Content-Type: application/json; charset=utf-8" \ |
| 58 | + --data-binary @/tmp/payload.json) |
| 59 | + echo "IndexNow returned HTTP $status" |
| 60 | + cat /tmp/response.txt |
| 61 | + # 200/202 = accepted. 422 = invalid (key/host mismatch). Anything else fails. |
| 62 | + if [ "$status" != "200" ] && [ "$status" != "202" ]; then |
| 63 | + echo "::error::IndexNow rejected the payload (HTTP $status)" |
| 64 | + exit 1 |
| 65 | + fi |
0 commit comments