mcpField
U
using-crabnebula-cloud-with-tauri

using-crabnebula-cloud-with-tauri

github.com/dchuk云与 DevOps36136 次安装40 周前更新
代码仓库

关于 using-crabnebula-cloud-with-tauri

这项技能介绍如何通过 CrabNebula Cloud 分发 Tauri 应用,涵盖发布流程、渠道管理、CI/CD 和自动更新配置。

主要功能

  1. 01创建、上传和发布版本
  2. 02管理 stable、beta 和 nightly 渠道
  3. 03配置 Tauri 自动更新
  4. 04用 GitHub Actions 自动发布
  5. 05跟踪应用下载量

适用场景

  1. 01发布 Tauri 应用安装包和更新
  2. 02设置 beta 与 stable 发布渠道
  3. 03通过 GitHub Actions 自动化发布

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/dchuk/claude-code-tauri-skills --skill using-crabnebula-cloud-with-tauri

安装后在 Claude Code 中输入/using-crabnebula-cloud-with-tauri确认已加载。

详细介绍

使用 Tauri 的 CrabNebula Cloud

CrabNebula 是 Tauri 的官方合作伙伴,提供可与 Tauri 更新器无缝集成的应用分发平台。该平台提供全球 CDN 分发、发布管理和内置自动更新支持。

概览

CrabNebula Cloud 提供:

  • 全球 CDN:在全球范围分发安装包和更新
  • 发布渠道:支持多个发布轨道(stable、beta、nightly)
  • 自动更新:内置更新服务,与 Tauri 的更新器插件兼容
  • 下载指标:用于跟踪应用下载量的分析数据
  • CI/CD 集成:支持通过 GitHub Actions 自动发布

初始设置

1. 创建 CrabNebula Cloud 账户
  1. 前往 CrabNebula Cloud
  2. 使用 GitHub 或 GitLab 身份验证登录
  3. 创建一个具有唯一标识符的组织
  4. 在组织中创建应用
2. 生成 API 密钥
  1. 前往 CrabNebula Cloud 中的 API Keys 部分
  2. 生成具有读写权限的新密钥
  3. 安全保存此密钥(仅显示一次)
  4. 在 GitHub 中将其添加为 CN_API_KEY 仓库机密

重要:请使用仓库机密,而不是环境机密,因为环境机密可能会出现在日志中。

CLI 安装

安装 CrabNebula CLI,以便在本地管理发布:

# macOS/Linux
curl -L https://cdn.crabnebula.app/install/cn | sh

# Or via cargo
cargo install cn-cli

发布工作流

发布流程分为四个步骤:草拟、上传、发布、获取。

手动 CLI 命令
# Create a release draft
cn release draft ORG_SLUG/APP_SLUG VERSION

# Upload assets with Tauri framework detection
cn release upload ORG_SLUG/APP_SLUG RELEASE_ID --framework tauri

# Publish the release
cn release publish ORG_SLUG/APP_SLUG RELEASE_ID

# Fetch latest release info
cn release latest ORG_SLUG/APP_SLUG
上传命令选项
cn release upload ORG_SLUG/APP_SLUG RELEASE_ID \
  --framework tauri \
  --channel stable \
  --update-platform linux-x86_64 \
  --file path/to/binary \
  --signature path/to/signature
标志说明
--framework自动检测构建包(tauri 或 packager)
--channel发布渠道(必须与草拟渠道一致)
--update-platform更新的平台标识符
--file二进制文件路径
--signature签名文件路径(与 --update-platform 一同使用时必需)

GitHub Actions 工作流

创建 .github/workflows/release.yml:

name: Release

on:
  push:
    branches:
      - main
  workflow_dispatch:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

env:
  CN_APPLICATION: "your-org/your-app"

jobs:
  draft:
    runs-on: ubuntu-latest
    outputs:
      version: ${{ steps.read-version.outputs.version }}
    steps:
      - uses: actions/checkout@v4

      - name: Read version from tauri.conf.json
        id: read-version
        run: |
          VERSION=$(jq -r '.version' src-tauri/tauri.conf.json)
          echo "version=$VERSION" >> $GITHUB_OUTPUT

      - name: Create draft release
        uses: crabnebula-dev/cloud-release@v0
        with:
          command: release draft ${{ env.CN_APPLICATION }} ${{ steps.read-version.outputs.version }} --framework tauri
          api-key: ${{ secrets.CN_API_KEY }}

  build:
    needs: draft
    strategy:
      fail-fast: false
      matrix:
        include:
          - platform: ubuntu-22.04
            args: ""
          - platform: macos-latest
            args: "--target aarch64-apple-darwin"
          - platform: macos-latest
            args: "--target x86_64-apple-darwin"
          - platform: windows-latest
            args: ""
    runs-on: ${{ matrix.platform }}
    steps:
      - uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: lts/*

      - name: Install Rust stable
        uses: dtolnay/rust-action@stable
        with:
          targets: ${{ matrix.platform == 'macos-latest' && 'aarch64-apple-darwin,x86_64-apple-darwin' || '' }}

      - name: Install Linux dependencies
        if: matrix.platform == 'ubuntu-22.04'
        run: |
          sudo apt-get update
          sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf

      - name: Install frontend dependencies
        run: npm ci

      - name: Build Tauri app
        uses: tauri-apps/tauri-action@v0
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
          TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
        with:
          args: ${{ matrix.args }}

      - name: Upload assets to CrabNebula Cloud
        uses: crabnebula-dev/cloud-release@v0
        with:
          command: release upload ${{ env.CN_APPLICATION }} --framework tauri
          api-key: ${{ secrets.CN_API_KEY }}

  publish:
    needs: [draft, build]
    runs-on: ubuntu-latest
    steps:
      - name: Publish release
        uses: crabnebula-dev/cloud-release@v0
        with:
          command: release publish ${{ env.CN_APPLICATION }} ${{ needs.draft.outputs.version }}
          api-key: ${{ secrets.CN_API_KEY }}

自动更新配置

1. 生成签名密钥
cargo tauri signer generate -w ~/.tauri/myapp.key

这会创建:

  • ~/.tauri/myapp.key - 私钥(请保密)
  • ~/.tauri/myapp.key.pub - 公钥(添加到配置中)

将以下内容添加到 GitHub 仓库机密:

  • TAURI_SIGNING_PRIVATE_KEY:myapp.key 的内容
  • TAURI_SIGNING_PRIVATE_KEY_PASSWORD:你的密码
2. 配置 tauri.conf.json
{
  "version": "0.1.0",
  "bundle": {
    "createUpdaterArtifacts": true
  },
  "plugins": {
    "updater": {
      "active": true,
      "endpoints": [
        "https://cdn.crabnebula.app/update/YOUR_ORG/YOUR_APP/{{target}}-{{arch}}/{{current_version}}"
      ],
      "dialog": true,
      "pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk..."
    }
  }
}

重要:请勿更改 {{target}}、{{arch}} 和 {{current_version}} 占位符。Tauri 会在运行时动态替换它们。

从 Tauri v1 迁移时,请使用 "createUpdaterArtifacts": "v1Compatible"。

3. 配置 Capabilities

更新 /src-tauri/capabilities/main.json:

{
  "$schema": "../gen/schemas/desktop-schema.json",
  "identifier": "main-capability",
  "description": "Main capability for the application",
  "windows": ["main"],
  "permissions": [
    "core:default",
    "dialog:default",
    "updater:default",
    "process:default",
    "process:allow-restart"
  ]
}
4. 安装依赖项

添加到 src-tauri/Cargo.toml:

[dependencies]
tauri-plugin-updater = "2"
tauri-plugin-dialog = "2"
tauri-plugin-process = "2"

安装前端软件包:

npm install @tauri-apps/plugin-updater @tauri-apps/plugin-dialog @tauri-apps/plugin-process
5. 注册插件(Rust)

更新 src-tauri/src/lib.rs:

use tauri::Manager;

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    tauri::Builder::default()
        .plugin(tauri_plugin_updater::Builder::new().build())
        .plugin(tauri_plugin_dialog::init())
        .plugin(tauri_plugin_process::init())
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
6. 实现更新检查(TypeScript)

创建 src/updater.ts:

import { check } from "@tauri-apps/plugin-updater";
import { ask } from "@tauri-apps/plugin-dialog";
import { relaunch } from "@tauri-apps/plugin-process";

export async function checkForAppUpdates(): Promise<void> {
  try {
    const update = await check();

    if (!update?.available) {
      console.log("No update available");
      return;
    }

    const proceed = await ask(
      `Version ${update.version} is available!\n\nRelease notes:\n${update.body}`,
      {
        title: "Update Available",
        kind: "info",
        okLabel: "Update Now",
        cancelLabel: "Later"
      }
    );

    if (proceed) {
      console.log("Downloading and installing update...");
      await update.downloadAndInstall();
      await relaunch();
    }
  } catch (error) {
    console.error("Update check failed:", error);
  }
}

在应用生命周期早期调用:

// React example
import { useEffect } from "react";
import { checkForAppUpdates } from "./updater";

function App() {
  useEffect(() => {
    checkForAppUpdates();
  }, []);

  return <div>Your app content</div>;
}

发布渠道

如需使用多个分发渠道(beta、stable、nightly):

选项 1:渠道参数
# Create draft with channel
cn release draft ORG/APP VERSION --channel beta

# Upload must specify same channel
cn release upload ORG/APP RELEASE_ID --framework tauri --channel beta
选项 2:单独的应用

在 CrabNebula Cloud 中创建单独的应用:

  • your-org/your-app(stable)
  • your-org/your-app-beta(beta)

在应用构建中为各个渠道配置不同的更新端点。

环境变量汇总

变量位置说明
CN_API_KEYGitHub SecretsCrabNebula Cloud API 密钥
TAURI_SIGNING_PRIVATE_KEYGitHub Secrets私有签名密钥的内容
TAURI_SIGNING_PRIVATE_KEY_PASSWORDGitHub Secrets签名密钥的密码
CN_APPLICATION工作流环境组织/应用标识符

故障排查

更新检查失败
  1. 确认端点 URL 与组织和应用标识符匹配
  2. 确保配置中的公钥与生成的密钥匹配
  3. 检查 createUpdaterArtifacts 是否设置为 true
  4. 确认 Capabilities 包含所需权限
上传时构建失败
  1. 确保 CN_API_KEY 已设置为仓库密钥(而不是环境密钥)
  2. 验证草稿是否已成功创建,然后再上传
  3. 检查签名密钥是否已正确配置
签名不匹配
  1. 确保 TAURI_SIGNING_PRIVATE_KEY 与配置中的公钥匹配
  2. 验证所有构建是否使用相同的密钥对
  3. 对于 v1 迁移,请使用 "createUpdaterArtifacts": "v1Compatible"

资源

评论

支持 Markdown