GitHub
本指南將說明如何在 GitHub Actions 中使用 tauri-action,以輕鬆建置和上傳您的應用程式,以及如何讓 Tauri 的更新器查詢新建立的 GitHub 發行版本以進行更新。
最後,它也將展示如何為 Linux Arm AppImages 設定更複雜的建置管線。
開始使用
若要設定 tauri-action
,您必須先設定 GitHub 儲存庫。您也可以在尚未設定 Tauri 的儲存庫上使用此動作,因為它可以自動為您初始化 Tauri,請參閱 action 的 readme 以取得必要的設定選項。
前往 GitHub 專案頁面上的 Actions 標籤,然後選取「New workflow」,接著選擇「Set up a workflow yourself」。將檔案替換為來自下方或來自 action 範例之一的工作流程。
設定
請參閱 tauri-action
readme 以取得所有可用的設定選項。
當您的應用程式不在儲存庫的根目錄時,請使用 projectPath
輸入。
您可以自由修改工作流程名稱、變更其觸發器,並新增更多步驟,例如 npm run lint
或 npm 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 及更高版本)建置和發佈您的應用程式。
此工作流程採取的步驟如下
- 使用
actions/checkout@v4
簽出儲存庫。 - 安裝建置應用程式所需的 Linux 系統依賴項。
- 使用
actions/setup-node@v4
設定 Node.js LTS 以及全域 npm/yarn/pnpm 套件資料的快取。 - 使用
dtolnay/rust-toolchain@stable
和swatinem/rust-cache@v2
設定 Rust 以及 Rust 建置產物的快取。 - 安裝前端依賴項,如果未設定為
beforeBuildCommand
,則執行 Web 應用程式的建置腳本。 - 最後,它使用
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 Runner 編譯
此工作流程使用 pguyot/arm-runner-action
直接在模擬的 Arm runner 上編譯。這彌合了 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/arm-runner-action@v2.6.5 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 環境 Token
GitHub Token 由 GitHub 自動為每個工作流程執行發行,無需進一步設定,這表示沒有洩漏密碼的風險。但是,此 Token 預設只有讀取權限,並且在執行工作流程時可能會收到「Resource not accessible by integration」錯誤。如果發生這種情況,您可能需要為此 Token 新增寫入權限。若要執行此操作,請前往您的 GitHub 專案設定,選取 Actions
,向下捲動至 Workflow permissions
,然後勾選「Read and write permissions」。
您可以在工作流程中透過此行看到 GitHub Token 傳遞到工作流程
env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
© 2025 Tauri 貢獻者。CC-BY / MIT