Tauri开发的程序,使用github action快速跨平台编译并发布流程,包括Windows、mac.

原因

Tauri 严重依赖原生库和工具链,因此目前无法在某一平台实现交叉编译。最佳选择是使用托管在 GitHub ActionAzure PipelinesGitLab 或其他选项上的 CI/CD 管道进行编译。管道可以同时为每个平台运行编译,使编译和发布过程更加容易。

GitHub Actions

利用 GitHub Actions,在你的仓库中自动化、定制和执行你的软件开发工作流程。你可以发现、创建和共享操作,以执行你想要的任何工作,包括 CI/CD,并在一个完全定制的工作流程中组合操作。

创建 release.yml

在项目根路径下创建 .github/workflows 目录,在 .github/workflows 下创建 release.yml(文件名自定义) 文件。将以下内容复制到文件中:

配置文件

name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:

jobs:
release:
permissions:
contents: write
strategy:
fail-fast: false
matrix:
platform: [macos-latest, windows-latest] # Ubuntu-20.04 has been removed
runs-on: ${{ matrix.platform }}

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install dependencies (ubuntu only)
if: matrix.platform == 'ubuntu-20.04'
# You can remove libayatana-appindicator3-dev if you don't use the system tray feature.
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libayatana-appindicator3-dev librsvg2-dev

- name: Rust setup
uses: dtolnay/rust-toolchain@stable

- name: Rust cache
uses: swatinem/rust-cache@v2
with:
workspaces: "./src-tauri -> target"

- name: Sync node version and setup cache
uses: actions/setup-node@v3
with:
node-version: "lts/*"
cache: "npm" # Set this to npm, yarn or pnpm.

- name: Install frontend dependencies
# If you don't have `beforeBuildCommand` configured you may want to build your frontend here too.
run: npm install # Change this to npm, yarn or pnpm.

- name: Build the app
uses: tauri-apps/tauri-action@v0

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tagName: ${{ github.ref_name }} # This only works if your workflow triggers on new tags.
releaseName: "App Name v__VERSION__" # tauri-action replaces \_\_VERSION\_\_ with the app version.
releaseBody: "See the assets to download and install this version."
releaseDraft: true
prerelease: false

– 注意我这里只构建了windows和Mac os

触发 Action

使用 GitHub Tag 来触发 Action

# 创建 tag
git tag v0.1.0

# 推送 tag
git push --tag

完成以上操作在GitHub仓库的Actions可以看到正在构建的工作流,点击tag再点击replace页面就可以看的构建发布的程序了