Skip to content

Commit d593899

Browse files
committed
feat: add gitlab CI support
1 parent 57217b0 commit d593899

8 files changed

Lines changed: 511 additions & 77 deletions

File tree

.gitlab-ci.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# This file defines reusable GitLab CI component for uploading OpenAPI specs to Stainless
2+
3+
image: node:20-alpine
4+
5+
.upload-openapi-spec:
6+
script:
7+
- apk add --no-cache git
8+
- git clone https://github.com/stainless-api/upload-openapi-spec-action.git
9+
- cd upload-openapi-spec-action
10+
- yarn install
11+
- node dist/index.js
12+
variables:
13+
INPUT_STAINLESS_API_KEY: $STAINLESS_API_KEY
14+
INPUT_INPUT_PATH: $INPUT_PATH
15+
INPUT_CONFIG_PATH: $CONFIG_PATH
16+
INPUT_OUTPUT_PATH: $OUTPUT_PATH
17+
INPUT_PROJECT_NAME: $PROJECT_NAME
18+
INPUT_COMMIT_MESSAGE: $COMMIT_MESSAGE
19+
INPUT_GUESS_CONFIG: $GUESS_CONFIG
20+
INPUT_BRANCH: $BRANCH

README.md

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# GitHub Action: upload your OpenAPI spec to Stainless
1+
# Upload your OpenAPI spec to Stainless (GitHub Action & GitLab CI)
22

33
```
44
stainless-api/upload-openapi-spec
55
```
66

77
[![lint](https://github.com/stainless-api/upload-openapi-spec-action/actions/workflows/lint.yml/badge.svg)](https://github.com/stainless-api/upload-openapi-spec-action/actions/workflows/lint.yml)
8-
[![build](https://github.com/stainless-api/upload-openapi-spec-action/actions/workflows/build.yml/badge.svg)](https://github.com/stainless-apiupload-openapi-spec-action/actions/workflows/build.yml)
8+
[![build](https://github.com/stainless-api/upload-openapi-spec-action/actions/workflows/build.yml/badge.svg)](https://github.com/stainless-api/upload-openapi-spec-action/actions/workflows/build.yml)
99

10-
A GitHub Action for pushing your OpenAPI spec to [Stainless](https://stainless.com/) to trigger regeneration of your SDKs.
10+
A CI component for pushing your OpenAPI spec to [Stainless](https://stainless.com/) to trigger regeneration of your SDKs. Supports both GitHub Actions and GitLab CI.
1111

1212
Note that there is currently a manual step in between this action and automatic creation of your PR's,
1313
and more manual steps before they are merged and released.
@@ -18,7 +18,11 @@ so that your API reference documentation can show examples of making each reques
1818

1919
## Example usage
2020

21-
First, obtain an API Key from your Stainless dashboard, and [add it to your GitHub Actions secrets](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository) as `STAINLESS_API_KEY`:
21+
First, obtain an API Key from your Stainless dashboard.
22+
23+
### GitHub Actions
24+
25+
For GitHub Actions, [add the API key to your repository secrets](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository) as `STAINLESS_API_KEY`:
2226

2327
```
2428
gh secret set STAINLESS_API_KEY
@@ -50,6 +54,29 @@ jobs:
5054
5155
You can optionally add `config_path: 'path/to/my-company.stainless.yaml'` to the `with:` block if you'd like to send us updates to your Stainless config.
5256

57+
### GitLab CI
58+
59+
For GitLab CI, add the API key to your [GitLab CI/CD variables](https://docs.gitlab.com/ee/ci/variables/#add-a-cicd-variable-to-a-project) as `STAINLESS_API_KEY`.
60+
61+
Then, add the following to your `.gitlab-ci.yml` file:
62+
63+
```yaml
64+
include:
65+
- remote: 'https://raw.githubusercontent.com/stainless-api/upload-openapi-spec-action/main/.gitlab-ci.yml'
66+
67+
upload-openapi-spec:
68+
extends: .upload-openapi-spec
69+
variables:
70+
STAINLESS_API_KEY: "$STAINLESS_API_KEY"
71+
INPUT_PATH: '$CI_PROJECT_DIR/path/to/my-company-openapi.json'
72+
PROJECT_NAME: 'my-stainless-project'
73+
COMMIT_MESSAGE: 'feat(api): my cool feature'
74+
GUESS_CONFIG: 'true'
75+
# CONFIG_PATH: '$CI_PROJECT_DIR/path/to/my-company.stainless.yaml' # Optional
76+
# OUTPUT_PATH: '$CI_PROJECT_DIR/path/to/output.json' # Optional
77+
# BRANCH: 'main' # Optional
78+
```
79+
5380
You can identify your Stainless project name on the [Stainless dashboard](https://app.stainless.com/).
5481

5582
### Optional parameters
@@ -75,7 +102,9 @@ openapi:
75102
code_samples: readme
76103
```
77104

78-
Then configure your GitHub Action to upload the Stainless-enhanced OpenAPI spec to ReadMe:
105+
### GitHub Actions with ReadMe
106+
107+
Configure your GitHub Action to upload the Stainless-enhanced OpenAPI spec to ReadMe:
79108

80109
```yaml
81110
name: Upload OpenAPI spec to Stainless and ReadMe
@@ -111,6 +140,7 @@ This assumes the following secrets have been [uploaded to your GitHub Actions Se
111140

112141
Remember to set the `readmeio/rdme` ref version to the latest stable available (`v8`, as of this writing). You can verify the latest version of ReadMe's GitHub Action [here](https://github.com/marketplace/actions/rdme-sync-to-readme).
113142

143+
114144
## Usage with Mintlify for docs with example snippets
115145

116146
If you use Mintlify's OpenAPI support for your API reference documentation,
@@ -121,7 +151,11 @@ openapi:
121151
code_samples: mintlify
122152
```
123153

124-
Mintlify can generate your docs based on the OpenAPI spec in your docs repo if it is [configured to do so](https://mintlify.com/docs/api-playground/openapi/setup#in-the-repo). To integrate Stainless, you can modify the GitHub Action that uploads your OpenAPI spec to Stainless such that it then pushes the Stainless-enhanced OpenAPI spec into your docs repo:
154+
Mintlify can generate your docs based on the OpenAPI spec in your docs repo if it is [configured to do so](https://mintlify.com/docs/api-playground/openapi/setup#in-the-repo).
155+
156+
### GitHub Actions with Mintlify
157+
158+
To integrate Stainless with your GitHub Actions workflow:
125159

126160
```yaml
127161
name: Upload OpenAPI spec to Stainless and (Mintlify) docs repo
@@ -161,3 +195,4 @@ This assumes the following secrets have been [uploaded to your GitHub Actions Se
161195

162196
- `secrets.STAINLESS_API_KEY`: Your Stainless API key.
163197
- `secrets.API_TOKEN_GITHUB`: A GitHub [Personal Access Token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens) with permissions to push to your docs repo.
198+

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Stainless — Upload OpenAPI specification
2-
description: Upload your OpenAPI spec to update your Stainless SDKs (and, if configured, add example snippets to your API docs)
2+
description: Upload your OpenAPI spec to update your Stainless SDKs (and, if configured, add example snippets to your API docs). Works with GitHub Actions and GitLab CI.
33
branding:
44
icon: book-open
55
color: green

0 commit comments

Comments
 (0)