Skip to content

Commit 4daa8ef

Browse files
authored
fix(ci): add hacky workaround for node-gyp bug (#2849)
See the comments in the script itself. This is not ideal but at this point anything that gets CI up any running is good. :)
1 parent 4f64e3c commit 4daa8ef

File tree

6 files changed

+70
-5
lines changed

6 files changed

+70
-5
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env bash
2+
3+
# This is a workaround for a node-gyp bug that has not fully been investigated
4+
# due to problems reproducing it outside of CI environments (even though it
5+
# occurs both in evergreen and github actions).
6+
# Something seems to go wrong when node-gyp extracts the Node.js header tarball,
7+
# on Windows specifically (this is most likely because node-tar treats
8+
# the overwriting of existing files differently on Windows than on other OS --
9+
# for good reasons, but still).
10+
# The most likely cause of this issue is that node-gyp somehow extracts the
11+
# same headers tarball twice, in parallel, in the same location, with race
12+
# conditions in the tar extraction code leading to issues.
13+
# The extraction result ends up in %LOCALAPPDATA%\node-gyp\Cache.
14+
# Manually extracting the tarballs will solve this issue, so we're doing that
15+
# here.
16+
# For actually resolving the bug, we would probably need somebody with a local
17+
# reproduction. However, it seems likely that other people will also encounter
18+
# this issue, so there's also a good chance that this workaround will just
19+
# not be needed with a future node-gyp version.
20+
21+
if [ x"$NODE_JS_VERSION" = x"" ]; then
22+
if node -v; then
23+
export NODE_JS_VERSION=$(node -p 'process.version.slice(1)')
24+
else
25+
echo "Need NODE_JS_VERSION to be set or Node.js to be installed for node-gyp bug workaround script"
26+
exit 1
27+
fi
28+
fi
29+
30+
if [ x"$LOCALAPPDATA" = x"" ]; then
31+
echo "No LOCALAPPDATA set, ignoring node-gyp bug workaround script"
32+
exit
33+
fi
34+
35+
set -x
36+
CACHEDIR="$LOCALAPPDATA/node-gyp/Cache"
37+
rm -rvf "$CACHEDIR"
38+
mkdir -p "$CACHEDIR/$NODE_JS_VERSION"
39+
cd "$CACHEDIR/$NODE_JS_VERSION"
40+
curl -sSfLO "https://nodejs.org/download/release/v$NODE_JS_VERSION/node-v$NODE_JS_VERSION-headers.tar.gz"
41+
tar --strip-components=1 -xvzf "node-v$NODE_JS_VERSION-headers.tar.gz"
42+
for arch in x64 x86 arm64; do
43+
mkdir $arch
44+
pushd $arch
45+
curl -sSfLO "https://nodejs.org/download/release/v$NODE_JS_VERSION/win-$arch/node.lib" || echo "no $arch v$NODE_JS_VERSION .lib file"
46+
popd
47+
done
48+
49+
# Finally, store the right installVersion value for current node-gyp versions
50+
echo 9 > installVersion

.evergreen/preinstall.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ if [ -n "$IS_WINDOWS" ]; then
3535
./node.exe node_modules/npm2/bin/npm-cli.js i -g npm@$NPM_VERSION
3636
rm -rf node_modules/npm2/
3737
chmod +x npm.cmd npm
38+
39+
cd ..
40+
.evergreen/node-gyp-bug-workaround.sh
3841
else
3942
echo "Installing nodejs v${NODE_JS_VERSION} for ${PLATFORM}..."
4043
curl -fs \
@@ -53,4 +56,4 @@ else
5356

5457
./bin/node lib/node_modules/npm2/bin/npm-cli.js i -g npm@$NPM_VERSION
5558
rm -rf lib/node_modules/npm2/
56-
fi
59+
fi

.github/workflows/authors-and-third-party-notices.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ jobs:
2525
- name: Install [email protected]
2626
run: |
2727
npm install -g [email protected]
28-
npx --yes rimraf $LOCALAPPDATA/node-gyp/Cache || true
28+
29+
- name: Run node-gyp bug workaround script
30+
run: |
31+
bash .evergreen/node-gyp-bug-workaround.sh
2932
3033
- name: Install Dependencies
3134
run: |

.github/workflows/build.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ jobs:
5252
- name: Install [email protected]
5353
run: |
5454
npm install -g [email protected]
55-
npx --yes rimraf $LOCALAPPDATA/node-gyp/Cache || true
55+
56+
- name: Run node-gyp bug workaround script
57+
run: |
58+
bash .evergreen/node-gyp-bug-workaround.sh
5659
5760
- name: Install Dependencies
5861
run: |

.github/workflows/check-test.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ jobs:
4949
- name: Install [email protected]
5050
run: |
5151
npm install -g [email protected]
52-
npx --yes rimraf $LOCALAPPDATA/node-gyp/Cache || true
52+
53+
- name: Run node-gyp bug workaround script
54+
run: |
55+
bash .evergreen/node-gyp-bug-workaround.sh
5356
5457
- name: Install Dependencies
5558
run: |

.github/workflows/connectivity-tests.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ jobs:
7979
- name: Install [email protected]
8080
run: |
8181
npm install -g [email protected]
82-
npx --yes rimraf $LOCALAPPDATA/node-gyp/Cache || true
82+
83+
- name: Run node-gyp bug workaround script
84+
run: |
85+
bash .evergreen/node-gyp-bug-workaround.sh
8386
8487
- name: Install Dependencies
8588
run: |

0 commit comments

Comments
 (0)