Skip to content

Commit 4759daa

Browse files
authored
Merge pull request #27 from 19-84/guard-registry-fetches
Keep the nightly update running when one registry breaks
2 parents caae305 + c1fa890 commit 4759daa

1 file changed

Lines changed: 40 additions & 27 deletions

File tree

‎.github/workflows/update-instances.yml‎

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,22 @@ jobs:
6767
# upstream registry of their own (or theirs has died, as Tent's did),
6868
# so this is their instance source. Fetched once and reused.
6969
# libredirect_update <farside type> <libredirect key>
70+
# A registry that is down or starts serving HTML (an error page, a
71+
# bot wall) makes its jq exit non-zero, and under `bash -e` that
72+
# aborted the whole run -- so one dead registry blocked every other
73+
# service's update and the prune. Each fetch below ends in
74+
# `|| registry_failed <name> <file>`: warn, write an empty list, and
75+
# let apply_update keep that service's existing instances.
76+
function registry_failed() {
77+
echo "::warning::$1: registry fetch failed or returned invalid JSON; keeping existing instances"
78+
echo '[]' > "$2"
79+
}
80+
7081
function libredirect_update() {
7182
local type="$1" key="$2"
7283
73-
jq --arg k "$key" '[.[$k].clearnet[]] | sort' libredirect.json \
74-
> "$type-tmp.json"
84+
jq --arg k "$key" '[.[$k].clearnet[]?] | sort' libredirect.json \
85+
> "$type-tmp.json" || registry_failed "$type (libredirect)" "$type-tmp.json"
7586
7687
jq --slurpfile new "$type-tmp.json" --arg t "$type" \
7788
'(.[] | select(.type == $t)).instances |= $new[0]' \
@@ -80,8 +91,9 @@ jobs:
8091
apply_update
8192
}
8293
83-
curl -s https://raw.githubusercontent.com/libredirect/instances/main/data.json \
84-
> libredirect.json
94+
curl -sf --max-time 60 https://raw.githubusercontent.com/libredirect/instances/main/data.json \
95+
> libredirect.json || true
96+
jq -e 'type == "object"' libredirect.json >/dev/null 2>&1 || echo '{}' > libredirect.json
8597
8698
# ==============================================================
8799
# Git config
@@ -112,7 +124,7 @@ jobs:
112124
# ==============================================================
113125
# SearXNG update
114126
# ==============================================================
115-
curl -s https://searx.space/data/instances.json | \
127+
curl -sf --max-time 60 https://searx.space/data/instances.json | \
116128
jq '[
117129
.instances |
118130
to_entries[] |
@@ -130,7 +142,7 @@ jobs:
130142
select(.value.html.grade == "V" or .value.html.grade == "F") |
131143
select(.key | contains(".i2p") | not) |
132144
.key
133-
] | sort' > searxng-tmp.json
145+
] | sort' > searxng-tmp.json || registry_failed searxng searxng-tmp.json
134146
135147
cat searxng-tmp.json | jq .
136148
@@ -151,12 +163,12 @@ jobs:
151163
# instances -- drop those; dead entries are left to prune.py.
152164
# Either source may fail on its own without emptying the list.
153165
# ==============================================================
154-
curl -sf https://status.d420.de/api/v1/instances | \
166+
curl -sf --max-time 60 https://status.d420.de/api/v1/instances | \
155167
jq '[.hosts | to_entries[] | select(.value.healthy == true) | .value.url]' \
156-
> nitter-d420.json || echo '[]' > nitter-d420.json
157-
curl -sf https://codeberg.org/mv12star/shitter/raw/branch/master/instances.json | \
168+
> nitter-d420.json || registry_failed "nitter (d420)" nitter-d420.json
169+
curl -sf --max-time 60 https://codeberg.org/mv12star/shitter/raw/branch/master/instances.json | \
158170
jq '[.[] | .url | select(type == "string")]' \
159-
> nitter-shitter.json || echo '[]' > nitter-shitter.json
171+
> nitter-shitter.json || registry_failed "nitter (shitter)" nitter-shitter.json
160172
161173
jq -s '[.[][] | rtrimstr("/")] - ["https://twiiit.com", "https://twit.0r.cx"] | unique' \
162174
nitter-d420.json nitter-shitter.json > nitter-tmp.json
@@ -171,9 +183,9 @@ jobs:
171183
# ==============================================================
172184
# SimplyTranslate update
173185
# ==============================================================
174-
curl -s https://codeberg.org/SimpleWeb/Website/raw/branch/master/config.json | jq -r '.projects | map(select(.id == "simplytranslate"))[0].instances | .[]' > st-out
186+
curl -sf --max-time 60 https://codeberg.org/SimpleWeb/Website/raw/branch/master/config.json | jq -r '.projects | map(select(.id == "simplytranslate"))[0].instances | .[]' > st-out || : > st-out
175187
sed -i -e 's/^/https:\/\//' st-out
176-
jq -ncR '[inputs]' <<< "$(cat st-out | sort)" > st-tmp.json
188+
jq -ncR '[inputs | select(length > 0)]' <<< "$(sort st-out)" > st-tmp.json
177189
178190
jq --slurpfile simplytranslate st-tmp.json \
179191
'( .[] | select(.type == "simplytranslate") )
@@ -184,12 +196,12 @@ jobs:
184196
# ==============================================================
185197
# Invidious update
186198
# ==============================================================
187-
curl -s https://api.invidious.io/instances.json | \
199+
curl -sf --max-time 60 https://api.invidious.io/instances.json | \
188200
jq '[
189201
.[] |
190202
select(.[1].type | contains("https")) ] |
191203
[.[][1].uri] |
192-
sort' > invidious-tmp.json
204+
sort' > invidious-tmp.json || registry_failed invidious invidious-tmp.json
193205
jq --slurpfile invidious invidious-tmp.json \
194206
'( .[] | select(.type == "invidious") )
195207
.instances |= $invidious[0]' services-full.json > services-tmp.json
@@ -199,7 +211,8 @@ jobs:
199211
# ==============================================================
200212
# Scribe update
201213
# ==============================================================
202-
curl -s https://git.sr.ht/~edwardloveall/scribe/blob/main/docs/instances.json > scribe-tmp.json
214+
curl -sf --max-time 60 https://git.sr.ht/~edwardloveall/scribe/blob/main/docs/instances.json > scribe-tmp.json || true
215+
jq -e 'type == "array"' scribe-tmp.json >/dev/null 2>&1 || registry_failed scribe scribe-tmp.json
203216
jq --slurpfile scribe scribe-tmp.json \
204217
'( .[] | select(.type == "scribe") )
205218
.instances |= $scribe[0]' services-full.json > services-tmp.json
@@ -225,12 +238,12 @@ jobs:
225238
# ==============================================================
226239
# libreddit + redlib update
227240
# ==============================================================
228-
curl -s https://raw.githubusercontent.com/redlib-org/redlib-instances/main/instances.json | \
241+
curl -sf --max-time 60 https://raw.githubusercontent.com/redlib-org/redlib-instances/main/instances.json | \
229242
jq '[
230243
.instances[] |
231244
select(.url) |
232245
.url ] |
233-
sort' > libreddit-tmp.json
246+
sort' > libreddit-tmp.json || registry_failed libreddit libreddit-tmp.json
234247
235248
jq --slurpfile libreddit libreddit-tmp.json \
236249
'( .[] | select(.type == "libreddit") )
@@ -247,8 +260,8 @@ jobs:
247260
# ==============================================================
248261
# BreezeWiki update
249262
# ==============================================================
250-
curl -s https://docs.breezewiki.com/files/instances.json | \
251-
jq '[.[] | .instance]' > breezewiki-tmp.json
263+
curl -sf --max-time 60 https://docs.breezewiki.com/files/instances.json | \
264+
jq '[.[] | .instance]' > breezewiki-tmp.json || registry_failed breezewiki breezewiki-tmp.json
252265
jq --slurpfile breezewiki breezewiki-tmp.json \
253266
'(.[] | select(.type == "breezewiki") )
254267
.instances |= $breezewiki[0]' services-full.json > services-tmp.json
@@ -259,8 +272,8 @@ jobs:
259272
# GotHub update
260273
# ==============================================================
261274
262-
curl -s https://codeberg.org/gothub/gothub-instances/raw/branch/master/instances.json | \
263-
jq '[.[] | .link]' > gothub-tmp.json
275+
curl -sf --max-time 60 https://codeberg.org/gothub/gothub-instances/raw/branch/master/instances.json | \
276+
jq '[.[] | .link]' > gothub-tmp.json || registry_failed gothub gothub-tmp.json
264277
jq --slurpfile gothub gothub-tmp.json \
265278
'(.[] | select(.type == "gothub") )
266279
.instances |= $gothub[0]' services-full.json > services-tmp.json
@@ -270,12 +283,12 @@ jobs:
270283
# ==============================================================
271284
# LibreX/LibreY update
272285
# ==============================================================
273-
curl -s https://raw.githubusercontent.com/Ahwxorg/LibreY/main/instances.json | \
286+
curl -sf --max-time 60 https://raw.githubusercontent.com/Ahwxorg/LibreY/main/instances.json | \
274287
jq '[
275288
.instances |
276289
.[] |
277290
.clearnet] |
278-
sort' > librey-tmp.json
291+
sort' > librey-tmp.json || registry_failed librey librey-tmp.json
279292
280293
jq --slurpfile librey librey-tmp.json \
281294
'( .[] | select(.type == "librey") )
@@ -287,11 +300,11 @@ jobs:
287300
# Rimgo update
288301
# ==============================================================
289302
290-
curl -s https://rimgo.codeberg.page/api.json | \
303+
curl -sf --max-time 60 https://rimgo.codeberg.page/api.json | \
291304
jq '[
292305
.clearnet[] |
293306
.url] |
294-
sort' > rimgo-tmp.json
307+
sort' > rimgo-tmp.json || registry_failed rimgo rimgo-tmp.json
295308
296309
jq --slurpfile rimgo rimgo-tmp.json \
297310
'(.[] | select(.type == "rimgo") )
@@ -312,8 +325,8 @@ jobs:
312325
# Mozhi update (translate frontend; clean JSON registry)
313326
# Tor/I2P-only entries have no "link" key -> skip them
314327
# ==============================================================
315-
curl -s https://codeberg.org/aryak/mozhi/raw/branch/master/instances.json | \
316-
jq '[.[] | .link // empty]' > mozhi-tmp.json
328+
curl -sf --max-time 60 https://codeberg.org/aryak/mozhi/raw/branch/master/instances.json | \
329+
jq '[.[] | .link // empty]' > mozhi-tmp.json || registry_failed mozhi mozhi-tmp.json
317330
jq --slurpfile mozhi mozhi-tmp.json \
318331
'( .[] | select(.type == "mozhi") )
319332
.instances |= $mozhi[0]' services-full.json > services-tmp.json

0 commit comments

Comments
 (0)