npm run electron workflow (docmirror/dev-sidecar)
The npm run electron workflow from docmirror/dev-sidecar, explained and optimized by Latchkey.
CI health: C - fair
Run this on Latchkey for self-healing, caching, and up to 58% lower cost.
Grade your own workflow free or run it on Latchkey →What it does
This is the npm run electron workflow from the docmirror/dev-sidecar repository, a real project running GitHub Actions. It is shown here with attribution under its MPL-2.0 license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: "npm run electron"
on:
push:
branches:
- run*
- test*
- release*
paths-ignore:
- "_script/**"
- "doc/**"
- "**/*.md"
- "**/.gitignore"
- "**/LICENSE"
workflow_dispatch:
permissions:
contents: read
jobs:
npm-run-electron:
runs-on: ${{ contains(matrix.os, '-arm') && matrix.os || format('{0}-latest', matrix.os) }}
env:
ELECTRON_CACHE: ${{ github.workspace }}/.cache/electron
ELECTRON_BUILDER_CACHE: ${{ github.workspace }}/.cache/electron-builder
strategy:
fail-fast: false
matrix:
os:
- windows
- ubuntu
# - ubuntu-24.04-arm # 因难以申请到 ARM64 runner而放弃;注意该系统名称不应使用latest后缀
- macos
node:
- 22
steps:
- name: "Checkout"
uses: actions/checkout@v4.1.7
with:
submodules: true
fetch-depth: 0
- name: "Setup pnpm"
uses: pnpm/action-setup@v4
- name: 'Setup Node.js "${{ matrix.node }}.x" environment'
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
registry-url: https://npm.pkg.github.com/
cache: pnpm
- name: "Setup Python environment, because of electron-builder install-app-deps requires Python setup tools"
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: "Print"
run: |
echo "github.ref_type = ${{ github.ref_type }}";
echo "github.ref = ${{ github.ref }}";
echo "github.ref_name = ${{ github.ref_name }}";
- name: "npm -v | pnpm -v | python --version"
run: |
echo "======================================================================";
echo "npm -v";
echo "--------------------";
npm -v;
echo "======================================================================";
echo "pnpm -v";
echo "--------------------";
pnpm -v;
echo "======================================================================";
echo "python --version";
echo "--------------------";
python --version;
- name: "Setup electron cache"
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/.cache/electron
key: ${{ runner.os }}-electron-cache-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-electron-cache-
- name: "Setup electron-builder cache"
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/.cache/electron-builder
key: ${{ runner.os }}-electron-builder-cache-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-electron-builder-cache-
- name: "Set C++17 compiler flags (Linux / macOS)"
if: ${{ matrix.os != 'windows' }}
run: |
echo "CXXFLAGS=-std=c++17" >> $GITHUB_ENV
echo "CFLAGS=-std=c11" >> $GITHUB_ENV
- name: "Set C++17 compiler flags (Windows)"
if: ${{ matrix.os == 'windows' }}
run: |
echo "CL=/std:c++17" >> $env:GITHUB_ENV
- name: "pnpm install"
run: |
echo "======================================================================";
dir || ls -lah;
echo "======================================================================";
echo "pnpm install";
echo "--------------------";
pnpm install;
- name: "npm run electron"
working-directory: packages/gui
run: |
echo "======================================================================";
dir || ls -lah;
echo "======================================================================";
echo "npm run electron";
echo "--------------------";
npm run electron;
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: "npm run electron" on: push: branches: - run* - test* - release* paths-ignore: - "_script/**" - "doc/**" - "**/*.md" - "**/.gitignore" - "**/LICENSE" workflow_dispatch: permissions: contents: read concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: npm-run-electron: timeout-minutes: 30 runs-on: ${{ contains(matrix.os, '-arm') && matrix.os || format('{0}-latest', matrix.os) }} env: ELECTRON_CACHE: ${{ github.workspace }}/.cache/electron ELECTRON_BUILDER_CACHE: ${{ github.workspace }}/.cache/electron-builder strategy: fail-fast: false matrix: os: - windows - ubuntu # - ubuntu-24.04-arm # 因难以申请到 ARM64 runner而放弃;注意该系统名称不应使用latest后缀 - macos node: - 22 steps: - name: "Checkout" uses: actions/checkout@v4.1.7 with: submodules: true fetch-depth: 0 - name: "Setup pnpm" uses: pnpm/action-setup@v4 - name: 'Setup Node.js "${{ matrix.node }}.x" environment' uses: actions/setup-node@v4 with: node-version: ${{ matrix.node }} registry-url: https://npm.pkg.github.com/ cache: pnpm - name: "Setup Python environment, because of electron-builder install-app-deps requires Python setup tools" uses: actions/setup-python@v5 with: python-version: "3.10" - name: "Print" run: | echo "github.ref_type = ${{ github.ref_type }}"; echo "github.ref = ${{ github.ref }}"; echo "github.ref_name = ${{ github.ref_name }}"; - name: "npm -v | pnpm -v | python --version" run: | echo "======================================================================"; echo "npm -v"; echo "--------------------"; npm -v; echo "======================================================================"; echo "pnpm -v"; echo "--------------------"; pnpm -v; echo "======================================================================"; echo "python --version"; echo "--------------------"; python --version; - name: "Setup electron cache" uses: actions/cache@v4 with: path: ${{ github.workspace }}/.cache/electron key: ${{ runner.os }}-electron-cache-${{ hashFiles('**/pnpm-lock.yaml') }} restore-keys: | ${{ runner.os }}-electron-cache- - name: "Setup electron-builder cache" uses: actions/cache@v4 with: path: ${{ github.workspace }}/.cache/electron-builder key: ${{ runner.os }}-electron-builder-cache-${{ hashFiles('**/pnpm-lock.yaml') }} restore-keys: | ${{ runner.os }}-electron-builder-cache- - name: "Set C++17 compiler flags (Linux / macOS)" if: ${{ matrix.os != 'windows' }} run: | echo "CXXFLAGS=-std=c++17" >> $GITHUB_ENV echo "CFLAGS=-std=c11" >> $GITHUB_ENV - name: "Set C++17 compiler flags (Windows)" if: ${{ matrix.os == 'windows' }} run: | echo "CL=/std:c++17" >> $env:GITHUB_ENV - name: "pnpm install" run: | echo "======================================================================"; dir || ls -lah; echo "======================================================================"; echo "pnpm install"; echo "--------------------"; pnpm install; - name: "npm run electron" working-directory: packages/gui run: | echo "======================================================================"; dir || ls -lah; echo "======================================================================"; echo "npm run electron"; echo "--------------------"; npm run electron;
What changed
- Cancel superseded runs when a branch or PR gets a newer push.
- Add a job timeout so a hung step cannot burn hours of runner time.
1 third-party action is referenced by a movable tag. Pin it to the commit SHA (Latchkey resolves and applies this automatically) so a repointed tag cannot change what runs.
What Latchkey heals here
This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:
- Dependency installs
This workflow runs 1 job (3 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.