Files
LangBot/.github/workflows/context7-registration-check.yml
T

85 lines
3.5 KiB
YAML

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: Check indexed documentation 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
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))
for field in ('error', 'message'):
detail = context.get(field)
if isinstance(detail, str):
report.append('Retrieval ' + field + ': ' +
json.dumps(detail.replace(key, '[REDACTED]')[:500]))
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 retrieval_status != 200 or not any('/blob/master/docs/en/' in url for url in sources):
raise SystemExit('Main-repository retrieval is not yet verified.')