building-tauri-with-github-actions
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBuilding Tauri Apps with GitHub Actions
使用GitHub Actions构建Tauri应用
This skill covers CI/CD pipeline configuration for Tauri applications using GitHub Actions and the official .
tauri-apps/tauri-action本技能介绍如何使用GitHub Actions及官方配置Tauri应用的CI/CD流水线。
tauri-apps/tauri-actionOverview
概述
GitHub Actions enables automated building, testing, and releasing of Tauri applications across Windows, macOS, and Linux platforms. The handles the complexity of cross-platform builds and release management.
tauri-actionGitHub Actions可实现Windows、macOS和Linux平台上Tauri应用的自动化构建、测试与发布。负责处理跨平台构建与发布管理的复杂流程。
tauri-actionWorkflow Triggers
工作流触发器
Push to Release Branch
推送到发布分支
yaml
name: 'publish'
on:
workflow_dispatch:
push:
branches:
- releaseyaml
name: 'publish'
on:
workflow_dispatch:
push:
branches:
- releaseTag-Based Releases
基于标签的发布
yaml
name: 'publish'
on:
push:
tags:
- 'app-v*'yaml
name: 'publish'
on:
push:
tags:
- 'app-v*'Platform Matrix Configuration
平台矩阵配置
Standard Multi-Platform Matrix
标准多平台矩阵
yaml
jobs:
publish-tauri:
permissions:
contents: write
strategy:
fail-fast: false
matrix:
include:
- platform: 'macos-latest'
args: '--target aarch64-apple-darwin'
- platform: 'macos-latest'
args: '--target x86_64-apple-darwin'
- platform: 'ubuntu-22.04'
args: ''
- platform: 'windows-latest'
args: ''
runs-on: ${{ matrix.platform }}yaml
jobs:
publish-tauri:
permissions:
contents: write
strategy:
fail-fast: false
matrix:
include:
- platform: 'macos-latest'
args: '--target aarch64-apple-darwin'
- platform: 'macos-latest'
args: '--target x86_64-apple-darwin'
- platform: 'ubuntu-22.04'
args: ''
- platform: 'windows-latest'
args: ''
runs-on: ${{ matrix.platform }}With ARM Linux Support (Public Repos Only)
支持ARM Linux(仅公共仓库)
Add to the matrix for native ARM64 Linux builds (public repositories only).
ubuntu-22.04-arm在矩阵中添加可实现原生ARM64 Linux构建(仅适用于公共仓库)。
ubuntu-22.04-armComplete Workflow Example
完整工作流示例
yaml
name: 'publish'
on:
workflow_dispatch:
push:
branches:
- release
jobs:
publish-tauri:
permissions:
contents: write
strategy:
fail-fast: false
matrix:
include:
- platform: 'macos-latest'
args: '--target aarch64-apple-darwin'
- platform: 'macos-latest'
args: '--target x86_64-apple-darwin'
- platform: 'ubuntu-22.04'
args: ''
- platform: 'windows-latest'
args: ''
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4
- name: Install dependencies (Ubuntu only)
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: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: 'npm'
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.platform == 'macos-latest' && 'aarch64-apple-darwin,x86_64-apple-darwin' || '' }}
- name: Rust cache
uses: swatinem/rust-cache@v2
with:
workspaces: './src-tauri -> target'
- name: Install frontend dependencies
run: npm ci
- name: Build and release
uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tagName: app-v__VERSION__
releaseName: 'App v__VERSION__'
releaseBody: 'See the assets to download this version and install.'
releaseDraft: true
prerelease: false
args: ${{ matrix.args }}yaml
name: 'publish'
on:
workflow_dispatch:
push:
branches:
- release
jobs:
publish-tauri:
permissions:
contents: write
strategy:
fail-fast: false
matrix:
include:
- platform: 'macos-latest'
args: '--target aarch64-apple-darwin'
- platform: 'macos-latest'
args: '--target x86_64-apple-darwin'
- platform: 'ubuntu-22.04'
args: ''
- platform: 'windows-latest'
args: ''
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4
- name: Install dependencies (Ubuntu only)
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: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: 'npm'
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.platform == 'macos-latest' && 'aarch64-apple-darwin,x86_64-apple-darwin' || '' }}
- name: Rust cache
uses: swatinem/rust-cache@v2
with:
workspaces: './src-tauri -> target'
- name: Install frontend dependencies
run: npm ci
- name: Build and release
uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tagName: app-v__VERSION__
releaseName: 'App v__VERSION__'
releaseBody: 'See the assets to download this version and install.'
releaseDraft: true
prerelease: false
args: ${{ matrix.args }}Package Manager Variants
包管理器变体
pnpm
pnpm
yaml
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: latest
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: 'pnpm'
- name: Install frontend dependencies
run: pnpm installyaml
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: latest
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: 'pnpm'
- name: Install frontend dependencies
run: pnpm installYarn
Yarn
yaml
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: 'yarn'
- name: Install frontend dependencies
run: yarn install --frozen-lockfileyaml
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: 'yarn'
- name: Install frontend dependencies
run: yarn install --frozen-lockfileCaching Strategies
缓存策略
Rust Artifact Caching
Rust工件缓存
yaml
- name: Rust cache
uses: swatinem/rust-cache@v2
with:
workspaces: './src-tauri -> target'yaml
- name: Rust cache
uses: swatinem/rust-cache@v2
with:
workspaces: './src-tauri -> target'Node.js Dependency Caching
Node.js依赖缓存
Configure via the parameter in : , , or .
cacheactions/setup-node@v4'npm''yarn''pnpm'通过中的参数配置:可选值为、或。
actions/setup-node@v4cache'npm''yarn''pnpm'Linux Dependencies
Linux依赖
Ubuntu requires WebKit and related libraries:
yaml
- name: Install dependencies (Ubuntu only)
if: matrix.platform == 'ubuntu-22.04'
run: |
sudo apt-get update
sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelfUbuntu需要WebKit及相关库:
yaml
- name: Install dependencies (Ubuntu only)
if: matrix.platform == 'ubuntu-22.04'
run: |
sudo apt-get update
sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelfRelease Automation
发布自动化
tauri-action Configuration
tauri-action配置
yaml
- uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tagName: app-v__VERSION__
releaseName: 'App v__VERSION__'
releaseBody: 'See the assets to download this version and install.'
releaseDraft: true
prerelease: false
args: ${{ matrix.args }}yaml
- uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tagName: app-v__VERSION__
releaseName: 'App v__VERSION__'
releaseBody: 'See the assets to download this version and install.'
releaseDraft: true
prerelease: false
args: ${{ matrix.args }}Version Placeholders
版本占位符
The action automatically replaces with the app version from .
__VERSION__tauri.conf.json该动作会自动将替换为中的应用版本。
__VERSION__tauri.conf.jsonRelease Options
发布选项
| Option | Description |
|---|---|
| Git tag for the release (supports |
| Display name for the release |
| Release notes content |
| Create as draft release ( |
| Mark as prerelease ( |
| 选项 | 描述 |
|---|---|
| 发布对应的Git标签(支持 |
| 发布的显示名称 |
| 发布说明内容 |
| 是否创建为草稿发布( |
| 是否标记为预发布版本( |
Artifact Uploads
工件上传
Upload Build Artifacts Without Release
仅上传构建工件而不发布
yaml
- name: Build Tauri app
uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
id: tauri
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: tauri-build-${{ matrix.platform }}
path: src-tauri/target/release/bundle/yaml
- name: Build Tauri app
uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
id: tauri
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: tauri-build-${{ matrix.platform }}
path: src-tauri/target/release/bundle/GitHub Token Configuration
GitHub Token配置
The requires write permissions for release creation.
GITHUB_TOKENGITHUB_TOKENRepository Settings
仓库设置
- Go to Settings > Actions > General
- Under "Workflow permissions"
- Select "Read and write permissions"
- Save
- 进入Settings > Actions > General
- 在“Workflow permissions”下
- 选择“Read and write permissions”
- 保存
Workflow Permissions
工作流权限
yaml
jobs:
publish-tauri:
permissions:
contents: writeyaml
jobs:
publish-tauri:
permissions:
contents: writeNon-Root Project Configuration
非根目录项目配置
For projects where Tauri is not at the repository root:
yaml
- uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
projectPath: './apps/desktop'
tagName: app-v__VERSION__
releaseName: 'App v__VERSION__'当Tauri不在仓库根目录时:
yaml
- uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
projectPath: './apps/desktop'
tagName: app-v__VERSION__
releaseName: 'App v__VERSION__'ARM Build Emulation (Alternative)
ARM构建模拟(替代方案)
For ARM builds in private repositories or when native ARM runners are unavailable:
yaml
jobs:
build-arm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build ARM64
uses: pguyot/arm-runner-action@v2.6.5
with:
base_image: dietpi:rpi_armv8_bullseye
commands: |
apt-get update
apt-get install -y curl build-essential libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env
curl -fsSL https://deb.nodesource.com/setup_lts.x | bash -
apt-get install -y nodejs
npm ci
npm run tauri buildNote: ARM emulation builds take approximately one hour for fresh projects.
对于私有仓库或无法使用原生ARM运行器的情况,可使用ARM模拟:
yaml
jobs:
build-arm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build ARM64
uses: pguyot/arm-runner-action@v2.6.5
with:
base_image: dietpi:rpi_armv8_bullseye
commands: |
apt-get update
apt-get install -y curl build-essential libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env
curl -fsSL https://deb.nodesource.com/setup_lts.x | bash -
apt-get install -y nodejs
npm ci
npm run tauri build注意:ARM模拟构建对于新项目大约需要一小时。
Code Signing Integration
代码签名集成
macOS Signing Environment Variables
macOS签名环境变量
yaml
- uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
APPLE_SIGNING_IDENTITY: ${{ secrets.APPLE_SIGNING_IDENTITY }}
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}yaml
- uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
APPLE_SIGNING_IDENTITY: ${{ secrets.APPLE_SIGNING_IDENTITY }}
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}Windows Signing Environment Variables
Windows签名环境变量
yaml
- 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 }}yaml
- 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 }}CI-Only Workflow (No Release)
仅CI工作流(无发布)
For pull request validation without creating releases:
yaml
name: 'CI Build'
on:
pull_request:
branches:
- main
jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- platform: 'macos-latest'
args: '--target aarch64-apple-darwin'
- platform: 'ubuntu-22.04'
args: ''
- platform: 'windows-latest'
args: ''
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4
- name: Install dependencies (Ubuntu only)
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: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: 'npm'
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.platform == 'macos-latest' && 'aarch64-apple-darwin,x86_64-apple-darwin' || '' }}
- name: Rust cache
uses: swatinem/rust-cache@v2
with:
workspaces: './src-tauri -> target'
- name: Install frontend dependencies
run: npm ci
- name: Build Tauri app
run: npm run tauri build -- ${{ matrix.args }}用于拉取请求验证,不创建发布:
yaml
name: 'CI Build'
on:
pull_request:
branches:
- main
jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- platform: 'macos-latest'
args: '--target aarch64-apple-darwin'
- platform: 'ubuntu-22.04'
args: ''
- platform: 'windows-latest'
args: ''
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4
- name: Install dependencies (Ubuntu only)
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: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: 'npm'
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.platform == 'macos-latest' && 'aarch64-apple-darwin,x86_64-apple-darwin' || '' }}
- name: Rust cache
uses: swatinem/rust-cache@v2
with:
workspaces: './src-tauri -> target'
- name: Install frontend dependencies
run: npm ci
- name: Build Tauri app
run: npm run tauri build -- ${{ matrix.args }}Troubleshooting
故障排除
Permission Denied for Release Creation
发布创建权限被拒绝
Ensure workflow has write permissions and verify repository settings allow Actions to create releases:
yaml
jobs:
publish-tauri:
permissions:
contents: write确保工作流具备写入权限,并验证仓库设置允许Actions创建发布:
yaml
jobs:
publish-tauri:
permissions:
contents: writeLinux Build Failures
Linux构建失败
Verify all dependencies are installed with the Ubuntu dependency installation step.
通过Ubuntu依赖安装步骤确认所有依赖已安装。
macOS Target Not Found
macOS目标未找到
Ensure Rust targets are installed for cross-compilation:
yaml
- uses: dtolnay/rust-toolchain@stable
with:
targets: 'aarch64-apple-darwin,x86_64-apple-darwin'确保已安装用于交叉编译的Rust目标:
yaml
- uses: dtolnay/rust-toolchain@stable
with:
targets: 'aarch64-apple-darwin,x86_64-apple-darwin'Cache Not Working
缓存未生效
Verify the workspace path matches your project structure:
yaml
- uses: swatinem/rust-cache@v2
with:
workspaces: './src-tauri -> target'确认工作区路径与项目结构匹配:
yaml
- uses: swatinem/rust-cache@v2
with:
workspaces: './src-tauri -> target'