下面这个例子是,当release分支有commit发生时,自动获取当前应用的版本信息,并使用缓存,分别构建前端和rust,并将构建好的包上传至指定tag的release上。在 platform处定义平台,这里我只选定了Win

releaseDraft让提交的release只是一个草稿,可以手动更改后发布。

这里前端用的Yarn,根据项目实际依赖工具来更改,以及应用名。

name: "publish"

on:
  push:
    branches:
      - release

# This is the example from the readme.
# On each push to the `release` branch it will create or update a GitHub release, build your app, and upload the artifacts to the release.

jobs:
  publish-tauri:
    permissions:
      contents: write
    strategy:
      fail-fast: false
      matrix:
        platform: [windows-latest]

    runs-on: ${{ matrix.platform }}
    steps:
      - uses: actions/checkout@v4

      - name: setup node
        uses: actions/setup-node@v4
        with:
          node-version: 20

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

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

      - name: install dependencies (ubuntu only)
        if: matrix.platform == 'ubuntu-20.04'
        run: |
          sudo apt-get update
          sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf

      - uses: actions/cache@v2
        with:
            path: '**/node_modules'
            key: ${{ runner.os }}-node-modules-${{ hashFiles('**/yarn.lock') }}

      - name: install frontend dependencies
        run: yarn install # change this to npm or pnpm depending on which one you use

      - name: build frontend
        run: yarn cross-env VITE_NETWORK_PROCESSOR=tauri vite build

      - uses: tauri-apps/tauri-action@v0
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          TAURI_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }}
          TAURI_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }}
        with:
          tagName: 应用名-v__VERSION__ # the action automatically replaces \_\_VERSION\_\_ with the app version
          releaseName: "应用名 v__VERSION__"
          releaseBody: "See the assets to download this version and install."
          releaseDraft: true
          prerelease: false