mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-10-29 20:05:25 +08:00
ci(docs): verify Context7 registration on isolated branch
Co-authored-by: multica-agent <[email protected]>
This commit is contained in:
co-authored by
multica-agent
parent
407352cc51
commit
cb2fd12633
@@ -0,0 +1,89 @@
|
||||
name: Verify Context7 migration
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [agent/hk-dev-codex/lang-168-context7]
|
||||
paths: [.github/workflows/context7-registration-check.yml]
|
||||
|
||||
permissions: {}
|
||||
|
||||
jobs:
|
||||
verify:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 5
|
||||
steps:
|
||||
- name: Register public repository and check retrieval
|
||||
env:
|
||||
CONTEXT7_API_KEY: ${{ secrets.CONTEXT7_API_KEY }}
|
||||
shell: python
|
||||
run: |
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import urllib.error
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
|
||||
key = os.environ.get('CONTEXT7_API_KEY', '')
|
||||
if not key:
|
||||
raise SystemExit('CONTEXT7_API_KEY is missing')
|
||||
library = '/langbot-app/langbot'
|
||||
report = []
|
||||
|
||||
def request(path, body=None):
|
||||
data = None if body is None else json.dumps(body).encode()
|
||||
req = urllib.request.Request(
|
||||
'https://context7.com/api' + path, data=data,
|
||||
headers={'Authorization': 'Bearer ' + key,
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json'})
|
||||
try:
|
||||
with urllib.request.urlopen(req, timeout=90) as response:
|
||||
status, raw = response.status, response.read()
|
||||
except urllib.error.HTTPError as error:
|
||||
status, raw = error.code, error.read()
|
||||
try:
|
||||
result = json.loads(raw)
|
||||
except (ValueError, UnicodeError):
|
||||
result = {}
|
||||
if not isinstance(result, dict):
|
||||
result = {}
|
||||
return status, result
|
||||
|
||||
status, result = request('/v2/add/repo/github', {
|
||||
'docsRepoUrl': 'https://github.com/langbot-app/LangBot',
|
||||
'private': False})
|
||||
report.append('Registration HTTP status: ' + str(status))
|
||||
registered = result.get('libraryName')
|
||||
if isinstance(registered, str) and registered.lower() == library:
|
||||
report.append('Registered library: ' + library)
|
||||
|
||||
query = urllib.parse.urlencode({
|
||||
'libraryId': library,
|
||||
'query': 'LangBot plugin development event handlers',
|
||||
'type': 'json'})
|
||||
retrieval_status, context = request('/v2/context?' + query)
|
||||
report.append('Retrieval HTTP status: ' + str(retrieval_status))
|
||||
sources = []
|
||||
for field, url_field in [('codeSnippets', 'codeId'), ('infoSnippets', 'pageId')]:
|
||||
snippets = context.get(field, [])
|
||||
if not isinstance(snippets, list):
|
||||
continue
|
||||
report.append(field + ': ' + str(len(snippets)))
|
||||
for snippet in snippets:
|
||||
url = snippet.get(url_field, '') if isinstance(snippet, dict) else ''
|
||||
if isinstance(url, str) and re.fullmatch(
|
||||
r'https://github\.com/langbot-app/[Ll]ang[Bb]ot/blob/[A-Za-z0-9_./#%=-]+', url):
|
||||
sources.append(url)
|
||||
report.extend(sorted(set(sources)))
|
||||
if retrieval_status == 202:
|
||||
report.append('Indexing is pending; retrieval is not yet verified.')
|
||||
report.append('docs/en filtering requires the root config in PR #2783 to be merged and refreshed.')
|
||||
summary = '\n'.join(report) + '\n'
|
||||
print(summary)
|
||||
with open(os.environ['GITHUB_STEP_SUMMARY'], 'a') as output:
|
||||
output.write(summary)
|
||||
if status not in (200, 202, 409):
|
||||
raise SystemExit('Repository registration did not succeed; see HTTP status above.')
|
||||
if retrieval_status != 200 or not sources:
|
||||
raise SystemExit('Main-repository retrieval is not yet verified.')
|
||||
Reference in New Issue
Block a user