|
| 1 | +--- |
| 2 | +title: GitHub |
| 3 | +i18nReady: true |
| 4 | +--- |
| 5 | + |
| 6 | +import TranslationNote from '@components/i18n/TranslationNote.astro'; |
| 7 | + |
| 8 | +この章では、[GitHub Actions](https://docs.github.com/en/actions) の [tauri-action](https://github.com/tauri-apps/tauri-action) を使用して簡単にアプリをビルド&アップロードする方法と、Tauri のアップデーターでアップデート用に新しく作成された GitHub リリースを照会する方法を説明します。 |
| 9 | + |
| 10 | +章の最後では、Linux Arm AppImages 用の、より複雑なビルド・パイプラインを設定する方法も説明します。 |
| 11 | + |
| 12 | +:::note[コード署名] |
| 13 | + |
| 14 | +あなたのワークフローに Windows と macOS のコード署名を設定するには、以下の各プラットフォーム毎のガイドに従ってください: |
| 15 | + |
| 16 | +- [Windows でのコード署名](/ja/distribute/sign/windows/) |
| 17 | +- [macOS でのコード署名](/ja/distribute/sign/macos/) |
| 18 | + |
| 19 | +::: |
| 20 | + |
| 21 | +## 作業手順 |
| 22 | + |
| 23 | +`tauri-action` を設定するには、まず最初に GitHub リポジトリを設定する必要があります。この tauri-action は Tauri を自動的に初期化できるため、Tauri がまだ設定されていないリポジトリでも使用できます。必要な設定オプションについては、[tauri-action の readme](https://github.com/tauri-apps/tauri-action/#project-initialization)(英語版)を参照してください。 |
| 24 | + |
| 25 | +あなたの GitHub プロジェクト・ページの「Actions」タブに移動し、「新しいワークフロー New workflow」を選択し、「自分でワークフローを設定する Set up a workflow yourself」を選択します。そのファイルを下記の「[ワークフロー例](#ワークフロー例)」または GitHub サイトの「[Actions の例](https://github.com/tauri-apps/tauri-action/tree/dev/examples)」のいずれかのワークフローに置き換えてください。 |
| 26 | + |
| 27 | +## 設定 |
| 28 | + |
| 29 | +利用可能な設定項目については、「`tauri-action` の [readme](https://github.com/tauri-apps/tauri-action/#inputs)」ファイルを参照してください。 |
| 30 | + |
| 31 | +あなたのアプリが「リポジトリのルート」に置かれていない場合は、「`projectPath` 入力項目」を使用します。 |
| 32 | + |
| 33 | +「ワークフロー名」の修正や「トリガー」の変更、および「`npm run lint`」や「`npm run test`」といったステップの追加などは、自由に行なえます。重要なのは、**以下の行をワークフローの最後に残しておくこと**です。この行があなたのアプリのビルド・スクリプトを実行し、リリースするためです。 |
| 34 | + |
| 35 | +### トリガーの方法 |
| 36 | + |
| 37 | +以下の設定事例や「`tauri-action` の例」に示されているリリース・ワークフローでは、「`release` ブランチへのプッシュ」によってトリガーが行なわれます。このアクションは、アプリケーションのバージョンに基づいて、GitHub リリース用の「git タグ」と「タイトル」を自動的に作成します。 |
| 38 | + |
| 39 | +別の事例としては、「`app-v0.7.0`」のような「バージョン git タグ」のプッシュ時にワークフローを実行するようにトリガーを変更することもできます。 |
| 40 | + |
| 41 | +```yaml |
| 42 | +name: 'publish' |
| 43 | + |
| 44 | +on: |
| 45 | + push: |
| 46 | + tags: |
| 47 | + - 'app-v*' |
| 48 | +``` |
| 49 | +
|
| 50 | +設定可能なトリガー内容の完全なリストについては、公式の [GitHub ドキュメント](https://docs.github.com/ja/actions/using-workflows/events-that-trigger-workflows) をご覧ください。 |
| 51 | +
|
| 52 | +## ワークフロー例 |
| 53 | +
|
| 54 | +以下の例は、`release` ブランチにプッシュするたびに実行されるように設定されたワークフローです。 |
| 55 | + |
| 56 | +このワークフローでは、Linux x64、Windows x64、macOS x64、macOS Arm64(M1 以上)用のアプリをビルドしてリリースします。 |
| 57 | + |
| 58 | +このワークフローが実行する手順は次のとおりです: |
| 59 | + |
| 60 | +1. `actions/checkout@v4` を使用してリポジトリを「チェックアウト」します。 |
| 61 | +2. アプリのビルドに必要な Linux システムの依存関係をインストールします。 |
| 62 | +3. `actions/setup-node@v4` を使用して、Node.js LTS(長期サポート版)とグローバル npm/yarn/pnpm パッケージ・データ用のキャッシュをセットアップします。 |
| 63 | +4. `dtolnay/rust-toolchain@stable` と `swatinem/rust-cache@v2` を使用して、Rust と「Rust のビルド成果物 artifact」(アプリをテストまたはデプロイするために必要なファイル)用のキャッシュをセットアップします。 |
| 64 | +5. フロントエンドの依存関係をインストールし、[`beforeBuildCommand`](/reference/config/#beforebuildcommand) として設定されていない場合は、Web アプリのビルド・スクリプトを実行します。 |
| 65 | +6. 最後に、`tauri-apps/tauri-action@v0` を使用して `tauri build` を実行し、成果物を生成して、GitHub リリースを作成します。 |
| 66 | + |
| 67 | +<TranslationNote lang="ja"> |
| 68 | + |
| 69 | +**成果物** artifact: ソフトウェア開発における「中間生成物」を指す用語。日本語の標準訳は「成果物」ですが、その意味内容が把握しづらいのが難。Microsoft Terminology Search サイトには、artifact type に「ツールが公開するデータの種類で、・・・、例としては、ソースファイル、欠陥、要件、テスト結果、ビルドなど」との説明があります。 |
| 70 | + |
| 71 | +</TranslationNote> |
| 72 | + |
| 73 | +```yaml |
| 74 | +name: 'publish' |
| 75 | +
|
| 76 | +on: |
| 77 | + workflow_dispatch: |
| 78 | + push: |
| 79 | + branches: |
| 80 | + - release |
| 81 | +
|
| 82 | +jobs: |
| 83 | + publish-tauri: |
| 84 | + permissions: |
| 85 | + contents: write |
| 86 | + strategy: |
| 87 | + fail-fast: false |
| 88 | + matrix: |
| 89 | + include: |
| 90 | + - platform: 'macos-latest' # Arm 版 macs 用(M1 以降) |
| 91 | + args: '--target aarch64-apple-darwin' |
| 92 | + - platform: 'macos-latest' # Intel 版 macs 用 |
| 93 | + args: '--target x86_64-apple-darwin' |
| 94 | + - platform: 'ubuntu-22.04' |
| 95 | + args: '' |
| 96 | + - platform: 'windows-latest' |
| 97 | + args: '' |
| 98 | +
|
| 99 | + runs-on: ${{ matrix.platform }} |
| 100 | + steps: |
| 101 | + - uses: actions/checkout@v4 |
| 102 | +
|
| 103 | + - name: install dependencies (ubuntu only) |
| 104 | + if: matrix.platform == 'ubuntu-22.04' # この項目は、上記で定義されたプラットフォーム値と一致する必要があります |
| 105 | + run: | |
| 106 | + sudo apt-get update |
| 107 | + sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf |
| 108 | +
|
| 109 | + - name: setup node |
| 110 | + uses: actions/setup-node@v4 |
| 111 | + with: |
| 112 | + node-version: lts/* |
| 113 | + cache: 'yarn' # この項目には、npm、yarn、pnpm のいずれかを設定 |
| 114 | +
|
| 115 | + - name: install Rust stable |
| 116 | + uses: dtolnay/rust-toolchain@stable # この項目には、dtolnay/rust-toolchain@nightly と設定 |
| 117 | + with: |
| 118 | + # これらのターゲットは macOS ランナーでのみ使用されるため、Windows および Linux ビルドをわずかに高速化するために `if` 内に置きます |
| 119 | + targets: ${{ matrix.platform == 'macos-latest' && 'aarch64-apple-darwin,x86_64-apple-darwin' || '' }} |
| 120 | + |
| 121 | + - name: Rust cache |
| 122 | + uses: swatinem/rust-cache@v2 |
| 123 | + with: |
| 124 | + workspaces: './src-tauri -> target' |
| 125 | + |
| 126 | + - name: install frontend dependencies |
| 127 | + # `beforeBuildCommand` が設定されていない場合は、ここでフロントエンドをビルドすることも可能です |
| 128 | + run: yarn install # 使用するものに応じて、ここを npm または pnpm に変更します |
| 129 | + |
| 130 | + - uses: tauri-apps/tauri-action@v0 |
| 131 | + env: |
| 132 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 133 | + with: |
| 134 | + tagName: app-v__VERSION__ # このアクションにより、\_\_VERSION\_\_ がアプリのバージョンに自動的に置き換えられます |
| 135 | + releaseName: 'App v__VERSION__' |
| 136 | + releaseBody: 'See the assets to download this version and install.' |
| 137 | + releaseDraft: true |
| 138 | + prerelease: false |
| 139 | + args: ${{ matrix.args }} |
| 140 | +``` |
| 141 | +
|
| 142 | +詳細な設定オプションについては、[`tauri-action`](https://github.com/tauri-apps/tauri-action) リポジトリとその [事例 examples](https://github.com/tauri-apps/tauri-action/blob/dev/examples/) を参照してください。 |
| 143 | + |
| 144 | +:::caution |
| 145 | + |
| 146 | +GitHub Actions の [使用制限、支払い、管理](https://docs.github.com/ja/actions/learn-github-actions/usage-limits-billing-and-administration) に関するドキュメントをよくお読みください。 |
| 147 | + |
| 148 | +::: |
| 149 | + |
| 150 | +## Arm ランナーによるコンパイル |
| 151 | + |
| 152 | +このワークフローでは、[`pguyot/arm-runner-action`](https://github.com/pguyot/arm-runner-action) を使用して、エミュレートされた「Arm ランナー」上で直接コンパイルします。これにより、AppImage ツールに欠けているアーキテクチャ間のビルド機能を補完します。 |
| 153 | + |
| 154 | +:::danger |
| 155 | +`arm-runner-action` は GitHub の標準ランナーよりも**はるかに**遅いため、ビルド時間に応じて課金されるプライベート・リポジトリでは注意が必要です。新規の `create-tauri-app` プロジェクトのキャッシュなしビルドでは約 1 時間かかります。 |
| 156 | +::: |
| 157 | + |
| 158 | +```yaml |
| 159 | +name: 'Publish Linux Arm builds' |
| 160 | +
|
| 161 | +on: |
| 162 | + workflow_dispatch: |
| 163 | + push: |
| 164 | + branches: |
| 165 | + - release |
| 166 | +
|
| 167 | +jobs: |
| 168 | + build: |
| 169 | + runs-on: ubuntu-22.04 |
| 170 | +
|
| 171 | + strategy: |
| 172 | + matrix: |
| 173 | + arch: [aarch64, armv7l] |
| 174 | + include: |
| 175 | + - arch: aarch64 |
| 176 | + cpu: cortex-a72 |
| 177 | + base_image: https://dietpi.com/downloads/images/DietPi_RPi5-ARMv8-Bookworm.img.xz |
| 178 | + deb: arm64 |
| 179 | + rpm: aarch64 |
| 180 | + appimage: aarch64 |
| 181 | + - arch: armv7l |
| 182 | + cpu: cortex-a53 |
| 183 | + deb: armhfp |
| 184 | + rpm: arm |
| 185 | + appimage: armhf |
| 186 | + base_image: https://dietpi.com/downloads/images/DietPi_RPi-ARMv7-Bookworm.img.xz |
| 187 | +
|
| 188 | + steps: |
| 189 | + - uses: actions/checkout@v3 |
| 190 | +
|
| 191 | + - name: Cache rust build artifacts |
| 192 | + uses: Swatinem/rust-cache@v2 |
| 193 | + with: |
| 194 | + workspaces: src-tauri |
| 195 | + cache-on-failure: true |
| 196 | +
|
| 197 | + - name: Build app |
| 198 | + uses: pguyot/arm-runner-action@v2.6.5 |
| 199 | + with: |
| 200 | + base_image: ${{ matrix.base_image }} |
| 201 | + cpu: ${{ matrix.cpu }} |
| 202 | + bind_mount_repository: true |
| 203 | + image_additional_mb: 10240 |
| 204 | + optimize_image: no |
| 205 | + #exit_on_fail: no |
| 206 | + commands: | |
| 207 | + # Prevent Rust from complaining about $HOME not matching eid home |
| 208 | + export HOME=/root |
| 209 | +
|
| 210 | + # Workaround to CI worker being stuck on Updating crates.io index |
| 211 | + export CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse |
| 212 | +
|
| 213 | + # Install setup prerequisites |
| 214 | + apt-get update -y --allow-releaseinfo-change |
| 215 | + apt-get autoremove -y |
| 216 | + 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 |
| 217 | + curl https://sh.rustup.rs -sSf | sh -s -- -y |
| 218 | + . "$HOME/.cargo/env" |
| 219 | + curl -fsSL https://deb.nodesource.com/setup_lts.x | bash |
| 220 | + apt-get install -y nodejs |
| 221 | +
|
| 222 | + # Install frontend dependencies |
| 223 | + npm install |
| 224 | +
|
| 225 | + # Build the application |
| 226 | + npm run tauri build -- --verbose |
| 227 | +
|
| 228 | + - name: Get app version |
| 229 | + run: echo "APP_VERSION=$(jq -r .version src-tauri/tauri.conf.json)" >> $GITHUB_ENV |
| 230 | +
|
| 231 | + # TODO: Combine this with the basic workflow and upload the files to the Release. |
| 232 | + - name: Upload deb bundle |
| 233 | + uses: actions/upload-artifact@v3 |
| 234 | + with: |
| 235 | + name: Debian Bundle |
| 236 | + path: ${{ github.workspace }}/src-tauri/target/release/bundle/deb/appname_${{ env.APP_VERSION }}_${{ matrix.deb }}.deb |
| 237 | +
|
| 238 | + - name: Upload rpm bundle |
| 239 | + uses: actions/upload-artifact@v3 |
| 240 | + with: |
| 241 | + name: RPM Bundle |
| 242 | + path: ${{ github.workspace }}/src-tauri/target/release/bundle/rpm/appname-${{ env.APP_VERSION }}-1.${{ matrix.rpm }}.rpm |
| 243 | +
|
| 244 | + - name: Upload appimage bundle |
| 245 | + uses: actions/upload-artifact@v3 |
| 246 | + with: |
| 247 | + name: AppImage Bundle |
| 248 | + path: ${{ github.workspace }}/src-tauri/target/release/bundle/appimage/appname_${{ env.APP_VERSION }}_${{ matrix.appimage }}.AppImage |
| 249 | +``` |
| 250 | + |
| 251 | +## トラブル・シューティング |
| 252 | + |
| 253 | +### GitHub 環境トークン |
| 254 | + |
| 255 | +GitHub トークンは、追加の設定を行なうことなく、各ワークフローの実行ごとに GitHub によって自動的に発行されます。このため、「シークレット」漏洩のリスクはありません。しかしながら、デフォルトではこのトークンには「読み取り権限」しか付与されていないため、ワークフローの実行時に「統合によってリソースにアクセスできません」(アクセス権不足)というエラーが表示される場合があります。その場合には、このトークンに「書き込み権限」を追加する必要があるかもしれません。権限を追加するには、「GitHub project settings」に移動し「`Actions`」を選択、「`Workflow permissions`」(ワークフロー権限)までスクロールダウンして、「Read and write permissions」(読み取りと書き込み権限)にチェックを入れてください。 |
| 256 | + |
| 257 | +GitHub トークンが、ワークフロー内の以下の行を通じてワークフローに渡されていることを確認できます。 |
| 258 | + |
| 259 | +```yaml |
| 260 | +env: |
| 261 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 262 | +``` |
| 263 | + |
| 264 | +<div style="text-align: right;"> |
| 265 | + 【※ この日本語版は、「Apr 9, 2025 英語版」に基づいています】 |
| 266 | +</div> |
0 commit comments