ミンミンの日記

o108minminの近況や感想など

tauri + workspaceのGitHub Actions設定例

Rustアドベントカレンダー3日目の記事です
既存のworkspaceにtauriで作成したディレクトリを追加したら、そこそこハマったので成功例を共有します。

想定読者

https://github.com/o108minmin/halberd

ディレクトリ構成

今回はCUIGUIが同居する下記のような構成

halberd
├── cargo.toml
├── halberd_core # ビジネスロジック
│   └── cargo.toml
├── halberd_cui # CUIゲートウェイ(clap)
│   └── cargo.toml
└── halberd_gui # GUIゲートウェイ(tauri)
    └── src-tauri/cargo.toml

Github Actionsの設定 https://github.com/o108minmin/halberd/tree/main/.github/workflows

tauriのビルド設定

基本的には下記のドキュメントに従えば良いが、workspace利用時は projectPathを設定する必要がある。

https://github.com/tauri-apps/tauri-action

今回のプロジェクトでの設定例

https://github.com/o108minmin/halberd/blob/main/.github/workflows/release.yml

    - name: install app dependencies and build it
      run: cd halberd_gui && yarn && yarn build
    - uses: tauri-apps/tauri-action@v0
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        releaseId: ${{ needs.release.outputs.release_id }}
        projectPath: ./halberd_gui

先にyarn buildまで終わらせ、そのあとtauri-actionsを呼び出す

tauri以外のビルド設定

今回だとCUI版も存在するので、そちらではtauri関連のモジュールはビルドしたくない。
(毎回tauriごとビルドするととても遅くなる)
そのためcargo buildする際に --workspace --exclude halberd_gui を引数に入れるとtauriが入ったcrateを除外することができる。

今回のプロジェクトでの設定例

https://github.com/o108minmin/halberd/blob/main/.github/workflows/release.yml

      - name: Cross build with all features Build project
        uses: actions-rs/cargo@v1
        with:
          use-cross: true
          command: build
          args: --release --target ${{ matrix.target }} --all-features --workspace --exclude halberd_gui

テストの場合も同様

https://github.com/o108minmin/halberd/blob/main/.github/workflows/test.yml

      - uses: actions-rs/cargo@v1
        with:
          command: llvm-cov
          args: --workspace --exclude halberd_gui

ハマったのはここらへんです。tauri使うと既存のCUIアプリにも簡単にGUIが生やせて楽しいので流行って欲しいですね。
もうちょっとうまいやり方があるような気もするので知見がたまったらまた共有します