Skip to content

Build and Publish Electron App #36

Build and Publish Electron App

Build and Publish Electron App #36

name: Build and Publish Electron App
# REQUIRES: Repo Admins allowed to bypass branch protection policies and push directly to main.
# REQUIRES: A Repo Admin creates a PAT (Personal Access Token) and sets it as GIT_PAT secret.
on:
# Manually triggered
workflow_dispatch:
inputs:
versionChange: # How much to increment the version number by.
description: 'Version Change'
required: true
default: 'none'
type: choice
options:
- patch
- minor
- major
jobs:
check_typescript_errors:
runs-on: ubuntu-latest
steps:
# Checkout the code
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: false
sparse-checkout: |
desktop
# Setup Node.js
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
# Install dependencies
- name: Install dependencies
working-directory: desktop
run: |
npm i
# Check for TypeScript errors
- name: Check for TypeScript errors
working-directory: desktop
run: |
npm run typecheck
version_bump:
runs-on: ubuntu-latest
needs: check_typescript_errors
outputs:
VERSION: ${{ steps.package_version.outputs.VERSION }}
steps:
# Checkout the code
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: false
# Bump version
- name: Bump version in package.json
run: npm run bump:${{ github.event.inputs.versionChange }}
working-directory: desktop
# Get the new version number
- name: Get the version from package.json
id: package_version
run: echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
working-directory: desktop
# Commit changes to the repo
- name: Commit version bump
run: |
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git add desktop/package.json
git commit -m "Bumped version to ${{ steps.package_version.outputs.VERSION }}"
git remote set-url origin https://x-access-token:${{ secrets.GIT_PAT }}@github.com/${{ github.repository }}
git push origin main
build_app:
runs-on: ${{ matrix.os }}
needs: version_bump
strategy:
matrix:
os: [windows-latest, macos-latest]
env:
GH_TOKEN: ${{ secrets.GIT_PAT }}
steps:
# Checkout the code
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all tags and branches
# Get latest changes
- name: Get latest changes
run: git pull
# Set up Node.js
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
# Install dependencies
- name: Install dependencies
run: |
npm install
working-directory: desktop
# Build for the platform
- name: Build Electron App for ${{ matrix.os }}
run: npm run build:${{ matrix.os }}
working-directory: desktop
# Upload artifacts
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: build-artifacts-${{ matrix.os }}
path: desktop/dist/
publish_release:
runs-on: ubuntu-latest
needs: [version_bump, build_app]
steps:
# Checkout code
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
# Download MacOs build artifacts
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
path: ./desktop/dist/
# Create a GitHub release
- name: Create GitHub Release
id: create_release
uses: softprops/action-gh-release@v2
with:
files: |
./desktop/dist/**/*.exe
./desktop/dist/**/*.dmg
tag_name: ${{ needs.version_bump.outputs.VERSION }}
name: Release ${{ needs.version_bump.outputs.VERSION }}
body: "Release ${{ needs.version_bump.outputs.VERSION }} for electron-updater"
prerelease: false