-
-
Notifications
You must be signed in to change notification settings - Fork 290
155 lines (133 loc) · 6.74 KB
/
main.yml
File metadata and controls
155 lines (133 loc) · 6.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
- name: Set Node.js 22.x
uses: actions/setup-node@v3
with:
node-version: 22.x
- uses: borales/actions-yarn@v4
with:
cmd: install # will run `yarn install` command
- uses: borales/actions-yarn@v4
with:
cmd: build # will run `yarn build` command
# create a build/docs folder and move all content from build there
- name: Add docs subfolder
run: |
mv ./build build-old
mkdir -p build/docs
mv build-old/* build/docs
- name: Deploy
uses: reggionick/s3-deploy@v3
with:
folder: build
bucket: ${{ secrets.S3_BUCKET }}
bucket-region: ${{ secrets.S3_BUCKET_REGION }}
dist-id: ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }}
invalidation: /docs*
delete-removed: true
cache: "public, max-age:86400"
private: true
- name: Submit docs URLs to IndexNow
env:
INDEXNOW_HOST: keploy.io
# The default key is the one served from keploy.io/<key>.txt by the
# landing repo; override via a repo secret only if rotating.
INDEXNOW_KEY: ${{ secrets.INDEXNOW_KEY || 'feeeddbe661a4686ba6e4d5cb663b2cb' }}
continue-on-error: true
run: |
set -euo pipefail
INDEXNOW_KEY_LOC="https://${INDEXNOW_HOST}/${INDEXNOW_KEY}.txt"
# Unique temp file for the IndexNow response body; cleaned up on
# every exit path via trap so stale data can't leak into future
# reads and repeat runs of this step don't collide.
RESPONSE_FILE=$(mktemp)
trap 'rm -f "$RESPONSE_FILE"' EXIT
# Use the just-built sitemap so URLs are guaranteed to exist on the
# deployed site (the previous S3 sync step pushed it up moments ago).
SITEMAP="build/docs/sitemap.xml"
if [ ! -f "$SITEMAP" ]; then
echo "::notice::Sitemap not found at $SITEMAP, skipping IndexNow submission"
exit 0
fi
# Filter the sitemap URL list:
# - drop auto-generated /tags/ pages (low-value for search indexing)
# - drop any versioned doc path like /docs/N.M.P/ so only the
# current (unversioned) docs are submitted. Matching any numeric
# major-minor-patch prefix keeps the rule correct when a future
# v5/v6 archive lands alongside today's v1-v3 legacy versions.
#
# `|| true` makes the pipeline non-fatal under `set -euo pipefail`:
# if every URL happens to be filtered out, grep returns 1, which
# would otherwise abort the step before the empty-result check below.
URLS=$(grep -oP '<loc>\K[^<]+' "$SITEMAP" \
| grep -v '/tags/' \
| grep -vE '/docs/[0-9]+\.[0-9]+\.[0-9]+/' \
| sort -u || true)
if [ -z "$URLS" ]; then
echo "::notice::No current-version docs URLs parsed from $SITEMAP, skipping"
exit 0
fi
URL_COUNT=$(printf '%s\n' "$URLS" | wc -l | tr -d '[:space:]')
echo "Submitting $URL_COUNT docs URLs to IndexNow"
# Log a small sample so jq/curl failures below have enough context
# to debug from the log alone (otherwise the only artifact is a
# count, and the operator can't tell which URL broke the payload).
echo "First 5 URLs:"
printf '%s\n' "$URLS" | head -5 | sed 's/^/ /'
# Explicit jq availability + payload-build checks: under
# `set -euo pipefail` a missing/failing jq would abort the step
# before the error/troubleshooting branches below could run,
# leaving an unannotated "process exited 1" in the Actions UI.
if ! command -v jq >/dev/null 2>&1; then
echo "::error::jq is required to build the IndexNow request payload. Install jq or use a runner image that includes it, then rerun this workflow."
exit 1
fi
if ! JSON_URLS=$(printf '%s\n' "$URLS" | jq -R -s 'split("\n") | map(select(length > 0))'); then
echo "::error::Failed to build the IndexNow JSON payload from the sitemap URL list. See the 'First 5 URLs' sample logged above for unexpected characters, then rerun the workflow."
exit 1
fi
# Capture curl exit status separately from HTTP code so network/DNS
# failures are distinguishable from real non-2xx responses.
CURL_EXIT=0
HTTP_CODE=$(curl -sS -o "$RESPONSE_FILE" -w "%{http_code}" \
-X POST "https://api.indexnow.org/indexnow" \
-H "Content-Type: application/json" \
-d "{\"host\":\"${INDEXNOW_HOST}\",\"key\":\"${INDEXNOW_KEY}\",\"keyLocation\":\"${INDEXNOW_KEY_LOC}\",\"urlList\":${JSON_URLS}}") || CURL_EXIT=$?
if [ "$CURL_EXIT" -ne 0 ]; then
echo "::error::IndexNow request failed to execute (curl exit $CURL_EXIT)."
echo " Check connectivity: curl -I https://api.indexnow.org/"
exit 1
fi
# IndexNow returns 200 for processed and 202 for accepted-pending-
# verification; both are success per the spec.
if [ "$HTTP_CODE" -ge 200 ] && [ "$HTTP_CODE" -lt 300 ]; then
echo "Submitted $URL_COUNT URLs to IndexNow (HTTP $HTTP_CODE)"
exit 0
fi
echo "::error::IndexNow returned HTTP $HTTP_CODE. Response body:"
cat "$RESPONSE_FILE" 2>/dev/null || true
echo ""
echo "Troubleshooting:"
echo " 1. Verify key file is publicly reachable: curl -sS \"$INDEXNOW_KEY_LOC\""
echo " 2. Reproduce request:"
echo " curl -sS -X POST \"https://api.indexnow.org/indexnow\" -H 'Content-Type: application/json' \\"
echo " -d '{\"host\":\"${INDEXNOW_HOST}\",\"key\":\"${INDEXNOW_KEY}\",\"keyLocation\":\"${INDEXNOW_KEY_LOC}\",\"urlList\":[\"https://${INDEXNOW_HOST}/docs/\"]}'"
exit 1