electron-userland / electron-builder

A complete solution to package and build a ready for distribution Electron app with “auto update” support out of the box
https://www.electron.build
MIT License
13.72k stars 1.74k forks source link

NSIS does not work on GitHub Actions #8613

Open minai621 opened 1 month ago

minai621 commented 1 month ago

When using windows@latest as the GitHub Actions runner OS, the default version of NSIS is 3.10.0.

However, electron-builder requires version 3.0.4.1, and because it cannot find this version, the following error occurs:

exited          command=makensis.exe code=-4058 pid=undefined
⨯ spawn C:\Users\runneradmin\AppData\Local\electron-builder\Cache\nsis\nsis-3.0.4.1\Bin\makensis.exe ENOENT  failedTask=build stackTrace=Error: spawn C:\Users\runneradmin\AppData\Local\electron-builder\Cache\nsis\nsis-3.0.4.1\Bin\makensis.exe ENOENT

Here is my action script

name: electron-build
on: push

jobs:
  release:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [macos-latest, windows-latest]
        node-version: [18.x]

    steps:
      - name: Check out Git repository
        uses: actions/checkout@v4

      - name: Install Node.js
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}

      - name: Install pnpm
        uses: pnpm/action-setup@v2

      - name: Install dependencies
        run: pnpm install --prefer-offline --no-frozen-lockfile

      - name: Deploy native project
        run: pnpm --filter native deploy ./standalone-native

      - name: Build/release Electron app (macOS and Linux)
        if: runner.os != 'Windows'
        env:
          GH_TOKEN: ${{ secrets.github_token }}
          DEBUG: electron-builder
        working-directory: ./standalone-native
        run: pnpm run release

      - name: Build/release Electron app (Windows)
        if: runner.os == 'Windows'
        env:
          GH_TOKEN: ${{ secrets.github_token }}
          DEBUG: electron-builder,electron-builder:*
        working-directory: ./standalone-native
        run: pnpm run build && pnpx electron-builder --win --x64 --publish always

My package.json build configuration is as follows

"build": {
    "publish": {
      "provider": "github",
      "releaseType": "draft"
    },
    "appId": "com.example.product",
    "productName": "product",
    "files": [
      "dist/**/*",
      "node_modules/**/*",
      "package.json",
      "!node_modules/**/*.{ts,map}"
    ],
    "directories": {
      "output": "release"
    },
    "mac": {
      "target": "dmg"
    },
    "win": {
      "target": [
        {
          "target": "nsis",
          "arch": [
            "x64"
          ]
        }
      ]
    },
    "nsis": {
      "oneClick": false,
      "allowToChangeInstallationDirectory": true
    },
    "linux": {
      "target": "AppImage"
    }
  }

It seems that the issue is related to the cache for NSIS electron-builder\Cache\nsis\nsis-3.0.4.1\Bin\makensis.exe ENOENT Could you help me understand why this issue occurs and what might be causing the cache problem?

mmaietta commented 1 month ago

Does this reproduce locally as well?

There should be a file at C:\Users\<user name>\AppData\Local\electron-builder\Cache\nsis\nsis-3.0.4.1\Bin/makensis.exe

minai621 commented 1 month ago

@mmaietta

Does this reproduce locally as well?

There should be a file at C:\Users\<user name>\AppData\Local\electron-builder\Cache\nsis\nsis-3.0.4.1\Bin/makensis.exe

makensis.exe exists locally on my machine. It can only not be found in the GitHub Actions CI environment.

mmaietta commented 1 month ago

Tbh, I've never seen this issue before and electron-builder's unit tests run on the latest windows/mac/ubuntu runners without issue, so I'm confused as to why that file doesn't exist in the github runner. Was this working previously for you?

To block you in the interim, can you set this var to the directory that 3.10.0 makensis.exe exists in and see if that resolves your issue for now?

process.env.ELECTRON_BUILDER_NSIS_DIR = <path to directory containing makensis.exe>
minai621 commented 1 month ago

@mmaietta In local machine testing:

  1. Building for Windows on macOS works normally.
  2. Building for Windows on Windows still fails to spawn makensis.exe (makensis.exe exists in the actual path).

You can reproduce this issue using the GitHub repository at https://github.com/minai621/builder-test

To reproduce on Windows:

  1. Run pnpm install
  2. Run pnpm run release

The error occurs during the NSIS step of the build process.

mmaietta commented 1 month ago

@beyondkmp would you be willing to take a look at this?

minai621 commented 1 month ago

@mmaietta I'm facing build failures on my local Windows machine. There's an ongoing issue where the spawn command fails to execute nsis.exe. Would you please confirm if Windows builds work properly with these versions

mmaietta commented 1 month ago

The GH CI/CD runs on node 18 currently, and all historical CI runs completed successfully on master branch as well, so yes, Windows builds work properly with node 18 and eb 25.1.8. Version of electron shouldn't matter

beyondkmp commented 1 month ago

Using pnpx will report an error about makensis.exe not being found. Because Windows has a maximum path length of 260 characters. This can be resolved by setting pnpm config -g set virtual-store-dir-max-length 60 to control the length.

https://github.com/pnpm/pnpm/issues/8402#issuecomment-2279614428

https://github.com/beyondkmp/builder-test/blob/4c79f5f0118109876ec2733d48b7a0756e091e1b/.github/workflows/windows-build.yml#L64

However, my recommendation is to avoid using pnpx and instead directly use pnpm run build/release. This way, it will use files directly from node_modules, and the path length won't exceed 260 characters.