Electron local build can only build programs for the current system. You can use Github Action to automatically build programs for all platforms. Here is the process.
Install create-electron-app
npm install -g create-electron-app
Create project
create-electron-app myproject
cd myproject
Install dependencies
npm install --save-dev @electron-forge/publisher-github
In the created project folder, there is a forge.config.js
file. Add publishers settings in it:
publishers: [
{
name: '@electron-forge/publisher-github',
config: {
repository: {
owner: '<github username>',
name: '<github repo>',
},
draft: true,
},
},
],
Add Github Action settings .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') }}
If you want to create a new release, you need to include a tag in the commit.
- Update the version number in
package.json
, e.g.1.0.0
git commit -am v1.0.0
git tag v1.0.0
git push && git push --tags
After pushing, if the build is successful, a draft release will be generated, which can be chosen to be published.