Repository navigation
54 lines (51 loc) · 2.51 KB
/
Copy pathcontext7-refresh.yml
File metadata and controls
54 lines (51 loc) · 2.51 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
# Context7 serves this repo's docs to coding agents, and re-indexes on its own
# schedule, which can lag a release by weeks. This asks it to re-index when a
# release is published and once a day. Context7 indexes the default branch, so
# agents may see docs ahead of the last release.
# Context7 takes one refresh per library per 10 days and answers an earlier
# one with HTTP 400 too-early. The daily schedule asks again once the window
# reopens, so a change is usually refreshed within 11 days; GitHub runs
# schedules best-effort, so that is not guaranteed. The schedule also spends
# each window as it opens, so a release rarely refreshes at once.
# Scope and agent rules live in context7.json.
# Endpoint: https://context7.com/docs/integrations/github-actions
name: Context7 Refresh
on:
release:
types: [published]
schedule:
- cron: "23 5 * * *"
workflow_dispatch:
permissions: {}
jobs:
refresh:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Ask Context7 to re-index /cachekit-io/cachekit-py
env:
CONTEXT7_API_KEY: ${{ secrets.CONTEXT7_API_KEY }}
run: |
if [ -z "$CONTEXT7_API_KEY" ]; then
echo "::error::The CONTEXT7_API_KEY secret is not available to this repository."
exit 1
fi
status=$(curl -sS --max-time 60 -o "$RUNNER_TEMP/context7-response.json" -w '%{http_code}' \
-X POST https://context7.com/api/v1/refresh \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $CONTEXT7_API_KEY" \
--data '{"libraryName": "/cachekit-io/cachekit-py"}')
cat "$RUNNER_TEMP/context7-response.json"
echo
# Patterns keep their opening paren: ci.yml's runner drift guard reads a
# line that starts with `*` as a YAML alias and fails the build.
case "$status" in
(202) echo "::warning::Context7 has not finalized this library yet (HTTP 202). Re-run this workflow later." ;;
(2??) echo "Context7 accepted the refresh (HTTP $status)." ;;
(400) if jq -e '.error == "too-early"' "$RUNNER_TEMP/context7-response.json" >/dev/null 2>&1; then
echo "::warning::Context7 refreshed this library less than 10 days ago (HTTP 400 too-early). The daily schedule asks again."
else
echo "::error::Context7 refresh failed with HTTP 400."; exit 1
fi ;;
(*) echo "::error::Context7 refresh failed with HTTP $status."; exit 1 ;;
esac