-
Notifications
You must be signed in to change notification settings - Fork 51
147 lines (127 loc) · 4.59 KB
/
algolia-reindex.yml
File metadata and controls
147 lines (127 loc) · 4.59 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
name: Algolia Reindex
on:
push:
branches:
- main
paths:
- docs/**
- i18n/**
- src/**
- static/**
- docusaurus.config.ts
- sidebars.js
- sidebar-semver-sort.js
workflow_dispatch:
workflow_call:
secrets:
ALGOLIA_CRAWLER_USER_ID:
required: true
ALGOLIA_CRAWLER_API_KEY:
required: true
concurrency:
group: algolia-reindex
cancel-in-progress: false
jobs:
algolia-reindex:
name: Reindex Algolia Search
runs-on: ubuntu-latest
env:
ALGOLIA_APP_ID: ${{ vars.ALGOLIA_APP_ID || 'JUYLFQHE7W' }}
ALGOLIA_CRAWLER_NAME: ${{ vars.ALGOLIA_CRAWLER_NAME || 'unraid' }}
ALGOLIA_REINDEX_DELAY_SECONDS: ${{ vars.ALGOLIA_REINDEX_DELAY_SECONDS || '300' }}
steps:
- name: Wait for docs deployment to propagate
if: github.event_name == 'push'
run: |
set -euo pipefail
echo "Waiting ${ALGOLIA_REINDEX_DELAY_SECONDS}s before reindexing ${ALGOLIA_CRAWLER_NAME}."
sleep "${ALGOLIA_REINDEX_DELAY_SECONDS}"
- name: Resolve crawler id
id: resolve
env:
ALGOLIA_CRAWLER_USER_ID: ${{ secrets.ALGOLIA_CRAWLER_USER_ID }}
ALGOLIA_CRAWLER_API_KEY: ${{ secrets.ALGOLIA_CRAWLER_API_KEY }}
run: |
set -euo pipefail
response="$(
curl --silent --show-error --fail \
--user "${ALGOLIA_CRAWLER_USER_ID}:${ALGOLIA_CRAWLER_API_KEY}" \
"https://crawler.algolia.com/api/1/crawlers?name=${ALGOLIA_CRAWLER_NAME}&itemsPerPage=100"
)"
crawler_id="$(
jq -er \
'.items[0].id' \
<<<"${response}"
)"
details="$(
curl --silent --show-error --fail \
--user "${ALGOLIA_CRAWLER_USER_ID}:${ALGOLIA_CRAWLER_API_KEY}" \
"https://crawler.algolia.com/api/1/crawlers/${crawler_id}"
)"
crawler_status="$(
jq -er \
'if .blocked then "blocked"
elif .reindexing then "reindexing"
elif .running then "running"
else "paused"
end' \
<<<"${details}"
)"
echo "crawler_id=${crawler_id}" >> "${GITHUB_OUTPUT}"
echo "crawler_status=${crawler_status}" >> "${GITHUB_OUTPUT}"
echo "Resolved crawler ${ALGOLIA_CRAWLER_NAME} (${crawler_id}) with current status ${crawler_status}."
- name: Trigger crawler reindex
id: reindex
env:
ALGOLIA_CRAWLER_USER_ID: ${{ secrets.ALGOLIA_CRAWLER_USER_ID }}
ALGOLIA_CRAWLER_API_KEY: ${{ secrets.ALGOLIA_CRAWLER_API_KEY }}
run: |
set -euo pipefail
response="$(
curl --silent --show-error --fail \
--user "${ALGOLIA_CRAWLER_USER_ID}:${ALGOLIA_CRAWLER_API_KEY}" \
--request POST \
--header "content-type: application/json" \
"https://crawler.algolia.com/api/1/crawlers/${{ steps.resolve.outputs.crawler_id }}/reindex"
)"
task_id="$(
jq -er \
'.taskId' \
<<<"${response}"
)"
echo "task_id=${task_id}" >> "${GITHUB_OUTPUT}"
echo "Queued Algolia reindex task ${task_id} for crawler ${ALGOLIA_CRAWLER_NAME}."
- name: Confirm crawler entered reindexing state
env:
ALGOLIA_CRAWLER_USER_ID: ${{ secrets.ALGOLIA_CRAWLER_USER_ID }}
ALGOLIA_CRAWLER_API_KEY: ${{ secrets.ALGOLIA_CRAWLER_API_KEY }}
run: |
set -euo pipefail
for attempt in 1 2 3 4 5; do
response="$(
curl --silent --show-error --fail \
--user "${ALGOLIA_CRAWLER_USER_ID}:${ALGOLIA_CRAWLER_API_KEY}" \
"https://crawler.algolia.com/api/1/crawlers/${{ steps.resolve.outputs.crawler_id }}"
)"
reindexing="$(
jq -er \
'.reindexing' \
<<<"${response}"
)"
if [ "${reindexing}" = "true" ]; then
status="$(
jq -er \
'if .blocked then "blocked"
elif .reindexing then "reindexing"
elif .running then "running"
else "paused"
end' \
<<<"${response}"
)"
echo "Crawler ${ALGOLIA_CRAWLER_NAME} is now ${status}."
exit 0
fi
sleep 5
done
echo "Crawler ${ALGOLIA_CRAWLER_NAME} did not report reindexing=true after the reindex request." >&2
exit 1