Automating your Electron app’s build and release process can save a lot of time—and reduce human error. With GitHub Actions, we can create a workflow that not only builds and publishes Electron apps but also handles multiple operating systems and automatically generates changelogs for tagged releases.
Here’s how you can set it up.
Workflow Overview
This workflow triggers on every push to the main
branch. It does the following:
- Checks if the commit is a version tag (e.g.,
v1.2.3
) - Builds the Electron app on both Ubuntu and Windows
- Publishes releases only for tagged commits
- Generates a changelog for tagged releases (check this)
- Updates or creates a GitHub release
GitHub Actions Workflow File
name: Build/release
on:
push:
branches:
- 'main'
jobs:
release:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
steps:
# Step 1: Checkout the repository
- name: Check out repository
uses: actions/checkout@v5
# Step 2: Detect if commit is a tag
- uses: kaisugi/action-regex-match@v1.0.1
id: regex-match
with:
text: ${{ github.event.head_commit.message }}
regex: '^v[0-9]+\.[0-9]+\.[0-9]+$'
# Step 3: Set up Node.js
- name: Set up Node.js
uses: actions/setup-node@v5
with:
node-version: 20
cache: 'npm'
# Step 4: Package Electron (non-tagged commits)
- name: Package Electron
if: ${{ steps.regex-match.outputs.match == '' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npm i
npx electron-builder --publish never
# Step 5: Package and Publish Electron (tagged commits)
- name: Package and Publish Electron
if: ${{ steps.regex-match.outputs.match != '' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npm i
npx electron-builder --publish always
# Step 6: Build Changelog
- name: Build Changelog
if: ${{ steps.regex-match.outputs.match != '' }}
id: changelog
uses: ardalanamini/auto-changelog@v4
with:
mention-authors: false
mention-new-contributors: false
include-compare-link: false
semver: false
# Step 7: Update GitHub Release
- name: Update Release
if: ${{ steps.regex-match.outputs.match != '' }}
uses: ncipollo/release-action@v1.20.0
with:
body: ${{ steps.changelog.outputs.changelog }}
allowUpdates: true
tag: ${{ github.event.head_commit.message }}
name: Release ${{ github.event.head_commit.message }}
token: ${{ secrets.GITHUB_TOKEN }}
How It Works
Multi-OS Builds
The workflow uses a matrix strategy to run the release job on both Ubuntu and Windows. This ensures your Electron app is packaged correctly for multiple platforms without needing separate workflows.
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
Tag Detection
Instead of relying on bash scripts, this workflow uses action-regex-match to check if the commit message is a semantic version tag (vX.Y.Z
).
- uses: kaisugi/action-regex-match@v1.0.1
id: regex-match
with:
text: ${{ github.event.head_commit.message }}
regex: '^v[0-9]+\.[0-9]+\.[0-9]+$'
This outputs a match
variable we can use to determine whether to publish a release.
Conditional Steps
We use GitHub Actions’ if:
statements to separate regular builds from release builds:
match == '' → normal packaging
match != '' → publish and release
Changelog & Release
For tagged releases, the workflow automatically generates a changelog with auto-changelog
and updates the GitHub release with ncipollo/release-action
.
Top comments (0)