Skip to content

Commit a5cd583

Browse files
committed
update npm publishing guide
1 parent d423e42 commit a5cd583

File tree

1 file changed

+81
-55
lines changed

1 file changed

+81
-55
lines changed

fern/products/sdks/overview/typescript/publishing-to-npm.mdx

Lines changed: 81 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ Set up a release workflow via [GitHub Actions](https://docs.github.com/en/action
185185
</Step>
186186
<Step title="Add secret for your npm Token">
187187

188-
1. Select **New repository secret**.
189-
1. Name your secret `NPM_TOKEN`.
190-
1. Add the corresponding token you generated above.
191-
1. Click **Add secret**.
188+
1. Select **New repository secret**.
189+
1. Name your secret `NPM_TOKEN`.
190+
1. Add the corresponding token you generated above.
191+
1. Click **Add secret**.
192192

193193
<Frame>
194194
<img src="assets/npm-token-secret.png" alt="NPM_TOKEN secret" />
@@ -197,12 +197,12 @@ Set up a release workflow via [GitHub Actions](https://docs.github.com/en/action
197197
</Step>
198198
<Step title="Add secret for your Fern Token">
199199

200-
1. Select **New repository secret**.
201-
1. Name your secret `FERN_TOKEN`.
202-
1. Add your Fern token. If you don't already have one, generate one by running
203-
`fern-token`. By default, the `fern_token` is generated for the organization
204-
listed in `fern.config.json`.
205-
1. Click **Add secret**.
200+
1. Select **New repository secret**.
201+
1. Name your secret `FERN_TOKEN`.
202+
1. Add your Fern token. If you don't already have one, generate one by
203+
running `fern token`. By default, the `fern_token` is generated for the
204+
organization listed in `fern.config.json`.
205+
1. Click **Add secret**.
206206

207207
<Frame>
208208
<img src="assets/npm-token-secret.png" alt="NPM_TOKEN secret" />
@@ -211,45 +211,71 @@ Set up a release workflow via [GitHub Actions](https://docs.github.com/en/action
211211
</Step>
212212
<Step title="Set up a new workflow">
213213

214-
In your repo, navigate to **Actions**. Select **New workflow**, then **Set up workflow yourself**. Set up a workflow dispatch that is similar to this:
214+
In your repo, navigate to **Actions**. Select **New workflow**, then **Set up workflow yourself**. Set up a CI workflow that automatically publishes on tagged pushes:
215215

216216
```yaml title=".github/workflows/publish.yml" maxLines=0
217217
name: Publish TypeScript SDK
218218
219-
on:
220-
workflow_dispatch:
221-
inputs:
222-
version:
223-
description: "The version of the TypeScript SDK that you would like to release"
224-
required: true
225-
type: string
219+
on: [push]
226220
227221
jobs:
228-
release:
229-
runs-on: ubuntu-latest
230-
steps:
231-
- name: Checkout repo
232-
uses: actions/checkout@v4
233-
234-
- name: Install Fern CLI
235-
run: npm install -g fern-api
236-
237-
- name: Release TypeScript SDK
238-
env:
239-
FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
240-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
241-
run: |
242-
fern generate --group ts-sdk --version ${{ inputs.version }} --log-level debug
222+
compile:
223+
runs-on: ubuntu-latest
224+
225+
steps:
226+
- name: Checkout repo
227+
uses: actions/checkout@v3
228+
229+
- name: Set up node
230+
uses: actions/setup-node@v3
231+
232+
- name: Compile
233+
run: yarn && yarn build
234+
235+
test:
236+
runs-on: ubuntu-latest
237+
238+
steps:
239+
- name: Checkout repo
240+
uses: actions/checkout@v3
241+
242+
- name: Set up node
243+
uses: actions/setup-node@v3
244+
245+
- name: Compile
246+
run: yarn && yarn test
247+
248+
publish:
249+
needs: [ compile ]
250+
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
251+
runs-on: ubuntu-latest
252+
steps:
253+
- name: Checkout repo
254+
uses: actions/checkout@v3
255+
- name: Set up node
256+
uses: actions/setup-node@v3
257+
- name: Install dependencies
258+
run: yarn install
259+
- name: Build
260+
run: yarn build
261+
262+
- name: Publish to npm
263+
run: |
264+
npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
265+
if [[ ${GITHUB_REF} == *alpha* ]]; then
266+
npm publish --access public --tag alpha
267+
elif [[ ${GITHUB_REF} == *beta* ]]; then
268+
npm publish --access public --tag beta
269+
else
270+
npm publish --access public
271+
fi
272+
env:
273+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
243274
```
244275
</Step>
245-
<Step title="Run your workflow">
276+
<Step title="Trigger a release">
246277

247-
Navigate to the **Actions** tab, select the workflow you just created, and
248-
click **Run workflow**.
249-
250-
<Frame>
251-
<img src="assets/ts-sdk-release-action.png" alt="Running TS publish workflow" />
252-
</Frame>
278+
To trigger a release, create and push a git tag to your repository. The workflow will automatically run and publish your package to npm.
253279
254280
Once your workflow completes, log back into npm and
255281
navigate to **Packages** to see your new release.
@@ -264,21 +290,21 @@ Set up a release workflow via [GitHub Actions](https://docs.github.com/en/action
264290

265291
Add `token: ${NPM_TOKEN}` to `generators.yml` to tell Fern to use the `NPM_TOKEN` environment variable for authentication when publishing to the npm registry.
266292

267-
```yaml {9}
268-
groups:
269-
ts-sdk:
270-
generators:
271-
- name: fernapi/fern-typescript-sdk
272-
version: <Markdown src="/snippets/typescript-sdk-version.mdx"/>
273-
output:
274-
location: npm
275-
package-name: name-of-your-package
276-
token: ${NPM_TOKEN}
277-
config:
278-
namespaceExport: YourClientName
279-
github:
280-
repository: your-org/your-repository
281-
```
293+
```yaml {9}
294+
groups:
295+
ts-sdk:
296+
generators:
297+
- name: fernapi/fern-typescript-sdk
298+
version: <Markdown src="/snippets/typescript-sdk-version.mdx"/>
299+
output:
300+
location: npm
301+
package-name: name-of-your-package
302+
token: ${NPM_TOKEN}
303+
config:
304+
namespaceExport: YourClientName
305+
github:
306+
repository: your-org/your-repository
307+
```
282308

283309
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)
284310
</Step>

0 commit comments

Comments
 (0)