发布到 crates.io
发布到 crates.io
将您的公共 Fern Rust SDK 发布到 crates.io 注册表。按照本页面的步骤操作后, 您将在 crates.io 上发布一个版本化的 crate。
本页面假设您已经:
- 初始化了
fern文件夹,为您的 Rust SDK 创建了 GitHub 仓库,并在generators.yml中配置了 Rust 生成器组。请参阅 生成 SDK (Rust)。

配置 generators.yml
设置 crates.io 发布身份验证
发布您的 SDK
决定您希望如何将 SDK 发布到 crates.io。您可以使用 GitHub 工作流进行自动化发布,或通过 CLI 直接发布。
通过 GitHub 工作流发布(推荐)
通过 GitHub Actions 设置发布工作流,这样您就可以直接从源仓库触发新的 SDK 发布。
设置身份验证
在 GitHub 中打开您的源仓库。点击仓库中的 Settings 选项卡。然后,在 Security 部分下,打开 Secrets and variables > Actions。
您也可以使用 URL https://github.com/<your-repo>/settings/secrets/actions。
为您的 crates.io token 添加密钥
- 选择 New repository secret。
- 将您的密钥命名为
CRATES_IO_API_KEY。 - 添加您在上面生成的对应 token。
- 点击 Add secret。
为您的 Fern token 添加密钥
- 选择 New repository secret。
- 将您的密钥命名为
FERN_TOKEN。 - 添加您的 Fern token。如果您还没有,可以通过
运行
fern token来生成一个。默认情况下,fern_token是为fern.config.json中列出的组织生成的。 - 点击 Add secret。
设置新工作流
设置一个可以从 GitHub UI 手动触发的 CI 工作流。在您的仓库中,导航到 Actions。选择 New workflow,然后选择 Set up workflow yourself。添加类似以下的工作流:
重新生成并发布您的 SDK
导航到 Actions 选项卡,选择您刚创建的工作流,指定版本号,然后点击 Run workflow。这将重新生成您的 SDK。
The rest of the release process depends on your chosen mode:
-
Release mode (default): If you didn’t specify a
modeor setmode: release, no further action is required. Fern automatically tags the new release with your specified version number and initiates the publishing workflow in your SDK repository. -
Pull request or push mode: If you set
mode: pull-requestormode: push, Fern creates a pull request or pushes to a branch respectively. Review and merge the PR (pull-request) or branch (push), then tag a new release to initiate the publishing workflow in your SDK repository.
工作流完成后,您可以通过登录 crates.io,导航到 Dashboard,并在 My Crates 下查看您的新发布。
通过 CLI 和环境变量发布
重新生成并发布您的 SDK
重新生成您的 SDK,指定版本:
The rest of the release process depends on your chosen mode:
-
Release mode (default): If you didn’t specify a
modeor setmode: release, no further action is required. Fern automatically tags the new release with your specified version number and initiates the publishing workflow in your SDK repository. -
Pull request or push mode: If you set
mode: pull-requestormode: push, Fern creates a pull request or pushes to a branch respectively. Review and merge the PR (pull-request) or branch (push), then tag a new release to initiate the publishing workflow in your SDK repository.
工作流完成后,您可以通过登录 crates.io,导航到 Dashboard,并在 My Crates 下查看您的新发布。
