Skip to content

Commit b1c2c3a

Browse files
committed
add sdk autogen workflow and make it a part of the release workflow
1 parent 6994564 commit b1c2c3a

File tree

3 files changed

+141
-0
lines changed

3 files changed

+141
-0
lines changed

.github/scripts/is_new_sdk_ref.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
# This script checks for diffs in the js/ and python/ directory.
6+
# If there are diffs, it means we need to generate new SDK references.
7+
if git diff --name-only HEAD^ | grep -q '^js/\|^python/'; then
8+
echo "true"
9+
else
10+
echo "false"
11+
fi
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: Generate SDK references
2+
3+
on:
4+
workflow_dispatch:
5+
workflow_call:
6+
# Remove after testing
7+
push:
8+
branches:
9+
- improved-api-refs
10+
11+
concurrency: ${{ github.workflow }}-${{ github.ref }}
12+
13+
permissions:
14+
contents: write
15+
16+
jobs:
17+
is_new_sdk_ref:
18+
name: Is new SDK reference?
19+
runs-on: ubuntu-latest
20+
outputs:
21+
new_sdk_ref: ${{ steps.sdk-changes.outputs.new_sdk_ref }}
22+
steps:
23+
- name: Checkout Repo
24+
uses: actions/checkout@v3
25+
with:
26+
fetch-depth: 2
27+
28+
- name: Check if SDK changes
29+
id: sdk-changes
30+
run: |
31+
IS_NEW_sdk_REF=$(./.github/scripts/is_new_sdk_ref.sh)
32+
echo "new_sdk_ref=$IS_NEW_sdk_REF" >> "$GITHUB_OUTPUT"
33+
34+
sdk-changes:
35+
name: SDK changes
36+
runs-on: ubuntu-latest
37+
steps:
38+
- name: Checkout repository
39+
uses: actions/checkout@v3
40+
with:
41+
fetch-depth: 0
42+
43+
- name: Install pnpm
44+
uses: pnpm/action-setup@v3
45+
id: pnpm-install
46+
with:
47+
version: 9.5
48+
49+
- name: Setup Node
50+
uses: actions/setup-node@v3
51+
with:
52+
node-version: "20.x"
53+
registry-url: "https://registry.npmjs.org"
54+
cache: pnpm
55+
cache-dependency-path: pnpm-lock.yaml
56+
57+
- name: Configure pnpm
58+
run: |
59+
pnpm config set auto-install-peers true
60+
pnpm config set exclude-links-from-lockfile true
61+
62+
- name: Install dependencies
63+
run: pnpm install --frozen-lockfile
64+
65+
- name: Set up Python
66+
id: setup-python
67+
uses: actions/setup-python@v5
68+
with:
69+
python-version: "3.8"
70+
71+
- name: Install and configure Poetry
72+
uses: snok/install-poetry@v1
73+
with:
74+
version: 1.5.1
75+
virtualenvs-create: true
76+
virtualenvs-in-project: true
77+
installer-parallel: true
78+
79+
- name: Install dependencies
80+
working-directory: ./packages/python-sdk
81+
run: poetry install --no-interaction --no-root
82+
83+
- name: Generate Python SDK reference
84+
id: python-sdk-ref
85+
working-directory: ./python
86+
run: |
87+
source .venv/bin/activate
88+
./scripts/generate_sdk_ref.sh
89+
90+
- name: Generate JS SDK reference
91+
id: js-sdk-ref
92+
working-directory: ./js
93+
run: ./scripts/generate_sdk_ref.sh
94+
95+
- name: Show docs file structure
96+
run: tree apps/web/src/app/\(docs\)/docs/sdk-reference
97+
98+
- name: Commit new SDK reference versions
99+
env:
100+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
101+
run: |
102+
git config user.name "github-actions[bot]"
103+
git config user.email "github-actions[bot]@users.noreply.github.com"
104+
git add ./sdk-reference
105+
git commit -m "[skip ci] Release new SDK reference doc versions" || exit 0
106+
git push

.github/workflows/release.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,30 @@ jobs:
319319
env:
320320
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
321321

322+
is_new_sdk_ref:
323+
name: Is new SDK reference?
324+
runs-on: ubuntu-latest
325+
outputs:
326+
new_sdk_ref: ${{ steps.sdk-changes.outputs.new_sdk_ref }}
327+
steps:
328+
- name: Checkout Repo
329+
uses: actions/checkout@v3
330+
with:
331+
fetch-depth: 2
332+
333+
- name: Check if SDK changes
334+
id: sdk-changes
335+
run: |
336+
IS_NEW_SDK_REF=$(./.github/scripts/is_new_sdk_ref.sh)
337+
echo "new_sdk_ref=$IS_NEW_SDK_REF" >> "$GITHUB_OUTPUT"
338+
339+
generate_sdk_ref:
340+
name: Generate SDK reference
341+
needs: [is_release, python-tests, js-tests, is_new_sdk_ref]
342+
if: (!cancelled()) && !contains(needs.*.result, 'failure') && needs.is_release.outputs.release == 'true' && needs.is_new_sdk_ref.outputs.new_sdk_ref == 'true'
343+
uses: ./.github/workflows/generate_sdk_ref.yml
344+
secrets: inherit
345+
322346
report-failure:
323347
needs: [python-tests, js-tests, release]
324348
if: failure()

0 commit comments

Comments
 (0)