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 username>',
name: '<github repo>',
},
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') }}
如果想要創建新的 release,需要在 commit 中帶上 tag。
- 更新
package.json
中的版本號,如1.0.0
git commit -am v1.0.0
git tag v1.0.0
git push && git push --tags
這樣 push 後如果 build 成功會生成一個 release 的 draft,可以選擇放出。