Skip to content

Commit

Permalink
Trigger fern from typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
billytrend-cohere committed Jan 16, 2025
1 parent f7d729e commit 5211849
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
8 changes: 4 additions & 4 deletions fern/apis/sdks/generators.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
api:
path: ../../../cohere-openapi.yaml
groups:
node-sdk:
typescript:
audiences:
- public
- v2-beta
Expand Down Expand Up @@ -36,7 +36,7 @@ groups:
"@aws-sdk/signature-v4": "^3.374.0"
"convict": "^6.2.4"

go-sdk:
go:
audiences:
- public
- v2-beta
Expand All @@ -49,7 +49,7 @@ groups:
config:
union: v1
includeLegacyClientOptions: true
java-sdk:
java:
audiences:
- public
- v2-beta
Expand Down Expand Up @@ -77,7 +77,7 @@ groups:
license: MIT
config:
client-class-name: Cohere
python-sdk:
python:
audiences:
- public
- v2-beta
Expand Down
41 changes: 40 additions & 1 deletion packages/autorelease/src/create-releases.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
import { Octokit } from "@octokit/rest"
import * as childProcess from "child_process"

export const execCmd = async (cmd: string, cwd: string): Promise<{error: null | childProcess.ExecException, stderr: string, stdout: string}> => {
return new Promise((resolve, reject) => {
try {
childProcess.exec(cmd, {cwd}, (error, stdout, stderr) => {
if (error) {
resolve({error, stderr, stdout})
}
resolve({ error, stderr, stdout})
})
} catch (error) {
resolve({error, stderr: '', stdout: ''})
}
})
}

const versionMatchRegex = /v?(\d+\.\d+\.\d+)/g

Expand Down Expand Up @@ -141,6 +157,25 @@ const createRelease = async (language: typeof languages[number], version: string
})
}

const runFernGenerate = async (language: typeof languages[number], version: string) => {
const command = `fern generate --api sdks --group ${language} --version "${version}" --log-level debug`

const { error, stderr, stdout } = await execCmd(command, process.cwd())

if (stderr) {
console.error(stderr)
}

if (stdout) {
console.log(stdout)
}

if (error) {
console.error(`Error running fern generate for ${language}@${version}`)
throw error
}
}

(async () => {
const bumpType = process.env.BUMP_TYPE as typeof bumpTypes[number] | undefined
const language = process.env.LANGUAGE as typeof languages[number] | "all" | undefined
Expand All @@ -158,6 +193,10 @@ const createRelease = async (language: typeof languages[number], version: string
await Promise.all(
languages
.filter(l => language === "all" ? true : l === language)
.map(async language => createRelease(language, nextVersions[language].next))
.flatMap(async language => [
createRelease(language, nextVersions[language].next),
runFernGenerate(language, nextVersions[language].next)
])
)

})()

0 comments on commit 5211849

Please sign in to comment.