Skip to content

Commit e4e6557

Browse files
authored
fix(ci): latest electron version breaks CI tests (#484)
* chore: fix electron@41 for node 14 * chore: try fixing electron install * chore: try fixing electron install * chore: try fixing electron install * chore: try fixing electron install * chore: try fixing electron install * chore: try fixing electron install * chore: try fixing electron install * chore: try fixing electron install * chore: try fixing electron install * chore: disable electron 16 test * chore: try disabling old workarounds * chore: try disabling old workarounds
1 parent 73319b4 commit e4e6557

3 files changed

Lines changed: 78 additions & 27 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Workaround: electron@42 ships without a postinstall script and lazily
4+
# downloads its binary on the first require('electron'). Its install.js
5+
# uses @electron/get (ESM, loaded via require(esm)) and extract-zip. On
6+
# recent Node (observed on Node 26) the extract-zip stage silently exits
7+
# 0 without writing node_modules/electron/path.txt, so subsequent
8+
# require('electron') calls fail with ENOENT.
9+
#
10+
# This script downloads the binary with @electron/get (which works on its
11+
# own) and extracts it with the system `unzip`, then writes path.txt the
12+
# way install.js would have.
13+
#
14+
# TODO: try removing this script and the workflow call to it when
15+
# upgrading to electron 43 or newer -- upstream may have fixed the
16+
# install.js bug by then.
17+
18+
set -euo pipefail
19+
20+
ELECTRON_DIR="node_modules/electron"
21+
22+
# electron <42 has a working postinstall that writes path.txt itself, so
23+
# we only run when path.txt is missing.
24+
if [ -f "$ELECTRON_DIR/path.txt" ]; then
25+
exit 0
26+
fi
27+
28+
RED='\033[1;31m'
29+
NC='\033[0m'
30+
ELECTRON_VERSION=$(node -p "require('./$ELECTRON_DIR/package.json').version")
31+
printf "${RED}=====================================================================${NC}\n"
32+
printf "${RED}WARNING: applying broken-electron-installer workaround for electron@${ELECTRON_VERSION}.${NC}\n"
33+
printf "${RED}Try removing .github/scripts/install-electron.sh and its workflow call${NC}\n"
34+
printf "${RED}when upgrading to electron 43 or newer.${NC}\n"
35+
printf "${RED}=====================================================================${NC}\n"
36+
37+
ZIPPATH=$(cd "$ELECTRON_DIR" && node -e "(async () => {
38+
const { downloadArtifact } = await import('@electron/get');
39+
const { version } = require('./package.json');
40+
const zipPath = await downloadArtifact({ version, artifactName: 'electron', platform: process.platform, arch: process.arch });
41+
process.stdout.write(zipPath);
42+
})().catch(e => { console.error(e); process.exit(1); });")
43+
44+
echo "Downloaded $ZIPPATH, extracting via system unzip..."
45+
mkdir -p "$ELECTRON_DIR/dist"
46+
unzip -q -o "$ZIPPATH" -d "$ELECTRON_DIR/dist"
47+
48+
case "${RUNNER_OS:-$(uname -s)}" in
49+
Linux|Linux*) printf electron > "$ELECTRON_DIR/path.txt" ;;
50+
macOS|Darwin*) printf "Electron.app/Contents/MacOS/Electron" > "$ELECTRON_DIR/path.txt" ;;
51+
Windows|MINGW*|MSYS*|CYG*) printf electron.exe > "$ELECTRON_DIR/path.txt" ;;
52+
*) echo "ERROR: unknown OS '${RUNNER_OS:-$(uname -s)}'"; exit 1 ;;
53+
esac
54+
55+
test -f "$ELECTRON_DIR/path.txt" || { echo "ERROR: path.txt missing after workaround"; ls -la "$ELECTRON_DIR/"; exit 1; }

.github/workflows/tests.yml

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
name: Tests
22

3-
on:
4-
- pull_request
5-
- push
3+
on: push
64

75
env:
86
CI: 1
97

8+
defaults:
9+
run:
10+
shell: bash
11+
1012
jobs:
1113
main:
12-
defaults:
13-
run:
14-
shell: bash
15-
1614
strategy:
1715
matrix:
1816
include:
@@ -21,20 +19,13 @@ jobs:
2119
node_version: latest
2220
electron_version: latest
2321
experimental: false
24-
- os: ubuntu-latest
25-
node_version: 16
26-
electron_version: latest
27-
experimental: false
2822
- os: ubuntu-latest
2923
node_version: 14
30-
electron_version: latest
24+
electron_version: 41
25+
nw_version: 0.81.0
3126
experimental: true
3227

3328
# Different electron version
34-
- os: ubuntu-latest
35-
node_version: latest
36-
electron_version: 16
37-
experimental: true
3829
- os: ubuntu-latest
3930
node_version: latest
4031
electron_version: 13
@@ -46,7 +37,7 @@ jobs:
4637
electron_version: latest
4738
experimental: true
4839
- os: windows-latest
49-
node_version: builtin # For an unknown reason, setup-node freezes
40+
node_version: latest
5041
electron_version: latest
5142
experimental: true
5243

@@ -55,19 +46,23 @@ jobs:
5546
continue-on-error: ${{ matrix.experimental }}
5647

5748
steps:
58-
- uses: actions/checkout@v4
59-
- uses: actions/setup-node@v4
49+
- uses: actions/checkout@v6
50+
- uses: actions/setup-node@v6
6051
with:
6152
node-version: ${{ matrix.node_version }}
62-
if: matrix.node_version != 'builtin'
63-
64-
- run: npm config set script-shell 'bash'
65-
if: runner.os == 'Windows'
66-
67-
- run: npm install
6853

69-
- run: npm install -D electron@${{ matrix.electron_version }}
70-
if: matrix.electron_version != 'latest'
54+
- run: |
55+
if [ "${{ matrix.electron_version }}" != 'latest' ]; then
56+
npm install -D electron@${{ matrix.electron_version }}
57+
fi
58+
if [ -n "${{ matrix.nw_version }}" ]; then
59+
npm install -D nw@${{ matrix.nw_version }}
60+
fi
61+
npm install
62+
# Workaround for broken electron@42 installer on modern Node.
63+
# Remove this call when upgrading to electron 43+ and the
64+
# upstream installer works again.
65+
.github/scripts/install-electron.sh
7166
7267
- run: |
7368
if [ "${RUNNER_OS}" = 'Linux' ]; then

e2e/vite-isolation-context-sandbox/vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default defineConfig({
3131
vite: mergeConfig(commonConfig, {
3232
resolve: {
3333
browserField: false,
34+
conditions: ['node', 'module', 'import', 'require', 'default'],
3435
}
3536
}),
3637
},

0 commit comments

Comments
 (0)