跳转到内容

GitHub

本指南将展示如何在 tauri-action 中使用 GitHub Actions,以便轻松构建和上传您的应用程序,以及如何使 Tauri 更新程序查询新创建的 GitHub 版本进行检查更新。

最后,它还将展示如何为 Linux ARM AppImages 设置更复杂的构建管道。

入门指南

要设置 tauri-action,您必须首先设置一个 GitHub 仓库。您也可以在尚未配置 Tauri 的仓库上使用此操作,因为它可以自动为您初始化 Tauri,请参阅 操作的 README 了解必要的配置选项。

转到您的 GitHub 项目页面上的“操作”选项卡,选择“新建流程”,然后选择“自行设置流程”。替换为以下链接中的文件或来自此处操作的示例之一。

配置

请参阅 tauri-actionREADME 了解所有可用的配置选项。

当您的应用程序不在仓库的根目录时,请使用 projectPath 输入。

您可以随意修改工作流程名称,更改其触发方式,并添加更多步骤,如 npm run lintnpm run test。重要的是,您需要在工作流程末尾保留以下行,因为这将运行构建脚本并发布您的应用程序。

如何触发

以下是示例工作流程和 tauri-action 示例中显示的发布工作流程,该工作流程由推送到 release 分支触发。操作会自动使用应用程序版本创建 Git 标签和 GitHub 版本的标题。

作为另一个例子,您也可以将触发更改为您在推送版本 Git 标签(例如 app-v0.7.0)时运行工作流程。

name: 'publish'
on:
push:
tags:
- 'app-v*'

有关可能的触发配置的完整列表,请参阅官方的 GitHub 文档

示例工作流程

以下是一个示例工作流程,它会在每次您推送到 release 分支时运行。

此工作流程将为 Linux x64、Windows x64、macOS x64 和 macOS Arm64(M1 以上)构建和发布您的应用程序。

此工作流程执行的步骤包括:

  1. 使用 actions/checkout@v4检出一 个仓库。
  2. 安装构建应用程序所需的 Linux 系统依赖项。
  3. 使用 actions/setup-node@v4设置 Node.js LTS 和全局 npm/yarn/pnpm 包数据的缓存。
  4. 使用 dtolnay/rust-toolchain@stableswatinem/rust-cache@v2设置 Rust 和 Rust 构建组件的缓存。
  5. 安装前端依赖项,如果不是配置为beforeBuildCommand,则运行Web应用的构建脚本。
  6. 最后,使用tauri-apps/tauri-action@v0运行tauri build,生成工件并创建GitHub发行版。
name: 'publish'
on:
workflow_dispatch:
push:
branches:
- release
jobs:
publish-tauri:
permissions:
contents: write
strategy:
fail-fast: false
matrix:
include:
- platform: 'macos-latest' # for Arm based macs (M1 and above).
args: '--target aarch64-apple-darwin'
- platform: 'macos-latest' # for Intel based macs.
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' # This must match the platform value defined above.
run: |
sudo apt-get update
sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
- name: setup node
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: 'yarn' # Set this to npm, yarn or pnpm.
- name: install Rust stable
uses: dtolnay/rust-toolchain@stable # Set this to dtolnay/rust-toolchain@nightly
with:
# Those targets are only used on macos runners so it's in an `if` to slightly speed up windows and linux builds.
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
# If you don't have `beforeBuildCommand` configured you may want to build your frontend here too.
run: yarn install # change this to npm or pnpm depending on which one you use.
- uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tagName: app-v__VERSION__ # the action automatically replaces \_\_VERSION\_\_ with the app version.
releaseName: 'App v__VERSION__'
releaseBody: 'See the assets to download this version and install.'
releaseDraft: true
prerelease: false
args: ${{ matrix.args }}

有关更多配置选项,请参阅tauri-action仓库及其示例

ARM 运行器编译

此工作流程使用pguyot/arm-runner-action在模拟的Arm运行器上直接编译。这填补了AppImage工具中缺失的交叉架构构建支持的空白。

name: 'Publish Linux Arm builds'
on:
workflow_dispatch:
push:
branches:
- release
jobs:
build:
runs-on: ubuntu-22.04
strategy:
matrix:
arch: [aarch64, armv7l]
include:
- arch: aarch64
cpu: cortex-a72
base_image: https://dietpi.com/downloads/images/DietPi_RPi-ARMv8-Bookworm.img.xz
deb: arm64
rpm: aarch64
appimage: aarch64
- arch: armv7l
cpu: cortex-a53
deb: armhfp
rpm: arm
appimage: armhf
base_image: https://dietpi.com/downloads/images/DietPi_RPi-ARMv7-Bookworm.img.xz
steps:
- uses: actions/checkout@v3
- name: Cache rust build artifacts
uses: Swatinem/rust-cache@v2
with:
workspaces: src-tauri
cache-on-failure: true
- name: Build app
uses: pguyot/[email protected]
with:
base_image: ${{ matrix.base_image }}
cpu: ${{ matrix.cpu }}
bind_mount_repository: true
image_additional_mb: 10240
optimize_image: no
#exit_on_fail: no
commands: |
# Prevent Rust from complaining about $HOME not matching eid home
export HOME=/root
# Workaround to CI worker being stuck on Updating crates.io index
export CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
# Install setup prerequisites
apt-get update -y --allow-releaseinfo-change
apt-get autoremove -y
apt-get install -y --no-install-recommends --no-install-suggests curl libwebkit2gtk-4.1-dev build-essential libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev patchelf libfuse2 file
curl https://sh.rustup.rs -sSf | sh -s -- -y
. "$HOME/.cargo/env"
curl -fsSL https://deb.nodesource.com/setup_lts.x | bash
apt-get install -y nodejs
# Install frontend dependencies
npm install
# Build the application
npm run tauri build -- --verbose
- name: Get app version
run: echo "APP_VERSION=$(jq -r .version src-tauri/tauri.conf.json)" >> $GITHUB_ENV
# TODO: Combine this with the basic workflow and upload the files to the Release.
- name: Upload deb bundle
uses: actions/upload-artifact@v3
with:
name: Debian Bundle
path: ${{ github.workspace }}/src-tauri/target/release/bundle/deb/appname_${{ env.APP_VERSION }}_${{ matrix.deb }}.deb
- name: Upload rpm bundle
uses: actions/upload-artifact@v3
with:
name: RPM Bundle
path: ${{ github.workspace }}/src-tauri/target/release/bundle/rpm/appname-${{ env.APP_VERSION }}-1.${{ matrix.rpm }}.rpm
- name: Upload appimage bundle
uses: actions/upload-artifact@v3
with:
name: AppImage Bundle
path: ${{ github.workspace }}/src-tauri/target/release/bundle/appimage/appname_${{ env.APP_VERSION }}_${{ matrix.appimage }}.AppImage

故障排除

GitHub 环境令牌

GitHub令牌将自动由GitHub为每个工作流程运行提供,无需进一步配置,这意味着没有泄密风险。但是,这个令牌默认只有读取权限,运行工作流时可能会遇到“资源无法通过集成访问”错误。如果发生这种情况,您可能需要为此令牌添加写入权限。为此,请转到您的GitHub项目设置,选择操作,向下滚动到工作流程权限,并检查“读取和写入权限”。

您可以通过以下工作流程中的这一行看到GitHub令牌被传递给工作流程

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

© 2025 Tauri贡献者。CC-BY / MIT