Skip to content

Commit 618c494

Browse files
committed
chore: add Context7 refresh workflow
1 parent c3ae8fa commit 618c494

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Refresh Context7 Docs
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- ".github/workflows/context7-refresh.yml"
9+
- "README.md"
10+
- "api.md"
11+
- "context7.json"
12+
- "pyproject.toml"
13+
- "docs/**"
14+
- "examples/**"
15+
workflow_dispatch:
16+
17+
permissions: {}
18+
19+
jobs:
20+
refresh:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Trigger Context7 refresh
24+
env:
25+
CONTEXT7_API_KEY: ${{ secrets.CONTEXT7_API_KEY }}
26+
run: |
27+
set -euo pipefail
28+
29+
if [ -z "$CONTEXT7_API_KEY" ]; then
30+
echo "::warning ::CONTEXT7_API_KEY secret is not configured. Configure it to enable automatic Context7 refreshes."
31+
exit 0
32+
fi
33+
34+
body_file="$(mktemp)"
35+
trap 'rm -f "$body_file"' EXIT
36+
status="$(curl -sS -o "$body_file" -w "%{http_code}" -X POST "https://context7.com/api/v1/refresh" \
37+
-H "Content-Type: application/json" \
38+
-H "Authorization: Bearer ${CONTEXT7_API_KEY}" \
39+
-d '{"libraryName": "/xquik-dev/x-twitter-scraper-python"}')"
40+
41+
case "$status" in
42+
200|202)
43+
cat "$body_file"
44+
;;
45+
400)
46+
if grep -Eiq "active-task|being processed|already.*process" "$body_file"; then
47+
echo "::warning ::Context7 is already processing another library. Retry on the next docs change."
48+
cat "$body_file"
49+
elif grep -Eiq "too-early|minimum .* days|required between updates" "$body_file"; then
50+
echo "::warning ::Context7 refresh is not due yet."
51+
cat "$body_file"
52+
else
53+
echo "::error ::Context7 refresh returned HTTP $status."
54+
cat "$body_file"
55+
exit 1
56+
fi
57+
;;
58+
404)
59+
echo "::warning ::Context7 library /xquik-dev/x-twitter-scraper-python is not available yet. Add processing may still be pending."
60+
cat "$body_file"
61+
;;
62+
401|403)
63+
echo "::error ::Context7 authentication failed."
64+
exit 1
65+
;;
66+
429)
67+
echo "::warning ::Context7 refresh is rate limited. Retry on the next docs change."
68+
;;
69+
*)
70+
echo "::error ::Context7 refresh returned HTTP $status."
71+
cat "$body_file"
72+
exit 1
73+
;;
74+
esac

0 commit comments

Comments
 (0)