diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3726c45e..77186559 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: fail-fast: false matrix: node-version: ['lts/-1', 'lts/*', 'latest'] - os: [macos-latest, ubuntu-latest, ubuntu-24.04-arm, windows-latest] + os: [macos-latest, ubuntu-latest, ubuntu-24.04-arm, windows-latest, windows-2022] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v7 @@ -21,8 +21,17 @@ jobs: with: node-version: ${{ matrix.node-version }} - run: npm ci + - name: Upgrade node-gyp if it cannot detect the installed Visual Studio + if: runner.os == 'Windows' + run: npm run upgrade-node-gyp - run: npm audit || true - run: npm run lint # - run: npm run update-crosswalk # To support newer versions of Node.js - run: npm run build --if-present + - name: DEBUG which node-gyp the tests will use + if: runner.os == 'Windows' + run: | + node -p "'npm_config_node_gyp=' + process.env.npm_config_node_gyp" + node -p "require('fs').existsSync(process.env.npm_config_node_gyp || '')" + node -p "require('./lib/util/compile.js').which_node_gyp()" - run: npm test diff --git a/.github/workflows/s3-bucket.yml b/.github/workflows/s3-bucket.yml index d77cba5f..8948d938 100644 --- a/.github/workflows/s3-bucket.yml +++ b/.github/workflows/s3-bucket.yml @@ -12,27 +12,31 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, macos-latest, windows-latest] + os: [ubuntu-latest, macos-latest, windows-latest, windows-2022] node-version: ['lts/-1', 'lts/*', 'latest'] env: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} S3_BUCKET: ${{ secrets.S3_BUCKET }} - name: Test S3 Bucket - Node ${{ matrix.node }} on ${{ matrix.os }} + name: Test S3 Bucket - Node ${{ matrix.node-version }} on ${{ matrix.os }} steps: - name: Checkout ${{ github.ref }} uses: actions/checkout@v7 - - name: Setup node ${{ matrix.node }} + - name: Setup node ${{ matrix.node-version }} uses: actions/setup-node@v7 with: - node-version: ${{ matrix.node }} + node-version: ${{ matrix.node-version }} - name: NPM Install run: npm install + - name: Upgrade node-gyp if it cannot detect the installed Visual Studio + if: runner.os == 'Windows' + run: npm run upgrade-node-gyp + - name: Show Environment Info run: | printenv diff --git a/lib/util/compile.js b/lib/util/compile.js index c60455aa..fa3c0bbf 100644 --- a/lib/util/compile.js +++ b/lib/util/compile.js @@ -60,6 +60,8 @@ function which_node_gyp() { } } +module.exports.which_node_gyp = which_node_gyp; + module.exports.run_gyp = function(args, opts, callback) { let shell_cmd = ''; const cmd_args = []; diff --git a/package.json b/package.json index 73f3cdf6..d1981828 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "lint": "eslint bin/node-pre-gyp lib/*js lib/util/*js test/*js scripts/*js", "fix": "npm run lint -- --fix", "update-crosswalk": "node scripts/abi_crosswalk.js", + "upgrade-node-gyp": "node scripts/upgrade-node-gyp.js", "test": "tape test/*test.js", "test:s3": "tape test/s3.test.js", "bucket": "node scripts/set-bucket.js" diff --git a/scripts/upgrade-node-gyp.js b/scripts/upgrade-node-gyp.js new file mode 100644 index 00000000..2b5eb02a --- /dev/null +++ b/scripts/upgrade-node-gyp.js @@ -0,0 +1,41 @@ +'use strict'; + +// script upgrades node-gyp when the bundled copy is too old to detect the installed Visual Studio. node-gyp +// recognises Visual Studio 2026 (major version 18) only from v12 onwards, so older copies fail to configure on runner +// images shipping it. + +const cp = require('child_process'); +const fs = require('fs'); +const path = require('path'); +const compile = require('../lib/util/compile.js'); + +const MINIMUM_MAJOR = 12; +const INSTALL_VERSION = '13.0.2'; + +const node_gyp_bin = compile.which_node_gyp(); +if (!node_gyp_bin) { + console.log('could not locate node-gyp; leaving it alone'); + process.exit(0); +} + +const { version } = require(path.join(node_gyp_bin, '../../package.json')); +console.log(`found node-gyp@${version} at ${node_gyp_bin}`); + +if (parseInt(version, 10) >= MINIMUM_MAJOR) { + console.log(`node-gyp@${version} detects Visual Studio 2026; nothing to do`); + process.exit(0); +} + +console.log(`node-gyp@${version} predates v${MINIMUM_MAJOR}; installing node-gyp@${INSTALL_VERSION}`); +cp.execFileSync('npm', ['install', '--no-save', `node-gyp@${INSTALL_VERSION}`], { stdio: 'inherit', shell: true }); + +const upgraded = path.join(__dirname, '../node_modules/node-gyp/bin/node-gyp.js'); +if (!fs.existsSync(upgraded)) { + throw new Error(`expected the upgraded node-gyp at ${upgraded}, but it is not there`); +} +console.log(`using node-gyp at ${upgraded}`); + +// export for later GitHub workflow steps, which npm would otherwise point back at its own bundled copy +if (process.env.GITHUB_ENV) { + fs.appendFileSync(process.env.GITHUB_ENV, `npm_config_node_gyp=${upgraded}\n`); +} diff --git a/test/run.util.js b/test/run.util.js index 55e50b13..fc03affa 100644 --- a/test/run.util.js +++ b/test/run.util.js @@ -58,11 +58,6 @@ function run(prog, command, args, app, opts, cb) { opts.cwd = path.join(__dirname, app.name); } - // Test building with msvs 2022 - if (process.platform === 'win32') { - final_cmd += ' --msvs_version=2022 '; - } - // finish appending all arguments final_cmd += ' ' + app.args; final_cmd += ' ' + args;