|
| 1 | +--- |
| 2 | +title: Releases |
| 3 | +description: Automate SDK releases with the Fern CLI GitHub Action. Configure your repository and set up CI to generate and publish SDKs on every push. |
| 4 | +--- |
| 5 | + |
| 6 | + |
| 7 | +After [structuring your project](/learn/sdks/overview/project-structure) and configuring your generators, set up a CI workflow to automate SDK releases. This page covers the complete configuration for a release-ready repository and the GitHub Action that drives it. |
| 8 | + |
| 9 | +## Repository configuration |
| 10 | + |
| 11 | +A release-ready Fern configuration repository contains three files in the `fern/` directory: |
| 12 | + |
| 13 | +<Files> |
| 14 | + <Folder name="my-api" defaultOpen> |
| 15 | + <Folder name=".github" defaultOpen> |
| 16 | + <Folder name="workflows" defaultOpen> |
| 17 | + <File name="ci.yml" comment="Release workflow" /> |
| 18 | + </Folder> |
| 19 | + </Folder> |
| 20 | + <Folder name="fern" defaultOpen> |
| 21 | + <File name="fern.config.json" comment="Organization and CLI version" /> |
| 22 | + <File name="generators.yml" comment="API spec location and generator config" /> |
| 23 | + <File name="openapi.yml" comment="Your API definition" /> |
| 24 | + </Folder> |
| 25 | + </Folder> |
| 26 | +</Files> |
| 27 | + |
| 28 | +### `fern.config.json` |
| 29 | + |
| 30 | +Pin the CLI version for deterministic builds: |
| 31 | + |
| 32 | +```json title="fern/fern.config.json" |
| 33 | +{ |
| 34 | + "organization": "your-org", |
| 35 | + "version": "5.44.3" |
| 36 | +} |
| 37 | +``` |
| 38 | + |
| 39 | +### `generators.yml` |
| 40 | + |
| 41 | +Declare your API spec and configure generators with a `github` block to enable releases: |
| 42 | + |
| 43 | +```yaml title="fern/generators.yml" |
| 44 | +api: |
| 45 | + specs: |
| 46 | + - openapi: openapi.yml |
| 47 | + |
| 48 | +groups: |
| 49 | + ts-sdk: |
| 50 | + generators: |
| 51 | + - name: fernapi/fern-typescript-sdk |
| 52 | + version: 3.12.3 |
| 53 | + output: |
| 54 | + location: npm |
| 55 | + package-name: "@your-org/sdk" |
| 56 | + token: OIDC |
| 57 | + github: |
| 58 | + repository: your-org/your-typescript-sdk |
| 59 | + mode: release |
| 60 | + config: |
| 61 | + namespaceExport: YourClient |
| 62 | +``` |
| 63 | +
|
| 64 | +The `github` block controls how Fern delivers generated code: |
| 65 | + |
| 66 | +| Field | Description | |
| 67 | +|-------|-------------| |
| 68 | +| `repository` | Target GitHub repository for the generated SDK | |
| 69 | +| `mode` | `release` (default), `pull-request`, or `push` | |
| 70 | +| `branch` | Target branch (required for `push` mode) | |
| 71 | + |
| 72 | +See the [`generators.yml` reference](/learn/sdks/reference/generators-yml#github) for the full set of options. |
| 73 | + |
| 74 | +<Note> |
| 75 | +The [Fern GitHub App](https://github.com/apps/fern-api) must be installed on your target SDK repository. |
| 76 | +</Note> |
| 77 | + |
| 78 | +## GitHub Action for releases |
| 79 | + |
| 80 | +The [`fern-api/setup-fern-cli`](https://github.com/marketplace/actions/setup-fern-cli) GitHub Action installs the Fern CLI in your workflow. Pair it with `fern generate` to automate SDK releases on every push to your default branch. |
| 81 | + |
| 82 | +### Basic workflow |
| 83 | + |
| 84 | +```yaml title=".github/workflows/ci.yml" |
| 85 | +name: Generate SDKs |
| 86 | +
|
| 87 | +on: |
| 88 | + push: |
| 89 | + branches: [main] |
| 90 | +
|
| 91 | +jobs: |
| 92 | + generate: |
| 93 | + runs-on: ubuntu-latest |
| 94 | + steps: |
| 95 | + - uses: actions/checkout@v4 |
| 96 | +
|
| 97 | + - uses: actions/setup-node@v4 |
| 98 | + with: |
| 99 | + node-version: "lts/*" |
| 100 | +
|
| 101 | + - name: Setup Fern CLI |
| 102 | + uses: fern-api/setup-fern-cli@v1 |
| 103 | +
|
| 104 | + - name: Generate SDKs |
| 105 | + env: |
| 106 | + FERN_TOKEN: ${{ secrets.FERN_TOKEN }} |
| 107 | + run: fern generate |
| 108 | +``` |
| 109 | + |
| 110 | +This workflow: |
| 111 | +1. Checks out your configuration repository |
| 112 | +2. Installs Node.js (required by the Fern CLI) |
| 113 | +3. Installs the Fern CLI via the `setup-fern-cli` action |
| 114 | +4. Runs `fern generate` to regenerate SDKs and push to the configured repositories |
| 115 | + |
| 116 | +### With a specific version |
| 117 | + |
| 118 | +Pin the Fern CLI to a specific version for reproducible builds: |
| 119 | + |
| 120 | +```yaml |
| 121 | +- name: Setup Fern CLI |
| 122 | + uses: fern-api/setup-fern-cli@v1 |
| 123 | + with: |
| 124 | + version: "5.44.3" |
| 125 | +``` |
| 126 | + |
| 127 | +### Versioned releases |
| 128 | + |
| 129 | +To publish a specific version, pass `--version` to `fern generate`: |
| 130 | + |
| 131 | +```yaml title=".github/workflows/release.yml" |
| 132 | +name: Release SDK |
| 133 | +
|
| 134 | +on: |
| 135 | + workflow_dispatch: |
| 136 | + inputs: |
| 137 | + version: |
| 138 | + description: "Version to publish (e.g., 1.0.0)" |
| 139 | + required: true |
| 140 | + type: string |
| 141 | +
|
| 142 | +jobs: |
| 143 | + release: |
| 144 | + runs-on: ubuntu-latest |
| 145 | + steps: |
| 146 | + - uses: actions/checkout@v4 |
| 147 | +
|
| 148 | + - uses: actions/setup-node@v4 |
| 149 | + with: |
| 150 | + node-version: "lts/*" |
| 151 | +
|
| 152 | + - name: Setup Fern CLI |
| 153 | + uses: fern-api/setup-fern-cli@v1 |
| 154 | +
|
| 155 | + - name: Generate and release |
| 156 | + env: |
| 157 | + FERN_TOKEN: ${{ secrets.FERN_TOKEN }} |
| 158 | + run: fern generate --group ts-sdk --version ${{ inputs.version }} --log-level debug |
| 159 | +``` |
| 160 | + |
| 161 | +Trigger this workflow from the **Actions** tab in GitHub to release a specific version on demand. |
| 162 | + |
| 163 | +## Authentication |
| 164 | + |
| 165 | +The workflows above require a `FERN_TOKEN` repository secret. Generate one by running: |
| 166 | + |
| 167 | +```bash |
| 168 | +fern token |
| 169 | +``` |
| 170 | + |
| 171 | +Add the token as a repository secret named `FERN_TOKEN` under **Settings > Secrets and variables > Actions** in your configuration repository. |
| 172 | + |
| 173 | +## Release modes |
| 174 | + |
| 175 | +The `mode` field in `generators.yml` determines what happens after generation: |
| 176 | + |
| 177 | +| Mode | Behavior | When to publish | |
| 178 | +|------|----------|-----------------| |
| 179 | +| `release` | Commits to the default branch and tags a release | Automatic — publishing triggers on the tag | |
| 180 | +| `pull-request` | Opens a PR for review | Merge the PR, then [tag a release](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository) | |
| 181 | +| `push` | Pushes to the specified branch | [Tag a release](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository) from the branch | |
| 182 | + |
| 183 | +For `pull-request` and `push` modes, the generated SDK repository contains a CI workflow (`.github/workflows/ci.yml`) that publishes the package when a GitHub release is tagged. |
0 commit comments