You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: use combined build action in examples (#206)
* docs: use combined build action in examples
* update example readme
* Apply suggestions from code review
Co-authored-by: Justin Michael <justin@stainless.com>
---------
Co-authored-by: Justin Michael <justin@stainless.com>
Copy file name to clipboardExpand all lines: README.md
+16-45Lines changed: 16 additions & 45 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,7 @@ workflow run that can be validated by Stainless.
25
25
**API keys:** Generate an API key from your Stainless organization dashboard and add it as a `STAINLESS_API_KEY` secret. This works well for getting started or when you don't have admin permissions to install the GitHub App. See [pull_request_api_key.yml](./examples/pull_request_api_key.yml) for the workflow setup.
26
26
27
27
> [!NOTE]
28
-
> **GitLab CI:** OIDC isn't yet supported. Use the API key method and set the `STAINLESS_API_KEY` environment variable. See the template files in `build/gitlab-ci.yml`, `merge/gitlab-ci.yml`, and `preview/gitlab-ci.yml`.
28
+
> **GitLab CI:** OIDC isn't yet supported. Use the API key method and set the `STAINLESS_API_KEY` environment variable. See the template files in `build/gitlab-ci.yml`.
29
29
30
30
## Usage
31
31
@@ -35,18 +35,17 @@ Add a workflow file to the repository that contains your OpenAPI spec:
For more examples of usage, including push-based workflows, using code samples,
111
86
integration with docs platforms, and testing preview builds, see the [examples
@@ -116,11 +91,11 @@ directory](./examples).
116
91
117
92
The workflows require the following [permissions](https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#jobsjob_idpermissions):
118
93
119
-
- **`id-token: write`** - Required for GitHub OIDC authentication. Allows the workflow to request an OIDC token from GitHub.
94
+
- **`contents: read`** - Required for checking out the repository code to read the OpenAPI spec and config files.
120
95
121
-
- **`pull-requests: write`** - Required for posting comments on pull requests with build results. If you don't need comments, you can set `make_comment: false` and remove this permission.
96
+
- **`pull-requests: write`** - Required for posting comments on pull requests with build results. If you don't need comments, you can set `make_comment: false` and set the permission to `pull-requests: read`.
122
97
123
-
- **`contents: read`** - Required for checking out the repository code to read the OpenAPI spec and config files.
98
+
- **`id-token: write`** - Required for GitHub OIDC authentication. Allows the workflow to request an OIDC token from GitHub.
124
99
125
100
</details>
126
101
@@ -142,10 +117,6 @@ This repository provides several GitHub actions:
142
117
143
118
- `stainless-api/upload-openapi-spec-action/build`- Build SDKs for a Stainless project. See the [action definition](./build/action.yml) for input parameters.
144
119
145
-
- `stainless-api/upload-openapi-spec-action/preview`- Preview SDK changes from a pull request. See the [action definition](./preview/action.yml) for input parameters.
146
-
147
-
- `stainless-api/upload-openapi-spec-action/merge`- Merge SDK changes from a pull request. See the [action definition](./merge/action.yml) for input parameters.
148
-
149
120
- `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.
150
121
151
122
### Preparation Tools
@@ -156,7 +127,7 @@ This repository provides several GitHub actions:
156
127
157
128
All except `checkout-pr-ref` work in GitLab CI.
158
129
159
-
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).
130
+
The `build` action outputs 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).
Copy file name to clipboardExpand all lines: examples/README.md
+16-14Lines changed: 16 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,18 @@
1
1
# Example workflows
2
2
3
-
There's two kinds of workflows, depending on how you manage your GitHub repo. Both workflows require you to provide your Stainless org and project names.
3
+
All workflows require you to provide your Stainless org and project names.
4
4
5
5
For authentication setup, see the [Authentication section](../README.md#authentication) in the main README.
6
6
7
-
## Pull request workflows
7
+
## GitHub Actions
8
8
9
-
The main kind of workflows are the pull-request-based workflows, such as [pull_request.yml](./pull_request.yml). If all changes to your OpenAPI spec are made via pull requests, we recommend using this workflow. It has two jobs:
9
+
We recommend you use [push.yml](./push.yml). It has a single `build` job that runs when you create or update pull requests and when you push to your main branch. It can also be triggered manually if needed. For pull requests, the `build` job creates a build of your SDK using the changes that will be introduced by the pull request, then it adds a comment to the pull request with links to a GitHub diff and installation commands. For pushes to your main branch, the `build` job creates a build of the SDK with the pushed changes.
10
10
11
-
-`preview`, which runs when a pull request is opened or updated. The job creates a build of your SDK which includes only the changes introduced by the pull request. It also makes a comment on the pull request, with links to a GitHub diff, and installation commands for trying out your SDK.
11
+
By default, the pull request workflow uses the title of the pull request as the commit message, but you can edit the comment on the pull requestto change the commit message.
12
12
13
-
-`merge`, which runs when a pull request is merged. The job creates a build of the SDK with the changes from the pull request, along with any [custom code](https://app.stainless.com/docs/guides/patch-custom-code#project-branches) added to the preview build.
13
+
### API key authentication
14
14
15
-
By default, the pull request workflow uses the title of the pull request as the commit message, but you can edit the comment on the pull request to change the commit message.
15
+
If you prefer to authenticate with an API key instead of OIDC, use [pull_request_api_key.yml](./pull_request_api_key.yml).
16
16
17
17
### Fork pull requests
18
18
@@ -26,23 +26,25 @@ The workflow explicitly checks out the PR's code to read the OpenAPI spec. This
26
26
27
27
If your OpenAPI spec is generated from your GitHub repo, via a shell script or other GitHub action, you will need to do some extra setup. This is because the action needs access to both the old OpenAPI spec and the new OpenAPI spec. See the example at [pull_request_generated.yml](./pull_request_generated.yml).
28
28
29
-
Here, `checkout-pr-ref` will checkout the relevant base Git commit. The first command runs against the base Git commit, generating the old OpenAPI spec. Then, `checkout-pr-ref` will checkout the relevant head Git commit. The second command runs against the head Git commit, generating the new OpenAPI spec.
29
+
Here, `checkout-pr-ref` will checkout the relevant base Git commit. The first command runs against the base Git commit, generating the old OpenAPI spec. Then, `checkout-pr-ref` will checkout the relevant head Git commit. The second command runs against the head Git commit, generating the new OpenAPI spec. These steps are conditioned on pull request events; on pushes to your main branch, only the current spec is needed.
30
+
31
+
### Using SDK build outputs
30
32
31
-
## Push workflows
33
+
If you want to install and test SDK builds as part of your workflow, see [pull_request_sdk_usage.yml](./pull_request_sdk_usage.yml). This example demonstrates how to extract the `install_url` from the build outputs and use it to install the SDK for integration testing.
32
34
33
-
The other kind of workflows are the push-based workflows, such as [push.yml](./push.yml). If for some reason you can't use the pull-request-based workflows, you can use this workflow. It has one job:
35
+
## GitLab CI
34
36
35
-
-`build`, which runs when a commit is pushed to a branch you specify. The job creates a build of your SDK against the latest commit on that branch.
37
+
For GitLab projects, add the configuration from [push_gitlab.yml](./push_gitlab.yml)to your `.gitlab-ci.yml` file. The workflow uses a single `build-sdk` job that runs on merge requests and pushes to your main branch.
36
38
37
-
In the examples, the push workflow is configured to use a generic commit message. You can change this to the message of the pushed commit by using `${{ github.event.head_commit.message }}`.
39
+
If your OpenAPI spec is in a GitLab repo, see [merge_request_gitlab_generated.yml](./merge_request_gitlab_generated.yml) for additional instructions.
38
40
39
41
## Integration with docs platforms
40
42
41
-
If your Stainless config has code samples configured, the `preview`, `merge`, and `build`actions also output a `documented_spec_path` containing a path to your OpenAPI spec with SDK code samples.
43
+
If your Stainless config has code samples configured, the `build`action also outputs a `documented_spec_path` containing a path to a version of your OpenAPI spec with SDK code samples included.
42
44
43
-
If you sync your OpenAPI spec with a [ReadMe API Reference](https://readme.com/), you can use the [Sync to ReadMe](https://github.com/marketplace/actions/rdme-sync-to-readme) GitHub action to upload the documented spec to ReadMe. You can see examples of this in the [pull_request_readme.yml](./pull_request_readme.yml) and [push_readme.yml](./push_readme.yml)files.
45
+
If you sync your OpenAPI spec with a [ReadMe API Reference](https://readme.com/), use the [Sync to ReadMe](https://github.com/marketplace/actions/rdme-sync-to-readme) GitHub action to upload the documented spec to ReadMe. We have examples in the [push_readme.yml](./push_readme.yml)file.
44
46
45
-
If you use [Mintlify's OpenAPI support](https://mintlify.com/docs/api-playground/openapi-setup#in-the-repo) for your API reference documentation, you can copy the documented spec to your Mintlify docs repo to update it. You can see examples of this in the [pull_request_mintlify.yml](./pull_request_mintlify.yml) and [push_mintlify.yml](./push_mintlify.yml)files.
47
+
If you use [Mintlify's OpenAPI support](https://mintlify.com/docs/api-playground/openapi-setup#in-the-repo) for your API reference documentation, copy the documented spec to your Mintlify docs repo to update it. We have examples in the [push_mintlify.yml](./push_mintlify.yml)file.
0 commit comments