DEV Community

Sumanth Perambuduri
Sumanth Perambuduri

Posted on

Multi-OS Electron Build & Release with GitHub Actions

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:

  1. Checks if the commit is a version tag (e.g., v1.2.3)
  2. Builds the Electron app on both Ubuntu and Windows
  3. Publishes releases only for tagged commits
  4. Generates a changelog for tagged releases (check this)
  5. 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 }}

Enter fullscreen mode Exit fullscreen mode

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]
Enter fullscreen mode Exit fullscreen mode

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]+$'
Enter fullscreen mode Exit fullscreen mode

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)