Skip to content

Commit f5b7645

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

File tree

8 files changed

+568
-76
lines changed

8 files changed

+568
-76
lines changed

.gitlab-ci.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
image: node:20-alpine
2+
3+
.upload-spec:
4+
script:
5+
- yarn install
6+
- node dist/index.js
7+
variables:
8+
STAINLESS_API_KEY: $STAINLESS_API_KEY
9+
INPUT_PATH: $INPUT_PATH
10+
CONFIG_PATH: $CONFIG_PATH
11+
OUTPUT_PATH: $OUTPUT_PATH
12+
PROJECT_NAME: $PROJECT_NAME
13+
COMMIT_MESSAGE: $COMMIT_MESSAGE
14+
GUESS_CONFIG: $GUESS_CONFIG
15+
BRANCH: $BRANCH

README.md

Lines changed: 130 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
@@ -7,7 +7,7 @@ stainless-api/upload-openapi-spec
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)
88
[![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)
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,28 @@ 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-spec
69+
variables:
70+
INPUT_PATH: 'path/to/my-company-openapi.json'
71+
PROJECT_NAME: 'my-stainless-project'
72+
COMMIT_MESSAGE: 'feat(api): my cool feature'
73+
GUESS_CONFIG: 'true'
74+
# CONFIG_PATH: 'path/to/my-company.stainless.yaml' # Optional
75+
# OUTPUT_PATH: 'path/to/output.json' # Optional
76+
# BRANCH: 'main' # Optional
77+
```
78+
5379
You can identify your Stainless project name on the [Stainless dashboard](https://app.stainless.com/).
5480

5581
### Optional parameters
@@ -75,7 +101,9 @@ openapi:
75101
code_samples: readme
76102
```
77103

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

80108
```yaml
81109
name: Upload OpenAPI spec to Stainless and ReadMe
@@ -111,6 +139,46 @@ This assumes the following secrets have been [uploaded to your GitHub Actions Se
111139

112140
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).
113141

142+
### GitLab CI with ReadMe
143+
144+
Configure your GitLab CI pipeline to upload the Stainless-enhanced OpenAPI spec to ReadMe:
145+
146+
```yaml
147+
include:
148+
- remote: 'https://raw.githubusercontent.com/stainless-api/upload-openapi-spec-action/main/.gitlab-ci.yml'
149+
150+
stages:
151+
- upload
152+
- sync
153+
154+
upload-openapi-spec:
155+
stage: upload
156+
extends: .upload-spec
157+
variables:
158+
INPUT_PATH: 'path/to/my-company-openapi.json'
159+
OUTPUT_PATH: 'path/to/my-company-openapi.documented.json'
160+
PROJECT_NAME: 'my-stainless-project'
161+
COMMIT_MESSAGE: 'feat(api): my cool feature'
162+
artifacts:
163+
paths:
164+
- path/to/my-company-openapi.documented.json
165+
166+
sync-to-readme:
167+
stage: sync
168+
image: node:20-alpine
169+
script:
170+
- npm install -g rdme
171+
- rdme openapi path/to/my-company-openapi.documented.json --key=$README_TOKEN --id=$README_DEFINITION_ID
172+
dependencies:
173+
- upload-openapi-spec
174+
```
175+
176+
This assumes the following variables have been added to your GitLab CI/CD Variables:
177+
178+
- `STAINLESS_API_KEY`: Your Stainless API key.
179+
- `README_TOKEN`: Your ReadMe API key.
180+
- `README_DEFINITION_ID`: Your ReadMe API definition ID.
181+
114182
## Usage with Mintlify for docs with example snippets
115183

116184
If you use Mintlify's OpenAPI support for your API reference documentation,
@@ -121,7 +189,11 @@ openapi:
121189
code_samples: mintlify
122190
```
123191

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:
192+
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).
193+
194+
### GitHub Actions with Mintlify
195+
196+
To integrate Stainless with your GitHub Actions workflow:
125197

126198
```yaml
127199
name: Upload OpenAPI spec to Stainless and (Mintlify) docs repo
@@ -161,3 +233,56 @@ This assumes the following secrets have been [uploaded to your GitHub Actions Se
161233

162234
- `secrets.STAINLESS_API_KEY`: Your Stainless API key.
163235
- `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.
236+
237+
### GitLab CI with Mintlify
238+
239+
To integrate Stainless with your GitLab CI pipeline:
240+
241+
```yaml
242+
include:
243+
- remote: 'https://raw.githubusercontent.com/stainless-api/upload-openapi-spec-action/main/.gitlab-ci.yml'
244+
245+
stages:
246+
- upload
247+
- push-docs
248+
249+
upload-openapi-spec:
250+
stage: upload
251+
extends: .upload-spec
252+
variables:
253+
INPUT_PATH: 'path/to/my-company-openapi.json'
254+
OUTPUT_PATH: 'path/to/my-company-openapi.documented.json'
255+
PROJECT_NAME: 'my-stainless-project'
256+
COMMIT_MESSAGE: 'feat(api): my cool feature'
257+
artifacts:
258+
paths:
259+
- path/to/my-company-openapi.documented.json
260+
261+
push-to-docs-repo:
262+
stage: push-docs
263+
image: alpine:latest
264+
script:
265+
- apk add --no-cache git openssh
266+
- mkdir -p ~/.ssh
267+
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
268+
- chmod 600 ~/.ssh/id_rsa
269+
- ssh-keyscan gitlab.com >> ~/.ssh/known_hosts
270+
- git config --global user.email "$GIT_USER_EMAIL"
271+
- git config --global user.name "$GIT_USER_NAME"
272+
- git clone git@gitlab.com:your-organization/docs-repo.git
273+
- mkdir -p docs-repo/openapi-specs
274+
- cp path/to/my-company-openapi.documented.json docs-repo/openapi-specs/
275+
- cd docs-repo
276+
- git add openapi-specs/my-company-openapi.documented.json
277+
- git commit -m "Auto-updates from Stainless"
278+
- git push origin main
279+
dependencies:
280+
- upload-openapi-spec
281+
```
282+
283+
This assumes the following variables have been added to your GitLab CI/CD Variables:
284+
285+
- `STAINLESS_API_KEY`: Your Stainless API key.
286+
- `SSH_PRIVATE_KEY`: An SSH private key with permissions to push to your docs repo.
287+
- `GIT_USER_EMAIL`: The email to use for the Git commits.
288+
- `GIT_USER_NAME`: The username to use for the Git commits.

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)