banner
绘素

绘素的Blog

twitter
github
email

Electronアプリを作成し、Github Actionを使用してクロスプラットフォームアプリをビルドする

Electron ローカルビルドは現在のシステムのプログラムのみをビルドできますが、Github Action を使用してクロスプラットフォームのプログラムを自動ビルドすることもできます。以下に手順を記録します。

create-electron-app をインストールします。

npm install -g create-electron-app

プロジェクトを作成します。

create-electron-app myproject
cd myproject

依存関係をインストールします。

npm install --save-dev @electron-forge/publisher-github

作成したプロジェクトフォルダ内に forge.config.js がありますので、publishers の設定を追加します。

publishers: [
    {
      name: '@electron-forge/publisher-github',
      config: {
        repository: {
          owner: '<githubのユーザー名>',
          name: '<githubのリポジトリ名>',
        },
        draft: true,
      },
    },
  ],

Github Action の設定を追加します .github/workflows/build.yml

name: Build/release

on:
  push

jobs:
  release:
    runs-on: ${{ matrix.os }}

    strategy:
      matrix:
        os: [macos-latest, ubuntu-latest, windows-latest]

    steps:
      - name: Check out Git repository
        uses: actions/checkout@v1

      - name: Install Node.js, NPM and Yarn
        uses: actions/setup-node@v1
        with:
          node-version: 16

      - name: Build/release Electron app
        uses: wenwuwu/action-electron-forge@v1.4.0
        with:
          package_root: "."
          # GitHub token, automatically provided to the action
          # (No need to define this secret in the repo settings)
          github_token: ${{ secrets.github_token }}

          # If the commit is tagged with a version (e.g. "v1.0.0"),
          # release the app after building
          release: ${{ startsWith(github.ref, 'refs/tags/v') }}

新しいリリースを作成する場合は、コミットにタグを付ける必要があります。

  1. package.json のバージョン番号を更新します(例: 1.0.0)。
  2. git commit -am v1.0.0 を実行します。
  3. git tag v1.0.0 を実行します。
  4. git push && git push --tags を実行します。

これにより、ビルドが成功した場合、リリースのドラフトが生成され、公開するかどうかを選択できます。

読み込み中...
文章は、創作者によって署名され、ブロックチェーンに安全に保存されています。