Skip to content

Commit ef43f57

Browse files
committed
feature: add sdk reference cron
1 parent 3b792c6 commit ef43f57

3 files changed

Lines changed: 126 additions & 22 deletions

File tree

.github/workflows/sdk-reference-generator-test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ on:
44
pull_request:
55
paths:
66
- "sdk-reference-generator/**"
7+
- ".github/workflows/sdk-reference-sync.yml"
8+
- ".github/workflows/sdk-reference-generator-test.yml"
9+
- "requirements.txt"
10+
- "docs.json"
11+
- "docs/sdk-reference/**"
712

813
jobs:
914
test:

.github/workflows/sdk-reference-sync.yml

Lines changed: 94 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ on:
2626

2727
repository_dispatch:
2828
types: [sdk-release]
29+
schedule:
30+
- cron: "*/15 * * * *"
2931

3032
# prevent concurrent runs that could conflict
3133
concurrency:
@@ -38,6 +40,7 @@ jobs:
3840
timeout-minutes: 30
3941
permissions:
4042
contents: write
43+
pull-requests: write
4144

4245
steps:
4346
- name: Checkout docs repo
@@ -78,7 +81,7 @@ jobs:
7881
- name: Install Python dependencies
7982
run: pip install -r requirements.txt
8083

81-
- name: Determine SDK and Version
84+
- name: Determine sync parameters
8285
id: params
8386
env:
8487
EVENT_NAME: ${{ github.event_name }}
@@ -91,20 +94,42 @@ jobs:
9194
PAYLOAD_LIMIT: ${{ github.event.client_payload.limit }}
9295
run: |
9396
if [[ "$EVENT_NAME" == "workflow_dispatch" ]]; then
97+
TRIGGER="workflow_dispatch"
9498
SDK="$INPUT_SDK"
9599
VERSION="$INPUT_VERSION"
96100
LIMIT="$INPUT_LIMIT"
97101
FORCE="$INPUT_FORCE"
98102
elif [[ "$EVENT_NAME" == "repository_dispatch" ]]; then
103+
TRIGGER="repository_dispatch (sdk-release)"
99104
SDK="$PAYLOAD_SDK"
100105
VERSION="${PAYLOAD_VERSION:-latest}"
101106
LIMIT="${PAYLOAD_LIMIT:-5}"
102107
FORCE="false"
108+
elif [[ "$EVENT_NAME" == "schedule" ]]; then
109+
TRIGGER="schedule (*/15 * * * *)"
110+
SDK="all"
111+
VERSION="all"
112+
LIMIT="3"
113+
FORCE="false"
114+
else
115+
TRIGGER="$EVENT_NAME"
116+
SDK="all"
117+
VERSION="latest"
118+
LIMIT="5"
119+
FORCE="false"
103120
fi
104121
122+
if [[ -z "$LIMIT" || "$LIMIT" == "0" ]]; then
123+
LIMIT_DISPLAY="No limit"
124+
else
125+
LIMIT_DISPLAY="$LIMIT"
126+
fi
127+
128+
echo "trigger=$TRIGGER" >> $GITHUB_OUTPUT
105129
echo "sdk=${SDK:-all}" >> $GITHUB_OUTPUT
106130
echo "version=${VERSION:-latest}" >> $GITHUB_OUTPUT
107131
echo "limit=${LIMIT:-5}" >> $GITHUB_OUTPUT
132+
echo "limit_display=$LIMIT_DISPLAY" >> $GITHUB_OUTPUT
108133
echo "force=${FORCE:-false}" >> $GITHUB_OUTPUT
109134
110135
- name: Generate SDK Reference
@@ -128,47 +153,96 @@ jobs:
128153
129154
pnpm run generate $ARGS
130155
131-
- name: Commit and push changes
132-
id: commit
133-
env:
134-
SDK_NAME: ${{ steps.params.outputs.sdk }}
135-
SDK_VERSION: ${{ steps.params.outputs.version }}
156+
- name: Collect change details
157+
id: changes
136158
run: |
137-
git config user.name "github-actions[bot]"
138-
git config user.email "github-actions[bot]@users.noreply.github.com"
159+
CHANGED_FILES="$(git status --porcelain -- docs/sdk-reference docs.json | wc -l | tr -d ' ')"
160+
TOTAL_MDX_FILES="$(find docs/sdk-reference -type f -name '*.mdx' | wc -l | tr -d ' ')"
139161
140-
git add docs/sdk-reference/
141-
git add docs.json
142-
143-
if git diff --staged --quiet; then
144-
echo "No changes to commit"
162+
if [[ "$CHANGED_FILES" == "0" ]]; then
145163
echo "changes=false" >> $GITHUB_OUTPUT
146164
else
147-
git commit -m "docs: update SDK reference for $SDK_NAME $SDK_VERSION"
148-
git push
149165
echo "changes=true" >> $GITHUB_OUTPUT
150166
fi
151167
168+
echo "changed_files=$CHANGED_FILES" >> $GITHUB_OUTPUT
169+
echo "total_mdx_files=$TOTAL_MDX_FILES" >> $GITHUB_OUTPUT
170+
171+
- name: Create pull request
172+
if: steps.changes.outputs.changes == 'true'
173+
id: cpr
174+
uses: peter-evans/create-pull-request@v8
175+
with:
176+
branch: automation/sdk-reference-sync
177+
delete-branch: true
178+
add-paths: |
179+
docs/sdk-reference
180+
docs.json
181+
author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
182+
committer: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
183+
commit-message: docs: sync SDK reference for ${{ steps.params.outputs.sdk }} ${{ steps.params.outputs.version }}
184+
title: docs: sync SDK reference for ${{ steps.params.outputs.sdk }} ${{ steps.params.outputs.version }}
185+
body: |
186+
## Summary
187+
This automated PR syncs generated SDK reference documentation.
188+
189+
## Trigger
190+
- Source: `${{ steps.params.outputs.trigger }}`
191+
- SDK: `${{ steps.params.outputs.sdk }}`
192+
- Version: `${{ steps.params.outputs.version }}`
193+
- Limit: `${{ steps.params.outputs.limit_display }}`
194+
- Force: `${{ steps.params.outputs.force }}`
195+
196+
## Changes
197+
- Updates generated reference files under `docs/sdk-reference/**`
198+
- Updates `docs.json` navigation when generation changes the docs tree
199+
- Changed files detected in this run: `${{ steps.changes.outputs.changed_files }}`
200+
- Total tracked MDX reference files after generation: `${{ steps.changes.outputs.total_mdx_files }}`
201+
202+
## Validation
203+
- [x] SDK reference generator completed successfully
204+
- [x] Workflow run summary is attached to this run
205+
- [ ] Reviewer has verified the generated docs diff before merge
206+
207+
## Run Details
208+
- Workflow: `${{ github.workflow }}`
209+
- Run: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
210+
152211
- name: Summary
153212
env:
213+
TRIGGER: ${{ steps.params.outputs.trigger }}
154214
SDK_NAME: ${{ steps.params.outputs.sdk }}
155215
SDK_VERSION: ${{ steps.params.outputs.version }}
156-
LIMIT: ${{ steps.params.outputs.limit }}
157-
CHANGES: ${{ steps.commit.outputs.changes }}
216+
LIMIT: ${{ steps.params.outputs.limit_display }}
217+
FORCE: ${{ steps.params.outputs.force }}
218+
CHANGES: ${{ steps.changes.outputs.changes }}
219+
CHANGED_FILES: ${{ steps.changes.outputs.changed_files }}
220+
TOTAL_MDX_FILES: ${{ steps.changes.outputs.total_mdx_files }}
221+
PR_OPERATION: ${{ steps.cpr.outputs.pull-request-operation }}
222+
PR_URL: ${{ steps.cpr.outputs.pull-request-url }}
158223
run: |
159224
echo "## SDK Reference Generation Complete" >> $GITHUB_STEP_SUMMARY
160225
echo "" >> $GITHUB_STEP_SUMMARY
161226
echo "| Parameter | Value |" >> $GITHUB_STEP_SUMMARY
162227
echo "|-----------|-------|" >> $GITHUB_STEP_SUMMARY
228+
echo "| Trigger | $TRIGGER |" >> $GITHUB_STEP_SUMMARY
163229
echo "| SDK | $SDK_NAME |" >> $GITHUB_STEP_SUMMARY
164230
echo "| Version | $SDK_VERSION |" >> $GITHUB_STEP_SUMMARY
165-
echo "| Limit | ${LIMIT:-No limit} |" >> $GITHUB_STEP_SUMMARY
166-
echo "| Changes committed | $CHANGES |" >> $GITHUB_STEP_SUMMARY
231+
echo "| Limit | $LIMIT |" >> $GITHUB_STEP_SUMMARY
232+
echo "| Force | $FORCE |" >> $GITHUB_STEP_SUMMARY
233+
echo "| Changes detected | $CHANGES |" >> $GITHUB_STEP_SUMMARY
234+
echo "| Changed files | ${CHANGED_FILES:-0} |" >> $GITHUB_STEP_SUMMARY
235+
echo "| PR operation | ${PR_OPERATION:-No PR created} |" >> $GITHUB_STEP_SUMMARY
236+
if [[ -n "$PR_URL" ]]; then
237+
echo "| Pull request | $PR_URL |" >> $GITHUB_STEP_SUMMARY
238+
fi
167239
echo "" >> $GITHUB_STEP_SUMMARY
168240
169241
if [[ "$CHANGES" == "true" ]]; then
170242
echo "### Generated Files" >> $GITHUB_STEP_SUMMARY
171243
echo '```' >> $GITHUB_STEP_SUMMARY
172-
echo "Total MDX files: $(find docs/sdk-reference -type f -name '*.mdx' | wc -l)" >> $GITHUB_STEP_SUMMARY
244+
echo "Total MDX files: $TOTAL_MDX_FILES" >> $GITHUB_STEP_SUMMARY
173245
echo '```' >> $GITHUB_STEP_SUMMARY
246+
else
247+
echo "No SDK reference changes were detected, so no pull request was created." >> $GITHUB_STEP_SUMMARY
174248
fi

sdk-reference-generator/README.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ Tests cover:
138138
The generator runs in GitHub Actions on:
139139
- Manual workflow dispatch
140140
- Automatic repository dispatch from SDK repos on release
141+
- Scheduled sync every 15 minutes
141142

142143
### Manual Trigger (GitHub UI)
143144

@@ -172,10 +173,35 @@ curl -X POST \
172173
-d '{"event_type": "sdk-release", "client_payload": {"sdk": "js-sdk", "version": "v2.9.0"}}'
173174
```
174175

176+
### Scheduled Sync
177+
178+
The sync workflow also runs on a 15-minute cron interval:
179+
180+
```text
181+
*/15 * * * *
182+
```
183+
184+
Scheduled runs default to:
185+
- **SDK**: `all`
186+
- **Version**: `all`
187+
- **Limit**: `3`
188+
- **Force**: `false`
189+
190+
This acts as a polling safety net if an SDK release event is missed, while keeping the scheduled scan bounded to the latest three versions per SDK.
191+
192+
### Output Behavior
193+
194+
The sync workflow no longer pushes directly to `main`.
195+
196+
When generated docs change, the workflow now:
197+
- Creates or updates an automation branch
198+
- Opens a structured pull request with trigger metadata, generation parameters, and a link to the workflow run
199+
- Limits committed paths to `docs/sdk-reference/**` and `docs.json`
200+
175201
### Safety Features
176202

177203
- Validates all generated files before committing
178-
- Only commits if changes detected
204+
- Only creates a pull request if changes are detected
179205
- Full logging visible in workflow runs
180206
- User inputs passed via environment variables (prevents script injection)
181207

@@ -197,4 +223,3 @@ pnpm run generate --sdk js-sdk --limit 1
197223
# run tests
198224
pnpm test
199225
```
200-

0 commit comments

Comments
 (0)