Skip to content

Commit d30490c

Browse files
authored
feat(preview): add output_dir input and write documented spec to file (#137)
1 parent 5e80cc4 commit d30490c

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

examples/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ In the examples, the push workflow is configured to use a generic commit message
3838

3939
## Integration with docs platforms
4040

41-
If your Stainless config has code samples configured, the `merge` and `build` actions also output a `documented_spec_path` containing a path to your OpenAPI spec with SDK code samples.
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.
4242

4343
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.
4444

package-lock.json

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

preview/action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ inputs:
9595
as the merge action's `merge_branch` input.
9696
required: false
9797
default: ${{ format('preview/{0}', github.event.pull_request.head.ref) }}
98+
output_dir:
99+
description: >-
100+
Directory to write output files to. Defaults to the runner's temporary
101+
directory.
102+
required: false
103+
default: ${{ runner.temp }}
98104

99105
outputs:
100106
outcomes:

src/preview.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
getStainlessAuthToken,
1111
} from "./compat";
1212
import { Stainless } from "@stainless-api/sdk";
13+
import * as fs from "node:fs";
1314
import {
1415
commentThrottler,
1516
printComment,
@@ -50,6 +51,7 @@ async function main() {
5051
const defaultBranch = getInput("default_branch", { required: true });
5152
const headSha = getInput("head_sha", { required: true });
5253
const branch = getInput("branch", { required: true });
54+
const outputDir = getInput("output_dir", { required: false }) || undefined;
5355
const prNumber = getPRNumber();
5456

5557
// If we came from the checkout-pr-ref action, we might need to save the
@@ -195,11 +197,18 @@ async function main() {
195197
throw new Error("No latest run found after build finish");
196198
}
197199

198-
const { outcomes, baseOutcomes } = latestRun!;
200+
const { outcomes, baseOutcomes, documentedSpec } = latestRun!;
199201

200202
setOutput("outcomes", outcomes);
201203
setOutput("base_outcomes", baseOutcomes);
202204

205+
if (documentedSpec && outputDir) {
206+
const documentedSpecPath = `${outputDir}/openapi.documented.yml`;
207+
fs.mkdirSync(outputDir, { recursive: true });
208+
fs.writeFileSync(documentedSpecPath, documentedSpec);
209+
setOutput("documented_spec_path", documentedSpecPath);
210+
}
211+
203212
if (!shouldFailRun({ failRunOn, outcomes, baseOutcomes })) {
204213
process.exit(1);
205214
}

0 commit comments

Comments
 (0)