Skip to content
Merged
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
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
111 changes: 69 additions & 42 deletions fern/products/sdks/overview/typescript/publishing-to-npm.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,17 @@ groups:

</Steps>

## Configure npm authentication
## Configure npm publication

Choose how you want to authenticate and publish your SDK to npm. You can use GitHub workflows for automated releases or publish directly via the CLI.

<AccordionGroup>
<Accordion title="Option 1: Configure authentication via GitHub Actions">
<Accordion title="Release via a GitHub workflow (recommended)">

Use [GitHub Actions](https://docs.github.com/en/actions/get-started/quickstart) to automatically publish new SDK versions to npm when you push code changes.
Set up a release workflow via [GitHub Actions](https://docs.github.com/en/actions/get-started/quickstart) so you can trigger new SDK releases directly from your repository.

<Steps>

<Step title="Navigate to Actions in Settings">
<Step title="Set up authentication">

Open your Fern repository in GitHub. Click on the **Settings** tab in your repository. Then, under the **Security** section, open **Secrets and variables** > **Actions**.

Expand All @@ -182,7 +183,6 @@ Use [GitHub Actions](https://docs.github.com/en/actions/get-started/quickstart)
You can also use the url `https://github.com/<your-repo>/settings/secrets/actions`.

</Step>

<Step title="Add secret for your npm Token">

1. Select **New repository secret**.
Expand All @@ -195,43 +195,70 @@ Use [GitHub Actions](https://docs.github.com/en/actions/get-started/quickstart)
</Frame>

</Step>
<Step title="Add secret for your Fern Token">

<Step title="Allow GitHub to run workflows">

Change your workflow permissions to allow GitHub to run workflows:
1. Select **New repository secret**.
1. Name your secret `FERN_TOKEN`.
1. Add your Fern token. If you don't already have one, generate one by running
`fern-token`. By default, the `fern_token` is generated for the organization
listed in `fern.config.json`.
1. Click **Add secret**.

1. Click on the **Settings** tab in your repository.
1. Under the **Code and automation** section, navigate to **Actions** > **General**.
1. Under **Actions permissions**, select **Allow all actions and reusable workflows**.
1. **Save** your settings. Now GitHub can run the actions you configure.
<Frame>
<img src="assets/npm-token-secret.png" alt="NPM_TOKEN secret" />
</Frame>

</Step>
<Step title="Add token to `generators.yml`">

Add `token: ${NPM_TOKEN}` to `generators.yml` to tell Fern to use the `NPM_TOKEN` environment variable (which you just configured in your GitHub repo) for authentication when publishing to the npm registry.

```yaml {9}
groups:
ts-sdk:
generators:
- name: fernapi/fern-typescript-sdk
version: <Markdown src="/snippets/typescript-sdk-version.mdx"/>
output:
location: npm
package-name: name-of-your-package
token: ${NPM_TOKEN}
config:
namespaceExport: YourClientName
github:
repository: your-org/your-repository
<Step title="Set up a new workflow">

In your repo, navigate to **Actions**. Select **New workflow**, then **Set up workflow yourself**. Set up a workflow dispatch that is similar to this:

```yaml title=".github/workflows/publish.yml" maxLines=0
name: Publish TypeScript SDK

on:
workflow_dispatch:
inputs:
version:
description: "The version of the TypeScript SDK that you would like to release"
required: true
type: string

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Install Fern CLI
run: npm install -g fern-api

- name: Release TypeScript SDK
env:
FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
fern generate --group ts-sdk --version ${{ inputs.version }} --log-level debug
```
</Step>
<Step title="Run your workflow">

When you regenerate your release, Fern will automatically create a workflow in your repository called `.github/workflows/ci.yml` that will automatically publish your release to npm. For an example, see Vapi's [npm publishing GitHub Action](https://github.com/VapiAI/server-sdk-typescript/blob/main/.github/workflows/ci.yml)
Navigate to the **Actions** tab, select the workflow you just created, and
click **Run workflow**.

<Frame>
<img src="assets/ts-sdk-release-action.png" alt="Running TS publish workflow" />
</Frame>

Once your workflow completes, log back into npm and
navigate to **Packages** to see your new release.

</Step>
</Steps>

</Accordion>
<Accordion title="Option 2: Configure via environment variables">
<Accordion title="Release via CLI and environment variables">
<Steps>
<Step title="Configure npm authentication token">

Expand All @@ -252,6 +279,8 @@ groups:
github:
repository: your-org/your-repository
```

When you regenerate your release, Fern will automatically create a workflow in your repository called `.github/workflows/ci.yml` that will automatically publish your release to npm. For an example, see Vapi's [npm publishing GitHub Action](https://github.com/VapiAI/server-sdk-typescript/blob/main/.github/workflows/ci.yml)
</Step>
<Step title="Set npm environment variable">

Expand All @@ -262,19 +291,17 @@ groups:
```

</Step>
</Steps>
</Accordion>
</AccordionGroup>

<Step title="Regenerate your SDK">


## Release your SDK to npm

Regenerate your SDK and publish it on npm:

```bash
fern generate --group ts-sdk --version <version>
```
Local machine output will verify that the release is pushed to your
repository and tagged with the version you specified. Log back into npm and
navigate to **Packages** to see your new release.
navigate to **Packages** to see your new release.

</Step>
</Steps>
</Accordion>
</AccordionGroup>
2 changes: 1 addition & 1 deletion fern/products/sdks/sdks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ navigation:
- page: Configuration
path: ./overview/typescript/configuration.mdx
slug: configuration
- page: Publishing to NPM
- page: Publishing to npm
path: ./overview/typescript/publishing-to-npm.mdx
slug: publishing
- page: Adding custom code
Expand Down