blob: 86d92735735ccbae3c508bfdbcd1c83b1c397c2e (
plain)
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
|
name: Context7 refresh
# Listens for completion of "Update version tags" via workflow_run, then
# refreshes the Context7 variant for the branch that fed it. The upstream
# workflow is matched by name — DO NOT rename `Update version tags` without
# updating the `workflows:` field below.
#
# Context7 API addresses variants by their underlying Git branch name
# (rolling/circinus/sagitta), not by their display name (rolling/1.5/1.4).
# For the default variant (rolling) the `branch` field is OMITTED.
#
# OPERATOR NOTE: do NOT use GitHub's "Re-run jobs" on `Update version tags`.
# Re-runs replay the original SHA, which would move the version tag
# BACKWARD and trigger this workflow to refresh Context7 against stale
# content. To force a Context7 refresh, use the workflow_dispatch input
# below — it calls Context7 directly without touching any tag.
on:
workflow_run:
workflows: ["Update version tags"]
types: [completed]
workflow_dispatch:
inputs:
branch:
description: "Source branch whose Context7 variant to refresh"
type: choice
options: [rolling, circinus, sagitta]
default: rolling
permissions: {}
concurrency:
group: context7-refresh-${{ inputs.branch || github.event.workflow_run.head_branch }}
cancel-in-progress: true
jobs:
refresh:
if: >-
github.event_name == 'workflow_dispatch' ||
(github.event.workflow_run.conclusion == 'success' &&
contains(fromJSON('["rolling","circinus","sagitta"]'), github.event.workflow_run.head_branch))
runs-on: ubuntu-latest
permissions: {}
steps:
- name: Refresh Context7 library
env:
CONTEXT7_API_KEY: ${{ secrets.CONTEXT7_API_KEY }}
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
DISPATCH_BRANCH: ${{ inputs.branch }}
run: |
set -euo pipefail
if [[ -z "${CONTEXT7_API_KEY:-}" ]]; then
echo "ERROR: CONTEXT7_API_KEY is unset or empty" >&2
exit 1
fi
if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
BRANCH="$DISPATCH_BRANCH"
else
BRANCH="$HEAD_BRANCH"
fi
case "$BRANCH" in
rolling|circinus|sagitta) ;;
*) echo "Unexpected branch: $BRANCH" >&2; exit 1 ;;
esac
echo "Refreshing Context7 variant for branch: $BRANCH"
# Default variant (rolling) refreshes when `branch` is omitted;
# non-default variants address by their Git branch name.
if [[ "$BRANCH" == "rolling" ]]; then
PAYLOAD="$(jq -nc --arg lib "/${{ github.repository }}" \
'{libraryName: $lib}')"
else
PAYLOAD="$(jq -nc --arg lib "/${{ github.repository }}" --arg br "$BRANCH" \
'{libraryName: $lib, branch: $br}')"
fi
curl -fsSL \
--connect-timeout 10 \
--max-time 60 \
--retry 2 --retry-delay 10 \
-X POST \
"https://context7.com/api/v1/refresh" \
-H "Authorization: Bearer $CONTEXT7_API_KEY" \
-H "Content-Type: application/json" \
-d "$PAYLOAD"
|