Repository navigation
109 lines (101 loc) · 5.06 KB
/
Copy pathcontext7.yml
File metadata and controls
109 lines (101 loc) · 5.06 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# Context7 - Keeps https://context7.com/xh/hoist-react current.
#
# Context7 serves hoist-react docs to AI coding tools (Cursor, Claude, etc.) through its MCP server.
# Left alone it re-indexes a library of this size every 45 days at most, and only if someone
# requested it recently, and it never discovers new release tags by itself. Two jobs close that gap:
#
# - refresh: asks Context7 to re-index the library. The main Context7 entry parses master, so this
# job runs on every push to master (a release) and on demand.
# Requires the CONTEXT7_API_KEY repository secret - create a key at https://context7.com/dashboard.
# Without the secret the job logs a warning and exits cleanly.
#
# - sync-versions: daily, rewrites `previousVersions` in context7.json to the newest release tag of
# each recent major and opens a PR when that list changed. The PR targets develop, so the new list
# reaches master (and the main entry) with the next release. The PR is opened with the XH Build Bot
# token so CI runs on it (PRs opened with GITHUB_TOKEN do not trigger workflows).
name: Context7
on:
push:
branches: [master]
schedule:
- cron: '17 6 * * *'
workflow_dispatch:
concurrency:
group: context7-${{ github.event_name }}
cancel-in-progress: false
jobs:
refresh:
if: github.event_name != 'schedule'
runs-on: ubuntu-latest
steps:
- name: Trigger Context7 refresh
env:
CONTEXT7_API_KEY: ${{ secrets.CONTEXT7_API_KEY }}
LIBRARY: /${{ github.repository }}
run: |
if [ -z "$CONTEXT7_API_KEY" ]; then
echo "::warning::CONTEXT7_API_KEY secret is not set - skipping Context7 refresh"
exit 0
fi
response=$(curl -sS -w '\n%{http_code}' -X POST https://context7.com/api/v1/refresh \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer $CONTEXT7_API_KEY" \
-d "{\"libraryName\": \"$LIBRARY\"}")
body=$(printf '%s\n' "$response" | sed '$d')
code=$(printf '%s\n' "$response" | tail -n1)
echo "Context7 responded HTTP $code: $body"
case "$code" in
200) ;;
429) echo "::warning::Context7 rate-limited this refresh (library refreshed recently) - nothing to do" ;;
*) exit 1 ;;
esac
sync-versions:
if: github.event_name != 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
fetch-tags: true
- name: Update previousVersions from release tags
id: sync
run: |
node .github/scripts/context7-versions.mjs
if git diff --quiet -- context7.json; then
echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "changed=true" >> "$GITHUB_OUTPUT"
git diff -- context7.json
fi
# Same org-owned GitHub App used by Deploy Snapshot. Credentials live in the team
# 1Password vault under "GitHub App: XH Build Bot".
- name: Mint XH Build Bot token
if: steps.sync.outputs.changed == 'true'
id: bot-token
uses: actions/create-github-app-token@v3
with:
client-id: ${{ vars.XH_BUILD_BOT_CLIENT_ID }}
private-key: ${{ secrets.XH_BUILD_BOT_PRIVATE_KEY }}
owner: xh
repositories: ${{ github.event.repository.name }}
permission-contents: write
permission-pull-requests: write
- name: Open or update pull request
if: steps.sync.outputs.changed == 'true'
env:
GH_TOKEN: ${{ steps.bot-token.outputs.token }}
BRANCH: context7/sync-versions
run: |
git config user.name 'xh-build-bot[bot]'
git config user.email 'xh-build-bot[bot]@users.noreply.github.com'
git switch -c "$BRANCH"
git commit -am "Update Context7 versions to current release tags"
git push --force "https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository }}.git" "$BRANCH"
open=$(gh pr list --head "$BRANCH" --base develop --state open --json number --jq 'length')
if [ "$open" = "0" ]; then
gh pr create --base develop --head "$BRANCH" \
--title "Update Context7 versions to current release tags" \
--body "Automated: \`previousVersions\` in \`context7.json\` now lists the newest release tag of each recent major. Merging triggers a Context7 refresh."
else
echo "Pull request for $BRANCH already open - branch updated"
fi