Skip to content

Conversation

@dgellow
Copy link

@dgellow dgellow commented Sep 26, 2025

What does this PR do?

This pull request adds a new workflow that does 2 things:

  1. generate SDK 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.

Test Plan

I tested in my fork: stainless-api#3

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 26, 2025
@leseb
Copy link
Collaborator

leseb commented Oct 3, 2025

Just added the STAINLESS_API_KEY key to the repo :)

Copy link
Collaborator

@leseb leseb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized that this can only work when NOT submitting a PR from fork given Github security model on passing secrets to workflow.

@dgellow I'm wondering how this is used elsewhere in practice and how other projects overcome that? Thanks!

@dgellow
Copy link
Author

dgellow commented Oct 23, 2025

I'm moving this one back to draft until I have a great documented solution to share

@dgellow dgellow marked this pull request as draft October 23, 2025 13:15
@bbrowning
Copy link
Collaborator

Parts 1, 2, 3, and 4 of https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/ are important reading if we need to find a way to pass a secret into something triggered on every pull request.

@dgellow
Copy link
Author

dgellow commented Oct 24, 2025

Thanks @bbrowning. I actually already read those articles, unfortunately there are a few details that are making the mentioned solutions a no-go for this repo.
However I have a great solution that won't require any CI secret. I expect to have it ready later today and will move the PR out of draft asap :)

edit: well, not exactly today, my plane internet is spotty

@dgellow dgellow force-pushed the dgellow/add-stainless-workflows branch from 0dc7d00 to a0eb949 Compare October 25, 2025 03:10
@dgellow
Copy link
Author

dgellow commented Oct 29, 2025

Currently blocked by stainless-api/upload-openapi-spec-action#133. Once merged I will update the github action SHA and that should be ready.

@dgellow dgellow force-pushed the dgellow/add-stainless-workflows branch from a0eb949 to df9149c Compare October 30, 2025 20:36
@dgellow dgellow force-pushed the dgellow/add-stainless-workflows branch from df9149c to cfae411 Compare October 30, 2025 20:39
@dgellow dgellow marked this pull request as ready for review October 30, 2025 20:40
@dgellow
Copy link
Author

dgellow commented Oct 30, 2025

Some notes that may be of interest that I shared on Discord.

The workflow

  1. external contributor (EC) forks the repo
  2. EC does some modifications to the Stainless config file or your spec file
  3. EC opens a PR
  4. the CI workflow is triggered, run the github action
  5. action creates a new preview branch for your Stainless project, uploads the config + spec file
  6. action starts a build (meaning all sdks configured in your config file will be generated + pushed to an internal repo)
  7. action wait for the build to complete
  8. action reports any build diagnostics as github comment to the PR
  9. when the PR is merged, the action start a new build but this time for your main branch, which will be pushed to your public SDK repos

On security

  • instead of a static API key in a repo secret the github action will be using github OpenID Connect (OIDC)
    • in short, github mints a short lived token that cannot be tempered with (cryptographically signed)
  • the token includes info regarding the repository, that makes it possible to validate you're actually allowed to push to the Stainless project. The only requirement is to have our github app installed in your github org (it does not need to be given read or write access to the repo where you generate your spec)
  • to support PRs from forks the workflow needs to rely on the github event pull_request_target , followed by a git checkout to the PR branch
  • workflow files aren't at risk, in the case of a fork PR the workflows from the base repo are used. Github will never run workflows maliciously edited by a fork, unless they have been merged
  • the github action doesn't evaluate anything from the fork repo, it only read the spec + config file then interact with the Stainless API

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too sure where exactly you would prefer that file to be located 🤔. I used docs/static/ to keep it close to the spec file, but that's really up to you

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dgellow I think we should keep it in the client-sdks/stainless/ folder. There is already an openapi.yml there. We can keep a stainless-config.yml right next to it. The README there can mention that this file is named openapi.stainless.yml in the stainless-sdk/ repository.

@dgellow dgellow requested a review from leseb October 30, 2025 20:45
@ashwinb
Copy link
Contributor

ashwinb commented Oct 30, 2025

@dgellow how could we do a test-run of this? We have a change from @raghotham which updated the types. See #3948

@ashwinb ashwinb changed the title chore(ci): setup automated stainless builds feat(ci): setup automated stainless builds Oct 30, 2025
@ashwinb ashwinb changed the title feat(ci): setup automated stainless builds chore(ci): setup automated stainless builds Oct 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants