Skip to content

Commit 3a52173

Browse files
committed
expand nuget publishing flow to include github actions
1 parent 3b5eebc commit 3a52173

File tree

4 files changed

+219
-95
lines changed

4 files changed

+219
-95
lines changed
81.3 KB
Loading
47.8 KB
Loading

fern/products/sdks/overview/csharp/publishing-to-nuget.mdx

Lines changed: 217 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -12,50 +12,57 @@ you'll have a versioned package published on NuGet.
1212
<img src="assets/dotnet-package.png" alt="Versioned package published on NuGet" />
1313
</Frame>
1414

15-
<Markdown src="/products/sdks/snippets/setup-fern-folder-callout.mdx"/>
15+
<Info>
16+
This page assumes that you have:
1617

17-
## Configure `generators.yml`
18+
* An initialized `fern` folder. See [Set up the `fern`
19+
folder](/sdks/overview/quickstart).
20+
* A GitHub repository for your C#/.NET SDK. See [Project structure](/sdks/overview/project-structure).
21+
* A C#/.NET generator group in `generators.yml`. See [C#/.NET
22+
Quickstart](quickstart#add-the-sdk-generator).
1823

19-
<Steps>
24+
</Info>
2025

21-
<Step title="Configure `output` location">
26+
## Configure SDK package settings
2227

23-
Next, change the output location in `generators.yml` from `local-file-system` (the default) to `nuget` to indicate that Fern should publish your package directly to the NuGet registry:
28+
You'll need to update your `generators.yml` file to configure the package name, output location, and client name for NuGet publishing. Your `generators.yml` [should live in your source repository](/sdks/overview/project-structure) (or on your local machine), not the repository that contains your C#/.NET SDK code.
2429

25-
```yaml {6-7}
26-
groups:
27-
csharp-sdk:
28-
generators:
29-
- name: fernapi/fern-csharp-sdk
30-
version: <Markdown src="/snippets/version-number-csharp.mdx"/>
31-
output:
32-
location: nuget
33-
```
34-
</Step>
30+
<Steps>
31+
<Step title="Configure `output` location">
3532

36-
<Step title="Add a unique package name">
33+
In the `group` for your C#/.NET SDK, change the output location from `local-file-system` (the default) to `nuget` to indicate that Fern should publish your package directly to the npm registry:
3734

38-
Your package name must be unique in the NuGet repository, otherwise publishing your SDK to NuGet will fail. Update your package name if you haven't done so already:
35+
```yaml {6-7} title="generators.yml"
36+
groups:
37+
csharp-sdk:
38+
generators:
39+
- name: fernapi/fern-csharp-sdk
40+
version: <Markdown src="/snippets/version-number-csharp.mdx"/>
41+
output:
42+
location: nuget
43+
```
44+
</Step>
45+
<Step title="Add a unique package name">
3946

47+
Your package name must be unique in the NuGet repository, otherwise publishing your SDK to NuGet will fail.
4048

41-
```yaml {8}
42-
groups:
43-
csharp-sdk:
44-
generators:
45-
- name: fernapi/fern-csharp-sdk
46-
version: <Markdown src="/snippets/version-number-csharp.mdx"/>
47-
output:
48-
location: nuget
49-
package-name: your-package-name
50-
```
51-
52-
</Step>
53-
<Step title="Configure `client-class-name`">
49+
```yaml {8} title="generators.yml"
50+
groups:
51+
csharp-sdk:
52+
generators:
53+
- name: fernapi/fern-csharp-sdk
54+
version: <Markdown src="/snippets/version-number-csharp.mdx"/>
55+
output:
56+
location: nuget
57+
package-name: your-package-name
58+
```
5459

55-
The `client-class-name` option controls the name of the generated client. This is the name customers use to import your SDK (`import { your-client-name } from 'your-package-name';`).
60+
</Step>
61+
<Step title="Configure `client-class-name`">
5662

63+
The `client-class-name` option controls the name of the generated client. This is the name customers use to import your SDK (`import { your-client-name } from 'your-package-name';`).
5764

58-
```yaml {9-10}
65+
```yaml {9-10} title="generators.yml"
5966
groups:
6067
csharp-sdk:
6168
generators:
@@ -67,14 +74,51 @@ groups:
6774
config:
6875
client_class_name: YourClientName # must be PascalCase
6976
```
70-
71-
</Step>
77+
</Step>
78+
</Steps>
7279
73-
<Step title="Add repository location">
80+
## Generate a NuGet API key
81+
82+
<Steps>
83+
84+
<Step title="Log into NuGet">
85+
86+
Log into [NuGet](https://nuget.org/) or create a new account.
87+
88+
</Step>
89+
90+
<Step title="Add New Key">
91+
92+
1. Click on your profile picture.
93+
1. Select **API Keys**, then **Create**.
94+
1. Name your key.
95+
1. Select **Push > Push new packages and package versions** as the **Select Scopes** type.
96+
1. Enter `*` under **Select Packages > Glob Patten**.
97+
98+
<Tip title="Replacing an existing NuGet package">
99+
If you are overriding an existing package, you can select the relevant
100+
package instead of entering `*`.
101+
</Tip>
102+
1. Click **Create**.
103+
104+
<Frame>
105+
<img src="assets/new-api-key.png" alt="Creating a New API Key" />
106+
</Frame>
74107

75-
Add the path to your GitHub repository to `generators.yml`:
108+
<Warning>Save your new key – it won’t be displayed after you leave the page.</Warning>
76109

77-
```yaml {11-12}
110+
</Step>
111+
112+
</Steps>
113+
114+
## Configure NuGet publication
115+
116+
<Steps>
117+
<Step title="Add repository location">
118+
119+
Add the path to the GitHub repository containing your C#/.NET SDK:
120+
121+
```yaml title="generators.yml" {11-12}
78122
groups:
79123
csharp-sdk:
80124
generators:
@@ -87,48 +131,33 @@ groups:
87131
client_class_name: YourClientName
88132
github:
89133
repository: your-org/company-csharp
90-
```
91-
92-
</Step>
93-
</Steps>
94-
95-
## Set up NuGet publishing authentication
96-
97-
<Steps>
98-
99-
<Step title="Log into NuGet">
100-
101-
Log into [NuGet](https://nuget.org/) or create a new account.
102-
103-
</Step>
104-
105-
<Step title="Add New Key">
134+
```
135+
</Step>
136+
<Step title="Configure NuGet authentication key">
106137

107-
1. Click on your profile picture.
108-
1. Select **API Keys**, then **Create**.
109-
1. Name your key.
110-
1. Select **Push > Push new packages and package versions** as the **Select Scopes** type.
111-
1. Enter `*` under **Select Packages > Glob Patten**.
112-
113-
<Tip title="Replacing an existing NuGet package">
114-
If you are overriding an existing package, you can select the relevant
115-
package instead of entering `*`.
116-
</Tip>
117-
1. Click **Create**.
138+
Add `api-key: ${NUGET_API_KEY}` to `generators.yml` to tell Fern to use the `NUGET_API_KEY` environment variable for authentication when publishing to the NuGet registry.
118139

119-
<Frame>
120-
<img src="assets/new-api-key.png" alt="Creating a New API Key" />
121-
</Frame>
122-
123-
<Warning>Save your new key – it won’t be displayed after you leave the page.</Warning>
124-
125-
</Step>
126-
127-
<Step title="Configure NuGet authentication key">
140+
```yaml title="generators.yml" {9}
141+
groups:
142+
csharp-sdk:
143+
generators:
144+
- name: fernapi/fern-csharp-sdk
145+
version: <Markdown src="/snippets/version-number-csharp.mdx"/>
146+
output:
147+
location: nuget
148+
package-name: your-package-name
149+
api-key: ${NUGET_API_KEY}
150+
config:
151+
client_class_name: YourClientName
152+
github:
153+
repository: your-org/company-csharp
154+
```
155+
</Step>
156+
<Step title="Choose your publishing mode">
128157

129-
Add `api-key: ${NUGET_API_KEY}` to `generators.yml` to tell Fern to use the `NUGET_API_KEY` environment variable for authentication when publishing to the NuGet registry.
158+
<Markdown src="/products/sdks/snippets/github-publishing-mode.mdx"/>
130159

131-
```yaml {9}
160+
```yaml title="generators.yml" {14}
132161
groups:
133162
csharp-sdk:
134163
generators:
@@ -142,37 +171,132 @@ groups:
142171
client_class_name: YourClientName
143172
github:
144173
repository: your-org/company-csharp
174+
mode: push
175+
branch: your-branch-name # Required for mode: push
145176
```
146-
</Step>
147177

178+
</Step>
148179
</Steps>
149180

150-
## Release your SDK to NuGet
181+
## Publish your SDK
182+
183+
Decide how you want to publish your SDK to NuGet. You can use GitHub workflows for automated releases or publish directly via the CLI.
184+
185+
<AccordionGroup>
186+
187+
<Accordion title="Release via a GitHub workflow">
151188

152-
At this point, you're ready to generate a release for your SDK.
189+
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 source repository.
153190

154191
<Steps>
192+
<Step title="Set up authentication">
155193

156-
<Step title="Set NuGet environment variable">
194+
Open your source repository in GitHub. Click on the **Settings** tab. Then, under the **Security** section, open **Secrets and variables** > **Actions**.
157195

158-
On your local machine, set the `NUGET_API_KEY` environment variable to the new API key you generated earlier:
196+
You can also use the url `https://github.com/<your-repo>/settings/secrets/actions`.
197+
198+
</Step>
199+
<Step title="Add secret for your NuGet API key">
200+
201+
1. Select **New repository secret**.
202+
1. Name your secret `NUGET_API_KEY`.
203+
1. Add the corresponding API key you generated above.
204+
1. Click **Add secret**.
205+
206+
<Frame>
207+
<img src="assets/nuget-api-key-secret.png" alt="NUGET_API_KEY secret" />
208+
</Frame>
159209

160-
```bash
161-
export NUGET_API_KEY=your-actual-nuget-key
210+
</Step>
211+
<Step title="Add secret for your Fern Token">
212+
213+
1. Select **New repository secret**.
214+
1. Name your secret `FERN_TOKEN`.
215+
1. Add your Fern token. If you don't already have one, generate one by
216+
running `fern token`. By default, the `fern_token` is generated for the
217+
organization listed in `fern.config.json`.
218+
1. Click **Add secret**.
219+
220+
</Step>
221+
<Step title="Set up a new workflow">
222+
223+
Set up a CI workflow that you can manually trigger from the GitHub UI. In your repository, navigate to **Actions**. Select **New workflow**, then **Set up workflow yourself**. Add a workflow that's similar to this:
224+
225+
```yaml title=".github/workflows/publish.yml" maxLines=0
226+
name: Publish C#/.NET SDK
227+
228+
on:
229+
workflow_dispatch:
230+
inputs:
231+
version:
232+
description: "The version of the C#/.NET SDK that you would like to release"
233+
required: true
234+
type: string
235+
236+
jobs:
237+
release:
238+
runs-on: ubuntu-latest
239+
steps:
240+
- name: Checkout repo
241+
uses: actions/checkout@v4
242+
243+
- name: Install Fern CLI
244+
run: npm install -g fern-api
245+
246+
- name: Release C#/.NET SDK
247+
env:
248+
FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
249+
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
250+
run: |
251+
fern generate --group csharp-sdk --version ${{ inputs.version }} --log-level debug
162252
```
253+
<Note>
254+
You can alternatively configure your workflow to execute `on: [push]`. See Vapi's [npm publishing GitHub Action](https://github.com/VapiAI/server-sdk-typescript/blob/main/.github/workflows/ci.yml) for an example.
255+
</Note>
256+
</Step>
163257

164-
</Step>
258+
<Step title="Regenerate and release your SDK">
165259

166-
<Step title="Generate your release">
260+
Navigate to the **Actions** tab, select the workflow you just created, specify a version number, and click **Run workflow**. This regenerates your SDK.
167261

168-
Regenerate your SDK and publish it on NuGet:
262+
<Frame>
263+
<img src="assets/csharp-sdk-release-action.png" alt="Running TS publish workflow" />
264+
</Frame>
169265

170-
```bash
171-
fern generate --group csharp-sdk --version <version>
172-
```
173-
Local machine output will verify that the release is pushed to your
174-
repository and tagged with the version you specified. Log back into NuGet and
175-
navigate to **Packages** to see your new release.
176-
</Step>
266+
<Markdown src="/products/sdks/snippets/release-sdk.mdx"/>
267+
268+
Once the workflow completes, you can view your new release by logging into NuGet and navigating to **Manage Packages**.
269+
270+
</Step>
271+
</Steps>
272+
</Accordion>
273+
274+
<Accordion title="Release via CLI and environment variables">
275+
<Steps>
276+
277+
<Step title="Set npm environment variable">
278+
279+
Set the `NUGET_API_KEY` environment variable on your local machine:
177280

178-
</Steps>
281+
```bash
282+
export NUGET_API_KEY=your-actual-nuget-api-key
283+
```
284+
285+
</Step>
286+
<Step title="Regenerate and release your SDK">
287+
288+
Regenerate your SDK, specifying the version:
289+
290+
```bash
291+
fern generate --group csharp-sdk --version <version>
292+
```
293+
294+
<Markdown src="/products/sdks/snippets/release-sdk.mdx"/>
295+
296+
Once the workflow completes, you can view your new release by logging into NuGet and navigating to **Manage Packages**.
297+
298+
</Step>
299+
300+
</Steps>
301+
</Accordion>
302+
</AccordionGroup>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ You'll need to update your `generators.yml` file to configure the package name,
2929
<Steps>
3030
<Step title="Configure `output` location">
3131

32-
In the `group` for your TypeScript SDK, change the output location in from `local-file-system` (the default) to `npm` to indicate that Fern should publish your package directly to the npm registry:
32+
In the `group` for your TypeScript SDK, change the output location from `local-file-system` (the default) to `npm` to indicate that Fern should publish your package directly to the npm registry:
3333

3434
```yaml {6-7} title="generators.yml"
3535
groups:
@@ -222,7 +222,7 @@ Set up a release workflow via [GitHub Actions](https://docs.github.com/en/action
222222
<Steps>
223223
<Step title="Set up authentication">
224224

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

227227
<Frame>
228228
<img src="assets/github-secret.png" alt="Adding GitHub Repository Secret" />

0 commit comments

Comments
 (0)