Skip to content

Commit 2d5b054

Browse files
authored
fix(ci): add node-gyp workaround script (#398)
1 parent e09ddd6 commit 2d5b054

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
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

.github/workflows/publish-release.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ jobs:
1717
- name: Install npm@7
1818
run: npm install -g npm@7
1919

20+
- name: Run node-gyp bug workaround script
21+
run: |
22+
bash .github/workflows/node-gyp-workaround.sh
23+
2024
- name: Install VSCode publishing dependencies
2125
run: npm install -g vsce
2226

.github/workflows/test-and-build.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ jobs:
4343
# Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0
4444
node-version: ^14.17.5
4545

46+
- name: Run node-gyp bug workaround script
47+
run: |
48+
bash .github/workflows/node-gyp-workaround.sh
49+
4650
- name: Install [email protected]
4751
run: npm install -g [email protected]
4852

0 commit comments

Comments
 (0)