-
Notifications
You must be signed in to change notification settings - Fork 0
136 lines (117 loc) · 4.5 KB
/
Copy pathcontext7-ops.yml
File metadata and controls
136 lines (117 loc) · 4.5 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
---
name: Context7 Ops
# Reusable workflow to synchronize a repository with Context7 (https://context7.com).
# It uses the Context7 Refresh API to trigger a refresh of the library documentation.
on:
workflow_call:
inputs:
library_name:
description: "Context7 Library name (e.g. /owner/repo). Defaults to /github.repository."
required: false
type: string
default: ""
branch:
description: "Branch to refresh. Defaults to current branch."
required: false
type: string
default: ""
secrets:
context7_api_key:
description: "Context7 API Key (ctx7sk...)"
required: true
permissions:
contents: read
jobs:
config:
name: Resolve Config
runs-on: ubuntu-24.04
outputs:
library_name: ${{ steps.params.outputs.library_name }}
branch: ${{ steps.params.outputs.branch }}
steps:
- name: Resolve Parameters
id: params
shell: bash
env:
LIBRARY_NAME_INPUT: ${{ inputs.library_name }}
BRANCH_INPUT: ${{ inputs.branch }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_REF_NAME: ${{ github.ref_name }}
run: |
echo "Resolving Context7 sync parameters..."
lib_name="${LIBRARY_NAME_INPUT}"
if [[ -z "${lib_name}" ]]; then
lib_name="/${GITHUB_REPOSITORY}"
echo "library_name empty; defaulting to '/${GITHUB_REPOSITORY}'"
fi
# Ensure library name starts with /
if [[ ! "${lib_name}" =~ ^/ ]]; then
lib_name="/${lib_name}"
echo "Prepending '/' to library_name: ${lib_name}"
fi
branch="${BRANCH_INPUT}"
# We don't default to GITHUB_REF_NAME here to allow Context7
# to use its default branch logic if no branch is specified.
echo "library_name=${lib_name}" >> "${GITHUB_OUTPUT}"
echo "branch=${branch}" >> "${GITHUB_OUTPUT}"
echo "Resolved outputs: library_name='${lib_name}', branch='${branch:-<default>}'"
refresh:
name: Refresh Context7
needs: config
runs-on: ubuntu-24.04
steps:
- name: Call Context7 API
id: call_api
shell: bash
env:
CONTEXT7_API_KEY: ${{ secrets.context7_api_key }}
LIB_NAME: ${{ needs.config.outputs.library_name }}
BRANCH: ${{ needs.config.outputs.branch }}
run: |
echo "🚢 Preparing Context7 refresh for ${LIB_NAME}..."
# Construct JSON payload
if [[ -n "${BRANCH}" ]]; then
echo "Branch specified: ${BRANCH}"
PAYLOAD=$(printf '{"libraryName": "%s", "branch": "%s"}' "${LIB_NAME}" "${BRANCH}")
else
echo "No branch specified; Context7 will use the default branch."
PAYLOAD=$(printf '{"libraryName": "%s"}' "${LIB_NAME}")
fi
echo "Payload: ${PAYLOAD}"
# Execute API call
RESPONSE=$(curl -sS -i -X POST "https://context7.com/api/v1/refresh" \
-H "Authorization: Bearer ${CONTEXT7_API_KEY}" \
-H "Content-Type: application/json" \
-d "${PAYLOAD}")
HTTP_CODE=$(echo "${RESPONSE}" | grep "HTTP/" | awk '{print $2}' | tail -n 1)
BODY=$(echo "${RESPONSE}" | sed '1,/^\r\{0,1\}$/d')
echo "Response Body: ${BODY}"
echo "HTTP Code: ${HTTP_CODE}"
if [[ "${HTTP_CODE}" -lt 200 ]] || [[ "${HTTP_CODE}" -ge 300 ]]; then
echo "::error::Failed to refresh Context7 library. HTTP Code: ${HTTP_CODE}. Response: ${BODY}"
exit 1
fi
echo "✅ Successfully triggered Context7 refresh."
report:
name: Sync Report
needs: [config, refresh]
runs-on: ubuntu-24.04
if: always()
steps:
- name: Execution Summary
shell: bash
env:
LIBRARY_NAME: ${{ needs.config.outputs.library_name }}
BRANCH: ${{ needs.config.outputs.branch }}
REFRESH_RESULT: ${{ needs.refresh.result }}
run: |
echo "Context7 Sync Summary"
echo "---------------------"
echo "Library: ${LIBRARY_NAME}"
echo "Branch: ${BRANCH}"
echo "Result: ${REFRESH_RESULT}"
if [[ "${REFRESH_RESULT}" == "success" ]]; then
echo "✅ Sync completed successfully."
else
echo "❌ Sync failed or was cancelled."
fi