diff --git a/.evergreen/node-gyp-bug-workaround.sh b/.evergreen/node-gyp-bug-workaround.sh new file mode 100755 index 00000000000..128f3c646eb --- /dev/null +++ b/.evergreen/node-gyp-bug-workaround.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +# This is a workaround for a node-gyp bug that has not fully been investigated +# due to problems reproducing it outside of CI environments (even though it +# occurs both in evergreen and github actions). +# Something seems to go wrong when node-gyp extracts the Node.js header tarball, +# on Windows specifically (this is most likely because node-tar treats +# the overwriting of existing files differently on Windows than on other OS -- +# for good reasons, but still). +# The most likely cause of this issue is that node-gyp somehow extracts the +# same headers tarball twice, in parallel, in the same location, with race +# conditions in the tar extraction code leading to issues. +# The extraction result ends up in %LOCALAPPDATA%\node-gyp\Cache. +# Manually extracting the tarballs will solve this issue, so we're doing that +# here. +# For actually resolving the bug, we would probably need somebody with a local +# reproduction. However, it seems likely that other people will also encounter +# this issue, so there's also a good chance that this workaround will just +# not be needed with a future node-gyp version. + +if [ x"$NODE_JS_VERSION" = x"" ]; then + if node -v; then + export NODE_JS_VERSION=$(node -p 'process.version.slice(1)') + else + echo "Need NODE_JS_VERSION to be set or Node.js to be installed for node-gyp bug workaround script" + exit 1 + fi +fi + +if [ x"$LOCALAPPDATA" = x"" ]; then + echo "No LOCALAPPDATA set, ignoring node-gyp bug workaround script" + exit +fi + +set -x +CACHEDIR="$LOCALAPPDATA/node-gyp/Cache" +rm -rvf "$CACHEDIR" +mkdir -p "$CACHEDIR/$NODE_JS_VERSION" +cd "$CACHEDIR/$NODE_JS_VERSION" +curl -sSfLO "https://nodejs.org/download/release/v$NODE_JS_VERSION/node-v$NODE_JS_VERSION-headers.tar.gz" +tar --strip-components=1 -xvzf "node-v$NODE_JS_VERSION-headers.tar.gz" +for arch in x64 x86 arm64; do + mkdir $arch + pushd $arch + curl -sSfLO "https://nodejs.org/download/release/v$NODE_JS_VERSION/win-$arch/node.lib" || echo "no $arch v$NODE_JS_VERSION .lib file" + popd +done + +# Finally, store the right installVersion value for current node-gyp versions +echo 9 > installVersion diff --git a/.evergreen/preinstall.sh b/.evergreen/preinstall.sh index 3420b30ebf4..aceab808468 100755 --- a/.evergreen/preinstall.sh +++ b/.evergreen/preinstall.sh @@ -35,6 +35,9 @@ if [ -n "$IS_WINDOWS" ]; then ./node.exe node_modules/npm2/bin/npm-cli.js i -g npm@$NPM_VERSION rm -rf node_modules/npm2/ chmod +x npm.cmd npm + + cd .. + .evergreen/node-gyp-bug-workaround.sh else echo "Installing nodejs v${NODE_JS_VERSION} for ${PLATFORM}..." curl -fs \ @@ -53,4 +56,4 @@ else ./bin/node lib/node_modules/npm2/bin/npm-cli.js i -g npm@$NPM_VERSION rm -rf lib/node_modules/npm2/ -fi \ No newline at end of file +fi diff --git a/.github/workflows/authors-and-third-party-notices.yaml b/.github/workflows/authors-and-third-party-notices.yaml index a7af27cc833..92c552b7c50 100644 --- a/.github/workflows/authors-and-third-party-notices.yaml +++ b/.github/workflows/authors-and-third-party-notices.yaml @@ -25,7 +25,10 @@ jobs: - name: Install npm@8.3.1 run: | npm install -g npm@8.3.1 - npx --yes rimraf $LOCALAPPDATA/node-gyp/Cache || true + + - name: Run node-gyp bug workaround script + run: | + bash .evergreen/node-gyp-bug-workaround.sh - name: Install Dependencies run: | diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 2f633ca75cc..4083ab4b815 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -52,7 +52,10 @@ jobs: - name: Install npm@8.3.1 run: | npm install -g npm@8.3.1 - npx --yes rimraf $LOCALAPPDATA/node-gyp/Cache || true + + - name: Run node-gyp bug workaround script + run: | + bash .evergreen/node-gyp-bug-workaround.sh - name: Install Dependencies run: | diff --git a/.github/workflows/check-test.yaml b/.github/workflows/check-test.yaml index d41dc286a27..240b6bb85d0 100644 --- a/.github/workflows/check-test.yaml +++ b/.github/workflows/check-test.yaml @@ -49,7 +49,10 @@ jobs: - name: Install npm@8.3.1 run: | npm install -g npm@8.3.1 - npx --yes rimraf $LOCALAPPDATA/node-gyp/Cache || true + + - name: Run node-gyp bug workaround script + run: | + bash .evergreen/node-gyp-bug-workaround.sh - name: Install Dependencies run: | diff --git a/.github/workflows/connectivity-tests.yaml b/.github/workflows/connectivity-tests.yaml index 7ebea2f3ff0..1d9c3acc756 100644 --- a/.github/workflows/connectivity-tests.yaml +++ b/.github/workflows/connectivity-tests.yaml @@ -79,7 +79,10 @@ jobs: - name: Install npm@8.3.1 run: | npm install -g npm@8.3.1 - npx --yes rimraf $LOCALAPPDATA/node-gyp/Cache || true + + - name: Run node-gyp bug workaround script + run: | + bash .evergreen/node-gyp-bug-workaround.sh - name: Install Dependencies run: |