Skip to content

Commit 121f74e

Browse files
committed
chore(ci): setup automated stainless builds
1 parent 7e294d3 commit 121f74e

File tree

4 files changed

+746
-2
lines changed

4 files changed

+746
-2
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 SDKs |
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: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
name: Build SDKs for pull request (including forks)
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 and OIDC tokens. This is safe because the
6+
# workflow definition comes from the base branch (trusted), and the action only
7+
# reads OpenAPI spec files without executing any code from the PR.
8+
#
9+
# Important: If your repository is public, configure GitHub to require approval
10+
# for workflows from fork PRs. Go to Settings → Actions → General, and under
11+
# "Fork pull request workflows from outside collaborators", select
12+
# "Require approval for all outside collaborators".
13+
14+
on:
15+
pull_request_target:
16+
types:
17+
- opened
18+
- synchronize
19+
- reopened
20+
- closed
21+
paths:
22+
- "client-sdks/stainless/**"
23+
24+
concurrency:
25+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
26+
cancel-in-progress: true
27+
28+
env:
29+
# Stainless organization name.
30+
STAINLESS_ORG: llamastack
31+
32+
# Stainless project name.
33+
STAINLESS_PROJECT: llama-stack-client
34+
35+
# Path to your OpenAPI spec.
36+
OAS_PATH: ./client-sdks/stainless/openapi.yml
37+
38+
# Path to your Stainless config. Optional; only provide this if you prefer
39+
# to maintain the ground truth Stainless config in your own repo.
40+
CONFIG_PATH: ./client-sdks/stainless/config.yml
41+
42+
# When to fail the job based on build conclusion.
43+
# Options: "never" | "note" | "warning" | "error" | "fatal".
44+
FAIL_ON: error
45+
46+
jobs:
47+
preview:
48+
if: github.event.action != 'closed'
49+
runs-on: ubuntu-latest
50+
permissions:
51+
contents: read
52+
pull-requests: write
53+
# id-token: write allows GitHub to mint a short-lived, cryptographically
54+
# signed OIDC token that Stainless validates for authentication. This
55+
# eliminates the need for manually managing API secrets. This permission
56+
# does NOT grant any operations on the source repository.
57+
id-token: write
58+
steps:
59+
# Checkout the PR's code to access the OpenAPI spec and config files.
60+
# This is necessary to read the spec/config from the PR (including from forks).
61+
- name: Checkout repository
62+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
63+
with:
64+
repository: ${{ github.event.pull_request.head.repo.full_name }}
65+
ref: ${{ github.event.pull_request.head.sha }}
66+
fetch-depth: 2
67+
68+
# This action builds preview SDKs from the OpenAPI spec changes and
69+
# posts/updates a comment on the PR with build results and links to the preview.
70+
- name: Run preview builds
71+
uses: stainless-api/upload-openapi-spec-action/preview@32823b096b4319c53ee948d702d9052873af485f # 1.6.0
72+
with:
73+
org: ${{ env.STAINLESS_ORG }}
74+
project: ${{ env.STAINLESS_PROJECT }}
75+
oas_path: ${{ env.OAS_PATH }}
76+
config_path: ${{ env.CONFIG_PATH }}
77+
fail_on: ${{ env.FAIL_ON }}
78+
base_sha: ${{ github.event.pull_request.base.sha }}
79+
base_ref: ${{ github.event.pull_request.base.ref }}
80+
head_sha: ${{ github.event.pull_request.head.sha }}
81+
82+
merge:
83+
if: github.event.action == 'closed' && github.event.pull_request.merged == true
84+
runs-on: ubuntu-latest
85+
permissions:
86+
contents: read
87+
pull-requests: write
88+
# id-token: write allows GitHub to mint a short-lived, cryptographically
89+
# signed OIDC token that Stainless validates for authentication. This
90+
# eliminates the need for manually managing API secrets. This permission
91+
# does NOT grant any operations on the source repository.
92+
id-token: write
93+
steps:
94+
# Checkout the PR's code to access the OpenAPI spec and config files.
95+
# This is necessary to read the spec/config from the PR (including from forks).
96+
- name: Checkout repository
97+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
98+
with:
99+
repository: ${{ github.event.pull_request.head.repo.full_name }}
100+
ref: ${{ github.event.pull_request.head.sha }}
101+
fetch-depth: 2
102+
103+
# Note that this only merges in changes that happened on the last build on
104+
# preview/${{ github.head_ref }}. It's possible that there are OAS/config
105+
# changes that haven't been built, if the preview-sdk job didn't finish
106+
# before this step starts. In theory we want to wait for all builds
107+
# against preview/${{ github.head_ref }} to complete, but assuming that
108+
# the preview-sdk job happens before the PR merge, it should be fine.
109+
- name: Run merge build
110+
uses: stainless-api/upload-openapi-spec-action/merge@32823b096b4319c53ee948d702d9052873af485f # 1.6.0
111+
with:
112+
org: ${{ env.STAINLESS_ORG }}
113+
project: ${{ env.STAINLESS_PROJECT }}
114+
oas_path: ${{ env.OAS_PATH }}
115+
config_path: ${{ env.CONFIG_PATH }}
116+
fail_on: ${{ env.FAIL_ON }}
117+
base_sha: ${{ github.event.pull_request.base.sha }}
118+
base_ref: ${{ github.event.pull_request.base.ref }}
119+
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.

0 commit comments

Comments
 (0)