From 12c276b6233cba8ec60bccfe58bc33c618e0de60 Mon Sep 17 00:00:00 2001 From: DeeDeeG Date: Sun, 22 Oct 2023 22:00:44 -0400 Subject: [PATCH] CI: Work around a weird bug in Yarn v1.x Install a global copy of node-gyp for Yarn to use. Works around a really weird bug. Details of the bug (and explanation of the workaround) below: --- Yarn install in Yarn v1.x has a really obscure bug that only happens for certain repos that "require node-gyp", and even then, only if the globally installed copy of npm is v9.7.2 or newer (or if there is no global copy of npm installed, which is quite rare.) In these unusual (and complex to describe) circumstances, this repo's postinstall script will not run, due to the bug in Yarn v1.x. Unfortunately for us, the versions of npm Yarn v1.x is incompatible with in this manner, npm v9.7.2 or newer, are bundled with NodeJS v18.18.0 and newer, as well as NodeJS v20.4.0 and newer. So, this is the new normal. Working around this is easy IRL. Yarn globally installs a copy of node-gyp it can use the first time, so this is a one-time issue. The only problem is it not handing off to its own package lifecycle script handler afterwrd, thus skipping the postinstall. So, to work around this problem IRL, simply run 'yarn install' a second time, or run 'yarn postinstall' once, in the ppm repo. ppm repo still needs a workaround (like this commit) to keep testing in CI with newer versions of Node. Either we install older npm in CI (not a sustainable fix, since this will become incompatible with newer versions of Node eventually), or give Yarn a copy of node-gyp it *can* use, (anything to ensure the postinstall script actually runs), which is what this commit does. (We could just manually run 'yarn postinstall' after the install, but this commit's approach is tidier, faster on machines where the workaround isn't needed, and clearer about what is going on.) (We may also want to consider switching to the newer versions of Yarn, which are actively maintained. Yarn v1.x doesn't accept bug fixes anymore, only "maybe" critical security fixes. Something like this could happen again, and we'd be on our own, again.) --- .github/workflows/CI.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 6eed6b3c..b9abc750 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -34,7 +34,11 @@ jobs: check-latest: true - name: Install dependencies - run: yarn install + run: | + # Yarn v1.x needs global node-gyp available if npm 9.7.2+ is the global npm version, + # or else postinstall scripts for this repo won't run. It's a long story. And it's a "won't fix" bug in Yarn v1.x. + yarn global add node-gyp@9.4.0 + yarn install - if: "!contains(matrix.os, 'windows')" name: Run tests 👩🏾‍💻