Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger fern from typescript #363

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/create-sdk-releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ on:
jobs:
run:
runs-on: ubuntu-latest
environment: sdk-release
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -43,4 +44,12 @@ jobs:
GITHUB_REPO: ${{ github.event.repository.name }}
BUMP_TYPE: ${{ github.event.inputs.bump_type }}
LANGUAGE: ${{ github.event.inputs.language }}
FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
MAVEN_CENTRAL_SECRET_KEY_KEY_ID: ${{ secrets.MAVEN_CENTRAL_SECRET_KEY_KEY_ID }}
MAVEN_CENTRAL_SECRET_KEY_PASSWORD: ${{ secrets.MAVEN_CENTRAL_SECRET_KEY_PASSWORD }}
MAVEN_CENTRAL_SECRET_KEY: ${{ secrets.MAVEN_CENTRAL_SECRET_KEY }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: pnpm run --filter autorelease release
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)
])
)

})()
Loading