Skip to content

Commit ebafc43

Browse files
committed
feat: add support for github OIDC auth
1 parent 3fc8e47 commit ebafc43

26 files changed

+79525
-122
lines changed

README.md

Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@ docs on automating builds](https://www.stainless.com/docs/guides/automate-update
66

77
Support for GitLab CI is available. See the [GitLab example](./examples/merge_request_gitlab.yml).
88

9-
## Usage
9+
## Authentication
1010

11-
Get an API key from your Stainless organization dashboard. In the GitHub
12-
repository that stores your ground truth OpenAPI spec, add the key to the
13-
[repository secrets](https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository)
14-
with the name `STAINLESS_API_KEY`. You can do this with the GitHub CLI via:
11+
[Install the Stainless GitHub App](https://www.stainless.com/docs/guides/publish/#install-the-stainless-github-app) and link it to your Stainless organization. The action will authenticate using GitHub OIDC—no API keys needed.
1512

16-
```bash
17-
gh secret set STAINLESS_API_KEY
18-
```
13+
**GitLab CI:** OIDC isn't yet supported. Set the `STAINLESS_API_KEY` environment variable instead. See the template files in `build/gitlab-ci.yml`, `merge/gitlab-ci.yml`, and `preview/gitlab-ci.yml`.
14+
15+
**API keys:** If you'd rather use an API key, see [pull_request_api_key.yml](./examples/pull_request_api_key.yml) and add a `STAINLESS_API_KEY` secret to your repo.
1916

20-
In the same repository, add a new workflow file:
17+
## Usage
18+
19+
Add a workflow file to the repository that contains your OpenAPI spec:
2120

2221
<details>
2322
<summary><code>.github/workflows/stainless.yml</code></summary>
@@ -49,6 +48,7 @@ jobs:
4948
permissions:
5049
contents: read
5150
pull-requests: write
51+
id-token: write # Required for GitHub OIDC authentication
5252
steps:
5353
- name: Checkout repository
5454
uses: actions/checkout@v4
@@ -58,7 +58,6 @@ jobs:
5858
- name: Run preview builds
5959
uses: stainless-api/upload-openapi-spec-action/preview@v1
6060
with:
61-
stainless_api_key: ${{ secrets.STAINLESS_API_KEY }}
6261
org: ${{ env.STAINLESS_ORG }}
6362
project: ${{ env.STAINLESS_PROJECT }}
6463
oas_path: ${{ env.OAS_PATH }}
@@ -69,6 +68,7 @@ jobs:
6968
permissions:
7069
contents: read
7170
pull-requests: write
71+
id-token: write # Required for GitHub OIDC authentication
7272
steps:
7373
- name: Checkout repository
7474
uses: actions/checkout@v4
@@ -78,7 +78,6 @@ jobs:
7878
- name: Run merge build
7979
uses: stainless-api/upload-openapi-spec-action/merge@v1
8080
with:
81-
stainless_api_key: ${{ secrets.STAINLESS_API_KEY }}
8281
org: ${{ env.STAINLESS_ORG }}
8382
project: ${{ env.STAINLESS_PROJECT }}
8483
oas_path: ${{ env.OAS_PATH }}
@@ -99,53 +98,31 @@ For more examples of usage, including push-based workflows, using code samples,
9998
integration with docs platforms, and testing preview builds, see the [examples
10099
directory](./examples).
101100

102-
## Actions
103-
104-
This repository provides four GitHub actions.
101+
## Security
105102

106-
- `stainless-api/upload-openapi-spec-action/build`: Build SDKs for a Stainless
107-
project. For information about the input parameters, see the [action definition](./build/action.yml).
103+
If your GitHub repository is public, require approval for workflows from fork PRs to prevent untrusted contributors from accessing OIDC tokens or secrets.
108104

109-
- `stainless-api/upload-openapi-spec-action/preview`: Preview changes to SDKs
110-
introduced by a pull request. For information about the input parameters, see
111-
the [action definition](./preview/action.yml).
105+
Go to **Settings** → **Actions** → **General**, then under "Fork pull request workflows from outside collaborators", select **"Require approval for all outside collaborators"**.
112106

113-
- `stainless-api/upload-openapi-spec-action/merge`: Merge changes to SDKs from
114-
a pull request. For information about the input parameters, see the [action
115-
definition](./merge/action.yml).
107+
See [GitHub's docs](https://docs.github.com/en/actions/managing-workflow-runs/approving-workflow-runs-from-public-forks) for more details.
116108

117-
- `stainless-api/upload-openapi-spec-action/checkout-pr-ref`: Checkout the base
118-
or head commit for previewing a pull request's changes, saving changes to the
119-
config when needed. For information about the input parameters, see the [action
120-
definition](./checkout-pr-ref/action.yml).
109+
## Actions reference
121110

122-
All except for the last action are also usable in GitLab CI.
111+
This repository provides four GitHub actions:
123112

124-
### Testing preview builds
113+
- `stainless-api/upload-openapi-spec-action/build` - Build SDKs for a Stainless project. See the [action definition](./build/action.yml) for input parameters.
125114

126-
The `preview` and `merge` actions output an `install_url` for each SDK language,
127-
which you can use to install and test SDK builds directly from the Stainless
128-
package server. This is useful for running integration tests against preview
129-
builds before merging, or for verifying merged builds. See the
130-
[SDK usage example](./examples/pull_request_sdk_usage.yml) for a complete
131-
workflow.
115+
- `stainless-api/upload-openapi-spec-action/preview` - Preview SDK changes from a pull request. See the [action definition](./preview/action.yml) for input parameters.
132116

133-
### Workflow permissions
117+
- `stainless-api/upload-openapi-spec-action/merge` - Merge SDK changes from a pull request. See the [action definition](./merge/action.yml) for input parameters.
134118

135-
The GitHub actions use the following
136-
[workflow permissions](https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#jobsjob_idpermissions):
119+
- `stainless-api/upload-openapi-spec-action/checkout-pr-ref` - Checkout the base or head commit for previewing changes. See the [action definition](./checkout-pr-ref/action.yml) for input parameters.
137120

138-
- The `preview` and `merge` actions have a `make_comment` input, which, if set,
139-
will comment on the pull request with the build results. This is set to true by
140-
default. The actions use the `github_token` input to make a comment, and the
141-
comment must have the `pull-requests: write` permission.
121+
All except `checkout-pr-ref` work in GitLab CI.
142122

143-
- The `preview` and `checkout-pr-ref` actions rely on being in a Git repository
144-
that can fetch from the remote to determine base revisions. This will be the
145-
case if you use the [`actions/checkout`](https://github.com/actions/checkout)
146-
GitHub action beforehand. That action needs the `contents: read` permission.
123+
The `preview` and `merge` actions output an `install_url` for each SDK language. You can use this to test builds directly from the Stainless package server before merging. See the [SDK usage example](./examples/pull_request_sdk_usage.yml).
147124

148-
### Versioning policy
125+
## Versioning
149126

150127
These actions use [semantic versioning](https://semver.org/), and you can pin
151128
your action to a major (`v1`), minor (`v1.0`), or patch (`v1.0.0`) version.

action.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ runs:
1111
main: dist/index.js
1212
inputs:
1313
stainless_api_key:
14-
description: "Stainless API key."
15-
required: true
14+
description: >-
15+
Stainless API key. Optional for GitHub Actions (will use OIDC authentication
16+
if not provided, requires 'id-token: write' permission). Required for GitLab CI.
17+
required: false
1618
input_path:
1719
description: "Path to the OpenAPI file."
1820
required: true

build/action.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ runs:
1010
# All inputs are also supported in GitLab CI, input as an all-uppercase variable.
1111
inputs:
1212
stainless_api_key:
13-
description: Stainless API key.
14-
required: true
13+
description: >-
14+
Stainless API key. Optional for GitHub Actions (will use OIDC authentication
15+
if not provided, requires 'id-token: write' permission). Required for GitLab CI.
16+
required: false
1517
project:
1618
description: Stainless project name.
1719
required: true

build/gitlab-ci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
image: node:20-alpine
22

33
.build-sdk:
4+
# Required environment variables:
5+
# - STAINLESS_API_KEY: Stainless API key (required for GitLab CI)
6+
# - PROJECT: Stainless project name
7+
# - OAS_PATH: Path to your OpenAPI spec
8+
#
9+
# Optional environment variables:
10+
# - CONFIG_PATH: Path to your Stainless config
11+
# - BRANCH: Stainless branch name (defaults to "main")
12+
# - COMMIT_MESSAGE: Commit message for the SDK build
413
script:
514
- apk add --no-cache git
615
- wget https://raw.githubusercontent.com/stainless-api/upload-openapi-spec-action/v1/dist/build.js

0 commit comments

Comments
 (0)