Skip to content

Commit 8f4c431

Browse files
authored
chore(ci): setup automated stainless builds (#3557)
# What does this PR do? <!-- Provide a short summary of what this PR does and why. Link to relevant issues if applicable. --> This pull request adds a new workflow that does 2 things: 1. generate [SDK preview builds](https://www.stainless.com/docs/guides/automate-updates#set-up-automatic-preview-builds) whenever the OpenAPI spec file is modified in a PR 2. on PR merge, generate SDK builds that will be pushed to the different SDK repos (i.e start the release process) > [!NOTE] > No repo secret `STAINLESS_API_KEY` is needed, the authentication is done automatically via GitHub OIDC. <!-- If resolving an issue, uncomment and update the line below --> <!-- Closes #[issue-number] --> ## Test Plan <!-- Describe the tests you ran to verify your changes with result summaries. *Provide clear instructions so the plan can be easily re-executed.* --> I tested in my fork: stainless-api#3
1 parent aa2bd82 commit 8f4c431

File tree

4 files changed

+126
-11
lines changed

4 files changed

+126
-11
lines changed

.github/workflows/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Llama Stack uses GitHub Actions for Continuous Integration (CI). Below is a tabl
1818
| Python Package Build Test | [python-build-test.yml](python-build-test.yml) | Test building the llama-stack PyPI project |
1919
| Integration Tests (Record) | [record-integration-tests.yml](record-integration-tests.yml) | Run the integration test suite from tests/integration |
2020
| Check semantic PR titles | [semantic-pr.yml](semantic-pr.yml) | Ensure that PR titles follow the conventional commit spec |
21+
| Stainless SDK Builds | [stainless-builds.yml](stainless-builds.yml) | Build Stainless SDK from OpenAPI spec changes |
2122
| Close stale issues and PRs | [stale_bot.yml](stale_bot.yml) | Run the Stale Bot action |
2223
| Test External Providers Installed via Module | [test-external-provider-module.yml](test-external-provider-module.yml) | Test External Provider installation via Python module |
2324
| Test External API and Providers | [test-external.yml](test-external.yml) | Test the External API and Provider mechanisms |
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: Stainless SDK Builds
2+
run-name: Build Stainless SDK from OpenAPI spec changes
3+
4+
# This workflow uses pull_request_target, which allows it to run on pull requests
5+
# from forks with access to secrets. This is safe because the workflow definition
6+
# comes from the base branch (trusted), and the action only reads OpenAPI spec
7+
# files without executing any code from the PR.
8+
9+
on:
10+
pull_request_target:
11+
types:
12+
- opened
13+
- synchronize
14+
- reopened
15+
- closed
16+
paths:
17+
- "client-sdks/stainless/**"
18+
19+
concurrency:
20+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
21+
cancel-in-progress: true
22+
23+
env:
24+
# Stainless organization name.
25+
STAINLESS_ORG: llamastack
26+
27+
# Stainless project name.
28+
STAINLESS_PROJECT: llama-stack-client
29+
30+
# Path to your OpenAPI spec.
31+
OAS_PATH: ./client-sdks/stainless/openapi.yml
32+
33+
# Path to your Stainless config. Optional; only provide this if you prefer
34+
# to maintain the ground truth Stainless config in your own repo.
35+
CONFIG_PATH: ./client-sdks/stainless/config.yml
36+
37+
# When to fail the job based on build conclusion.
38+
# Options: "never" | "note" | "warning" | "error" | "fatal".
39+
FAIL_ON: error
40+
41+
# In your repo secrets, configure:
42+
# - STAINLESS_API_KEY: a Stainless API key, which you can generate on the
43+
# Stainless organization dashboard
44+
45+
jobs:
46+
preview:
47+
if: github.event.action != 'closed'
48+
runs-on: ubuntu-latest
49+
permissions:
50+
contents: read
51+
pull-requests: write
52+
steps:
53+
# Checkout the PR's code to access the OpenAPI spec and config files.
54+
# This is necessary to read the spec/config from the PR (including from forks).
55+
- name: Checkout repository
56+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
57+
with:
58+
repository: ${{ github.event.pull_request.head.repo.full_name }}
59+
ref: ${{ github.event.pull_request.head.sha }}
60+
fetch-depth: 2
61+
62+
# This action builds preview SDKs from the OpenAPI spec changes and
63+
# posts/updates a comment on the PR with build results and links to the preview.
64+
- name: Run preview builds
65+
uses: stainless-api/upload-openapi-spec-action/preview@32823b096b4319c53ee948d702d9052873af485f # 1.6.0
66+
with:
67+
stainless_api_key: ${{ secrets.STAINLESS_API_KEY }}
68+
org: ${{ env.STAINLESS_ORG }}
69+
project: ${{ env.STAINLESS_PROJECT }}
70+
oas_path: ${{ env.OAS_PATH }}
71+
config_path: ${{ env.CONFIG_PATH }}
72+
fail_on: ${{ env.FAIL_ON }}
73+
base_sha: ${{ github.event.pull_request.base.sha }}
74+
base_ref: ${{ github.event.pull_request.base.ref }}
75+
head_sha: ${{ github.event.pull_request.head.sha }}
76+
77+
merge:
78+
if: github.event.action == 'closed' && github.event.pull_request.merged == true
79+
runs-on: ubuntu-latest
80+
permissions:
81+
contents: read
82+
pull-requests: write
83+
steps:
84+
# Checkout the PR's code to access the OpenAPI spec and config files.
85+
# This is necessary to read the spec/config from the PR (including from forks).
86+
- name: Checkout repository
87+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
88+
with:
89+
repository: ${{ github.event.pull_request.head.repo.full_name }}
90+
ref: ${{ github.event.pull_request.head.sha }}
91+
fetch-depth: 2
92+
93+
# Note that this only merges in changes that happened on the last build on
94+
# preview/${{ github.head_ref }}. It's possible that there are OAS/config
95+
# changes that haven't been built, if the preview-sdk job didn't finish
96+
# before this step starts. In theory we want to wait for all builds
97+
# against preview/${{ github.head_ref }} to complete, but assuming that
98+
# the preview-sdk job happens before the PR merge, it should be fine.
99+
- name: Run merge build
100+
uses: stainless-api/upload-openapi-spec-action/merge@32823b096b4319c53ee948d702d9052873af485f # 1.6.0
101+
with:
102+
stainless_api_key: ${{ secrets.STAINLESS_API_KEY }}
103+
org: ${{ env.STAINLESS_ORG }}
104+
project: ${{ env.STAINLESS_PROJECT }}
105+
oas_path: ${{ env.OAS_PATH }}
106+
config_path: ${{ env.CONFIG_PATH }}
107+
fail_on: ${{ env.FAIL_ON }}
108+
base_sha: ${{ github.event.pull_request.base.sha }}
109+
base_ref: ${{ github.event.pull_request.base.ref }}
110+
head_sha: ${{ github.event.pull_request.head.sha }}

client-sdks/stainless/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
These are the source-of-truth configuration files used to generate the Stainless client SDKs via Stainless.
22

33
- `openapi.yml`: this is the OpenAPI specification for the Llama Stack API.
4-
- `openapi.stainless.yml`: this is the Stainless _configuration_ which instructs Stainless how to generate the client SDKs.
4+
- `config.yml`: this is the Stainless _configuration_ which instructs Stainless how to generate the client SDKs.
55

66
A small side note: notice the `.yml` suffixes since Stainless uses that suffix typically for its configuration files.
77

8-
These files go hand-in-hand. As of now, only the `openapi.yml` file is automatically generated using the `run_openapi_generator.sh` script.
8+
These files go hand-in-hand. As of now, only the `openapi.yml` file is automatically generated using the `run_openapi_generator.sh` script.

client-sdks/stainless/config-not-source-of-truth-yet.yml renamed to client-sdks/stainless/config.yml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ resources:
115115
sampling_params: SamplingParams
116116
scoring_result: ScoringResult
117117
system_message: SystemMessage
118+
query_result: RAGQueryResult
119+
document: RAGDocument
120+
query_config: RAGQueryConfig
118121
toolgroups:
119122
models:
120123
tool_group: ToolGroup
@@ -140,6 +143,11 @@ resources:
140143
endpoint: get /v1/tool-runtime/list-tools
141144
paginated: false
142145
invoke_tool: post /v1/tool-runtime/invoke
146+
subresources:
147+
rag_tool:
148+
methods:
149+
insert: post /v1/tool-runtime/rag-tool/insert
150+
query: post /v1/tool-runtime/rag-tool/query
143151

144152
responses:
145153
models:
@@ -332,21 +340,18 @@ resources:
332340
endpoint: get /v1/inspect/routes
333341
paginated: false
334342

335-
336343
moderations:
337344
models:
338345
create_response: ModerationObject
339346
methods:
340347
create: post /v1/moderations
341348

342-
343349
safety:
344350
models:
345351
run_shield_response: RunShieldResponse
346352
methods:
347353
run_shield: post /v1/safety/run-shield
348354

349-
350355
shields:
351356
models:
352357
shield: Shield
@@ -455,18 +460,17 @@ resources:
455460
iterrows: get /v1beta/datasetio/iterrows/{dataset_id}
456461
appendrows: post /v1beta/datasetio/append-rows/{dataset_id}
457462

458-
459463
settings:
460464
license: MIT
461-
unwrap_response_fields: [ data ]
465+
unwrap_response_fields: [data]
462466

463467
openapi:
464468
transformations:
465469
- command: mergeObject
466470
reason: Better return_type using enum
467471
args:
468472
target:
469-
- '$.components.schemas'
473+
- "$.components.schemas"
470474
object:
471475
ReturnType:
472476
additionalProperties: false
@@ -491,10 +495,10 @@ openapi:
491495
args:
492496
filter:
493497
only:
494-
- '$.components.schemas.ScoringFn.properties.return_type'
495-
- '$.components.schemas.RegisterScoringFunctionRequest.properties.return_type'
498+
- "$.components.schemas.ScoringFn.properties.return_type"
499+
- "$.components.schemas.RegisterScoringFunctionRequest.properties.return_type"
496500
value:
497-
$ref: '#/components/schemas/ReturnType'
501+
$ref: "#/components/schemas/ReturnType"
498502
- command: oneOfToAnyOf
499503
reason: Prism (mock server) doesn't like one of our requests as it technically matches multiple variants
500504

0 commit comments

Comments
 (0)