| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
GitHub Action for building and releasing Electron apps
This is a GitHub Action for automatically building and releasing your Electron app using GitHub's CI/CD capabilities. It uses electron-builder to package your app and release it to a platform like GitHub Releases.
GitHub Actions allows you to build your app on macOS, Windows and Linux without needing direct access to each of these operating systems.
Install and configure electron-builder (v22+) in your Electron app. You can read about this in the project's docs or in my blog post.
If you need to compile code (e.g. TypeScript to JavaScript or Sass to CSS), make sure this is done using a build script in your package.json file. The action will execute that script before packaging your app. However, make sure that the build script does not run electron-builder, as this action will do that for you.
Add a workflow file to your project (e.g. .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@v4
- name: Install Node.js, NPM and Yarn
uses: actions/setup-node@v4
with:
node-version: 10
- name: Build/release Electron app
uses: samuelmeuli/action-electron-builder@v1
with:
# 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') }}Using this the workflow above, GitHub will build your app every time you push a commit.
When you want to create a new release, follow these steps:
After building successfully, the action will publish your release artifacts. By default, a new release draft will be created on GitHub with download links for your app. If you want to change this behavior, have a look at the electron-builder docs.
You can configure the action further with the following options:
See action.yml for a list of all possible input variables.
If you are building for macOS, you'll want your code to be signed. GitHub Actions therefore needs access to your code signing certificates:
Add the following options to your workflow's existing action-electron-builder step:
- name: Build/release Electron app
uses: samuelmeuli/action-electron-builder@v1
with:
# ...
mac_certs: ${{ secrets.mac_certs }}
mac_certs_password: ${{ secrets.mac_certs_password }}The same goes for Windows code signing (windows_certs and windows_certs_password secrets).
If you are building/releasing your Linux app for Snapcraft (which is electron-builder's default), you will additionally need to install and sign in to Snapcraft. This can be done using an action-snapcraft step before the action-electron-builder step:
- name: Install Snapcraft
uses: samuelmeuli/action-snapcraft@v1
# Only install Snapcraft on Ubuntu
if: startsWith(matrix.os, 'ubuntu')
with:
# Log in to Snap Store
snapcraft_token: ${{ secrets.snapcraft_token }}You can read here how you can obtain a snapcraft_token.
If you've configured electron-builder to notarize your Electron Mac app as described in this guide, you can use the following steps to let GitHub Actions perform the notarization for you:
Define the following secrets in your repository's settings on GitHub:
In your workflow file, add the following step before your action-electron-builder step:
- name: Prepare for app notarization
if: startsWith(matrix.os, 'macos')
# Import Apple API key for app notarization on macOS
run: |
mkdir -p ~/private_keys/
echo '${{ secrets.api_key }}' > ~/private_keys/AuthKey_${{ secrets.api_key_id }}.p8Pass the following environment variables to action-electron-builder:
- name: Build/release Electron app
uses: samuelmeuli/action-electron-builder@v1
with:
# ...
env:
# macOS notarization API key
API_KEY_ID: ${{ secrets.api_key_id }}
API_KEY_ISSUER_ID: ${{ secrets.api_key_issuer_id }}For an example of the action used in production (including app notarization and publishing to Snapcraft), see Mini Diary.
Suggestions and contributions are always welcome! Please discuss larger changes via issue before submitting a pull request.
| Back | FazBrowse Home | New Git URL |