|
| 1 | +name: Sync SDK Reference Documentation |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + sdk: |
| 7 | + description: "SDK to generate (see sdks.config.ts for available SDKs, or use 'all')" |
| 8 | + required: true |
| 9 | + default: "all" |
| 10 | + type: string |
| 11 | + version: |
| 12 | + description: "Version to generate (all, latest, or specific like v2.9.0)" |
| 13 | + required: true |
| 14 | + default: "latest" |
| 15 | + type: string |
| 16 | + limit: |
| 17 | + description: "Limit number of versions to generate (default: 5)" |
| 18 | + required: false |
| 19 | + default: 5 |
| 20 | + type: number |
| 21 | + force: |
| 22 | + description: "Force regeneration of existing versions" |
| 23 | + required: false |
| 24 | + default: false |
| 25 | + type: boolean |
| 26 | + |
| 27 | + repository_dispatch: |
| 28 | + types: [sdk-release] |
| 29 | + |
| 30 | +# prevent concurrent runs that could conflict |
| 31 | +concurrency: |
| 32 | + group: sdk-reference-${{ github.ref }} |
| 33 | + cancel-in-progress: false |
| 34 | + |
| 35 | +jobs: |
| 36 | + generate: |
| 37 | + runs-on: ubuntu-latest |
| 38 | + timeout-minutes: 30 |
| 39 | + permissions: |
| 40 | + contents: write |
| 41 | + |
| 42 | + steps: |
| 43 | + - name: Checkout docs repo |
| 44 | + uses: actions/checkout@v4 |
| 45 | + with: |
| 46 | + fetch-depth: 0 |
| 47 | + |
| 48 | + - name: Setup Node.js |
| 49 | + uses: actions/setup-node@v4 |
| 50 | + with: |
| 51 | + node-version: "20" |
| 52 | + |
| 53 | + - name: Install pnpm |
| 54 | + uses: pnpm/action-setup@v4 |
| 55 | + with: |
| 56 | + version: 9 |
| 57 | + |
| 58 | + - name: Cache pnpm dependencies |
| 59 | + uses: actions/cache@v4 |
| 60 | + with: |
| 61 | + path: | |
| 62 | + ~/.pnpm-store |
| 63 | + sdk-reference-generator/node_modules |
| 64 | + key: ${{ runner.os }}-pnpm-${{ hashFiles('sdk-reference-generator/pnpm-lock.yaml') }} |
| 65 | + restore-keys: | |
| 66 | + ${{ runner.os }}-pnpm- |
| 67 | +
|
| 68 | + - name: Setup Python |
| 69 | + uses: actions/setup-python@v5 |
| 70 | + with: |
| 71 | + python-version: "3.11" |
| 72 | + cache: "pip" |
| 73 | + |
| 74 | + - name: Install generator dependencies |
| 75 | + working-directory: sdk-reference-generator |
| 76 | + run: pnpm install --frozen-lockfile |
| 77 | + |
| 78 | + - name: Install Python dependencies |
| 79 | + run: pip install -r requirements.txt |
| 80 | + |
| 81 | + - name: Determine SDK and Version |
| 82 | + id: params |
| 83 | + env: |
| 84 | + EVENT_NAME: ${{ github.event_name }} |
| 85 | + INPUT_SDK: ${{ github.event.inputs.sdk }} |
| 86 | + INPUT_VERSION: ${{ github.event.inputs.version }} |
| 87 | + INPUT_LIMIT: ${{ github.event.inputs.limit }} |
| 88 | + INPUT_FORCE: ${{ github.event.inputs.force }} |
| 89 | + PAYLOAD_SDK: ${{ github.event.client_payload.sdk }} |
| 90 | + PAYLOAD_VERSION: ${{ github.event.client_payload.version }} |
| 91 | + PAYLOAD_LIMIT: ${{ github.event.client_payload.limit }} |
| 92 | + run: | |
| 93 | + if [[ "$EVENT_NAME" == "workflow_dispatch" ]]; then |
| 94 | + SDK="$INPUT_SDK" |
| 95 | + VERSION="$INPUT_VERSION" |
| 96 | + LIMIT="$INPUT_LIMIT" |
| 97 | + FORCE="$INPUT_FORCE" |
| 98 | + elif [[ "$EVENT_NAME" == "repository_dispatch" ]]; then |
| 99 | + SDK="$PAYLOAD_SDK" |
| 100 | + VERSION="${PAYLOAD_VERSION:-latest}" |
| 101 | + LIMIT="${PAYLOAD_LIMIT:-5}" |
| 102 | + FORCE="false" |
| 103 | + fi |
| 104 | +
|
| 105 | + echo "sdk=${SDK:-all}" >> $GITHUB_OUTPUT |
| 106 | + echo "version=${VERSION:-latest}" >> $GITHUB_OUTPUT |
| 107 | + echo "limit=${LIMIT:-5}" >> $GITHUB_OUTPUT |
| 108 | + echo "force=${FORCE:-false}" >> $GITHUB_OUTPUT |
| 109 | +
|
| 110 | + - name: Generate SDK Reference |
| 111 | + working-directory: sdk-reference-generator |
| 112 | + env: |
| 113 | + SDK_NAME: ${{ steps.params.outputs.sdk }} |
| 114 | + SDK_VERSION: ${{ steps.params.outputs.version }} |
| 115 | + LIMIT: ${{ steps.params.outputs.limit }} |
| 116 | + FORCE: ${{ steps.params.outputs.force }} |
| 117 | + FORCE_COLOR: "2" |
| 118 | + run: | |
| 119 | + ARGS="--sdk $SDK_NAME --version $SDK_VERSION" |
| 120 | +
|
| 121 | + if [[ -n "$LIMIT" && "$LIMIT" != "0" ]]; then |
| 122 | + ARGS="$ARGS --limit $LIMIT" |
| 123 | + fi |
| 124 | +
|
| 125 | + if [[ "$FORCE" == "true" ]]; then |
| 126 | + ARGS="$ARGS --force" |
| 127 | + fi |
| 128 | +
|
| 129 | + pnpm run generate $ARGS |
| 130 | +
|
| 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 }} |
| 136 | + run: | |
| 137 | + git config user.name "github-actions[bot]" |
| 138 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 139 | +
|
| 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" |
| 145 | + echo "changes=false" >> $GITHUB_OUTPUT |
| 146 | + else |
| 147 | + git commit -m "docs: update SDK reference for $SDK_NAME $SDK_VERSION" |
| 148 | + git push |
| 149 | + echo "changes=true" >> $GITHUB_OUTPUT |
| 150 | + fi |
| 151 | +
|
| 152 | + - name: Summary |
| 153 | + env: |
| 154 | + SDK_NAME: ${{ steps.params.outputs.sdk }} |
| 155 | + SDK_VERSION: ${{ steps.params.outputs.version }} |
| 156 | + LIMIT: ${{ steps.params.outputs.limit }} |
| 157 | + CHANGES: ${{ steps.commit.outputs.changes }} |
| 158 | + run: | |
| 159 | + echo "## SDK Reference Generation Complete" >> $GITHUB_STEP_SUMMARY |
| 160 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 161 | + echo "| Parameter | Value |" >> $GITHUB_STEP_SUMMARY |
| 162 | + echo "|-----------|-------|" >> $GITHUB_STEP_SUMMARY |
| 163 | + echo "| SDK | $SDK_NAME |" >> $GITHUB_STEP_SUMMARY |
| 164 | + echo "| Version | $SDK_VERSION |" >> $GITHUB_STEP_SUMMARY |
| 165 | + echo "| Limit | ${LIMIT:-No limit} |" >> $GITHUB_STEP_SUMMARY |
| 166 | + echo "| Changes committed | $CHANGES |" >> $GITHUB_STEP_SUMMARY |
| 167 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 168 | +
|
| 169 | + if [[ "$CHANGES" == "true" ]]; then |
| 170 | + echo "### Generated Files" >> $GITHUB_STEP_SUMMARY |
| 171 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 172 | + echo "Total MDX files: $(find docs/sdk-reference -type f -name '*.mdx' | wc -l)" >> $GITHUB_STEP_SUMMARY |
| 173 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 174 | + fi |
0 commit comments