Skip to content

Commit 2e765c7

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

File tree

3 files changed

+721
-0
lines changed

3 files changed

+721
-0
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: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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/openapi.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 enables OIDC token generation for identity verification
54+
# with external services. This does NOT grant permissions for any other
55+
# operations on the source repository.
56+
id-token: write
57+
steps:
58+
# Checkout the PR's code to access the OpenAPI spec and config files.
59+
# This is necessary to read the spec/config from the PR (including from forks).
60+
- name: Checkout repository
61+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
62+
with:
63+
repository: ${{ github.event.pull_request.head.repo.full_name }}
64+
ref: ${{ github.event.pull_request.head.sha }}
65+
fetch-depth: 2
66+
67+
# This action builds preview SDKs from the OpenAPI spec changes and
68+
# posts/updates a comment on the PR with build results and links to the preview.
69+
- name: Run preview builds
70+
uses: stainless-api/upload-openapi-spec-action/preview@32823b096b4319c53ee948d702d9052873af485f # 1.6.0
71+
with:
72+
org: ${{ env.STAINLESS_ORG }}
73+
project: ${{ env.STAINLESS_PROJECT }}
74+
oas_path: ${{ env.OAS_PATH }}
75+
config_path: ${{ env.CONFIG_PATH }}
76+
fail_on: ${{ env.FAIL_ON }}
77+
base_sha: ${{ github.event.pull_request.base.sha }}
78+
base_ref: ${{ github.event.pull_request.base.ref }}
79+
head_sha: ${{ github.event.pull_request.head.sha }}
80+
81+
merge:
82+
if: github.event.action == 'closed' && github.event.pull_request.merged == true
83+
runs-on: ubuntu-latest
84+
permissions:
85+
contents: read
86+
pull-requests: write
87+
# id-token: write enables OIDC token generation for identity verification
88+
# with external services. This does NOT grant permissions for any other
89+
# operations on the source repository.
90+
id-token: write
91+
steps:
92+
# Checkout the PR's code to access the OpenAPI spec and config files.
93+
# This is necessary to read the spec/config from the PR (including from forks).
94+
- name: Checkout repository
95+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
96+
with:
97+
repository: ${{ github.event.pull_request.head.repo.full_name }}
98+
ref: ${{ github.event.pull_request.head.sha }}
99+
fetch-depth: 2
100+
101+
# Note that this only merges in changes that happened on the last build on
102+
# preview/${{ github.head_ref }}. It's possible that there are OAS/config
103+
# changes that haven't been built, if the preview-sdk job didn't finish
104+
# before this step starts. In theory we want to wait for all builds
105+
# against preview/${{ github.head_ref }} to complete, but assuming that
106+
# the preview-sdk job happens before the PR merge, it should be fine.
107+
- name: Run merge build
108+
uses: stainless-api/upload-openapi-spec-action/merge@32823b096b4319c53ee948d702d9052873af485f # 1.6.0
109+
with:
110+
org: ${{ env.STAINLESS_ORG }}
111+
project: ${{ env.STAINLESS_PROJECT }}
112+
oas_path: ${{ env.OAS_PATH }}
113+
config_path: ${{ env.CONFIG_PATH }}
114+
fail_on: ${{ env.FAIL_ON }}
115+
base_sha: ${{ github.event.pull_request.base.sha }}
116+
base_ref: ${{ github.event.pull_request.base.ref }}
117+
head_sha: ${{ github.event.pull_request.head.sha }}

0 commit comments

Comments
 (0)