diff --git a/.github/actions/install-latest-npm/action.yml b/.github/actions/install-latest-npm/action.yml index e1406f5ce5892..8339dbf03882d 100644 --- a/.github/actions/install-latest-npm/action.yml +++ b/.github/actions/install-latest-npm/action.yml @@ -29,14 +29,8 @@ runs: shell: bash env: NODE_VERSION: ${{ inputs.node }} + working-directory: ${{ runner.temp }} run: | - set -ex - - which npx - npx --version - npm --version - npm exec --yes -- semver -r "1" "1.0.0" - MATCH="" SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") @@ -46,7 +40,7 @@ runs: ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" - if npm exec --yes -- semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then MATCH=$SPEC echo "Found compatible version: npm@$MATCH" break diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml index 3c317449445cc..12af9f91ad7c0 100644 --- a/.github/workflows/audit.yml +++ b/.github/workflows/audit.yml @@ -29,7 +29,7 @@ jobs: with: node-version: 20.x check-latest: contains('20.x', '.x') - # cache: npm + cache: npm - name: Check Git Status run: node scripts/git-dirty.js - name: Reset Deps diff --git a/.github/workflows/ci-libnpmaccess.yml b/.github/workflows/ci-libnpmaccess.yml index e2e2b17b989c3..b846ec2f1231d 100644 --- a/.github/workflows/ci-libnpmaccess.yml +++ b/.github/workflows/ci-libnpmaccess.yml @@ -38,7 +38,7 @@ jobs: with: node-version: 20.x check-latest: contains('20.x', '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: @@ -91,7 +91,7 @@ jobs: with: node-version: ${{ matrix.node-version }} check-latest: contains(matrix.node-version, '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: diff --git a/.github/workflows/ci-libnpmdiff.yml b/.github/workflows/ci-libnpmdiff.yml index b1070b81b525f..4f997637ac4a0 100644 --- a/.github/workflows/ci-libnpmdiff.yml +++ b/.github/workflows/ci-libnpmdiff.yml @@ -38,7 +38,7 @@ jobs: with: node-version: 20.x check-latest: contains('20.x', '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: @@ -91,7 +91,7 @@ jobs: with: node-version: ${{ matrix.node-version }} check-latest: contains(matrix.node-version, '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: diff --git a/.github/workflows/ci-libnpmexec.yml b/.github/workflows/ci-libnpmexec.yml index 66a90777d8b79..f0209034e34ba 100644 --- a/.github/workflows/ci-libnpmexec.yml +++ b/.github/workflows/ci-libnpmexec.yml @@ -38,7 +38,7 @@ jobs: with: node-version: 20.x check-latest: contains('20.x', '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: @@ -91,7 +91,7 @@ jobs: with: node-version: ${{ matrix.node-version }} check-latest: contains(matrix.node-version, '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: diff --git a/.github/workflows/ci-libnpmfund.yml b/.github/workflows/ci-libnpmfund.yml index fa2be55199ba6..8c87f8d82e0a8 100644 --- a/.github/workflows/ci-libnpmfund.yml +++ b/.github/workflows/ci-libnpmfund.yml @@ -38,7 +38,7 @@ jobs: with: node-version: 20.x check-latest: contains('20.x', '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: @@ -91,7 +91,7 @@ jobs: with: node-version: ${{ matrix.node-version }} check-latest: contains(matrix.node-version, '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: diff --git a/.github/workflows/ci-libnpmhook.yml b/.github/workflows/ci-libnpmhook.yml index 2b1362158d85e..b83adcebf1504 100644 --- a/.github/workflows/ci-libnpmhook.yml +++ b/.github/workflows/ci-libnpmhook.yml @@ -38,7 +38,7 @@ jobs: with: node-version: 20.x check-latest: contains('20.x', '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: @@ -91,7 +91,7 @@ jobs: with: node-version: ${{ matrix.node-version }} check-latest: contains(matrix.node-version, '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: diff --git a/.github/workflows/ci-libnpmorg.yml b/.github/workflows/ci-libnpmorg.yml index 5f120b42534a0..9aa89720490a1 100644 --- a/.github/workflows/ci-libnpmorg.yml +++ b/.github/workflows/ci-libnpmorg.yml @@ -38,7 +38,7 @@ jobs: with: node-version: 20.x check-latest: contains('20.x', '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: @@ -91,7 +91,7 @@ jobs: with: node-version: ${{ matrix.node-version }} check-latest: contains(matrix.node-version, '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: diff --git a/.github/workflows/ci-libnpmpack.yml b/.github/workflows/ci-libnpmpack.yml index a990556cafe23..0e15706e4eac7 100644 --- a/.github/workflows/ci-libnpmpack.yml +++ b/.github/workflows/ci-libnpmpack.yml @@ -38,7 +38,7 @@ jobs: with: node-version: 20.x check-latest: contains('20.x', '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: @@ -91,7 +91,7 @@ jobs: with: node-version: ${{ matrix.node-version }} check-latest: contains(matrix.node-version, '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: diff --git a/.github/workflows/ci-libnpmpublish.yml b/.github/workflows/ci-libnpmpublish.yml index 4acc81dd3b34e..42950d13ae439 100644 --- a/.github/workflows/ci-libnpmpublish.yml +++ b/.github/workflows/ci-libnpmpublish.yml @@ -38,7 +38,7 @@ jobs: with: node-version: 20.x check-latest: contains('20.x', '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: @@ -91,7 +91,7 @@ jobs: with: node-version: ${{ matrix.node-version }} check-latest: contains(matrix.node-version, '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: diff --git a/.github/workflows/ci-libnpmsearch.yml b/.github/workflows/ci-libnpmsearch.yml index ec43f943ecd1d..ba3bf93d36be6 100644 --- a/.github/workflows/ci-libnpmsearch.yml +++ b/.github/workflows/ci-libnpmsearch.yml @@ -38,7 +38,7 @@ jobs: with: node-version: 20.x check-latest: contains('20.x', '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: @@ -91,7 +91,7 @@ jobs: with: node-version: ${{ matrix.node-version }} check-latest: contains(matrix.node-version, '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: diff --git a/.github/workflows/ci-libnpmteam.yml b/.github/workflows/ci-libnpmteam.yml index 9871d90e1ecf8..36953e1980d15 100644 --- a/.github/workflows/ci-libnpmteam.yml +++ b/.github/workflows/ci-libnpmteam.yml @@ -38,7 +38,7 @@ jobs: with: node-version: 20.x check-latest: contains('20.x', '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: @@ -91,7 +91,7 @@ jobs: with: node-version: ${{ matrix.node-version }} check-latest: contains(matrix.node-version, '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: diff --git a/.github/workflows/ci-libnpmversion.yml b/.github/workflows/ci-libnpmversion.yml index 62aedff2de394..126ba9f37f163 100644 --- a/.github/workflows/ci-libnpmversion.yml +++ b/.github/workflows/ci-libnpmversion.yml @@ -38,7 +38,7 @@ jobs: with: node-version: 20.x check-latest: contains('20.x', '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: @@ -91,7 +91,7 @@ jobs: with: node-version: ${{ matrix.node-version }} check-latest: contains(matrix.node-version, '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: diff --git a/.github/workflows/ci-npmcli-arborist.yml b/.github/workflows/ci-npmcli-arborist.yml index f78720ab562dc..7f6b97a01e39a 100644 --- a/.github/workflows/ci-npmcli-arborist.yml +++ b/.github/workflows/ci-npmcli-arborist.yml @@ -38,7 +38,7 @@ jobs: with: node-version: 20.x check-latest: contains('20.x', '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: @@ -91,7 +91,7 @@ jobs: with: node-version: ${{ matrix.node-version }} check-latest: contains(matrix.node-version, '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: diff --git a/.github/workflows/ci-npmcli-config.yml b/.github/workflows/ci-npmcli-config.yml index 0d75012ae8a4a..74c59343be046 100644 --- a/.github/workflows/ci-npmcli-config.yml +++ b/.github/workflows/ci-npmcli-config.yml @@ -38,7 +38,7 @@ jobs: with: node-version: 20.x check-latest: contains('20.x', '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: @@ -91,7 +91,7 @@ jobs: with: node-version: ${{ matrix.node-version }} check-latest: contains(matrix.node-version, '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: diff --git a/.github/workflows/ci-npmcli-docs.yml b/.github/workflows/ci-npmcli-docs.yml index fdbedcee20545..bbb9296e7d08b 100644 --- a/.github/workflows/ci-npmcli-docs.yml +++ b/.github/workflows/ci-npmcli-docs.yml @@ -38,7 +38,7 @@ jobs: with: node-version: 20.x check-latest: contains('20.x', '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: @@ -87,7 +87,7 @@ jobs: with: node-version: ${{ matrix.node-version }} check-latest: contains(matrix.node-version, '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: @@ -125,7 +125,7 @@ jobs: with: node-version: 20.x check-latest: contains('20.x', '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: diff --git a/.github/workflows/ci-npmcli-mock-globals.yml b/.github/workflows/ci-npmcli-mock-globals.yml index 2bc3cf6d40a4a..ba2dca9434369 100644 --- a/.github/workflows/ci-npmcli-mock-globals.yml +++ b/.github/workflows/ci-npmcli-mock-globals.yml @@ -38,7 +38,7 @@ jobs: with: node-version: 20.x check-latest: contains('20.x', '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: @@ -90,7 +90,7 @@ jobs: with: node-version: ${{ matrix.node-version }} check-latest: contains(matrix.node-version, '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: diff --git a/.github/workflows/ci-npmcli-mock-registry.yml b/.github/workflows/ci-npmcli-mock-registry.yml index 1315aeabfa837..51d51bca51adb 100644 --- a/.github/workflows/ci-npmcli-mock-registry.yml +++ b/.github/workflows/ci-npmcli-mock-registry.yml @@ -38,7 +38,7 @@ jobs: with: node-version: 20.x check-latest: contains('20.x', '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: @@ -90,7 +90,7 @@ jobs: with: node-version: ${{ matrix.node-version }} check-latest: contains(matrix.node-version, '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: diff --git a/.github/workflows/ci-npmcli-smoke-tests.yml b/.github/workflows/ci-npmcli-smoke-tests.yml index 22b7109f984cb..4d8456968e2a1 100644 --- a/.github/workflows/ci-npmcli-smoke-tests.yml +++ b/.github/workflows/ci-npmcli-smoke-tests.yml @@ -38,7 +38,7 @@ jobs: with: node-version: 20.x check-latest: contains('20.x', '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: @@ -90,7 +90,7 @@ jobs: with: node-version: ${{ matrix.node-version }} check-latest: contains(matrix.node-version, '.x') - # cache: npm + cache: npm - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: diff --git a/.github/workflows/ci-release.yml b/.github/workflows/ci-release.yml index c3783ed6ab195..5f5cdb43af77f 100644 --- a/.github/workflows/ci-release.yml +++ b/.github/workflows/ci-release.yml @@ -49,7 +49,7 @@ jobs: with: node-version: 20.x check-latest: contains('20.x', '.x') - # cache: npm + cache: npm - name: Check Git Status run: node scripts/git-dirty.js - name: Reset Deps @@ -114,7 +114,7 @@ jobs: with: node-version: ${{ matrix.node-version }} check-latest: contains(matrix.node-version, '.x') - # cache: npm + cache: npm - name: Check Git Status run: node scripts/git-dirty.js - name: Reset Deps @@ -182,7 +182,7 @@ jobs: with: node-version: ${{ matrix.node-version }} check-latest: contains(matrix.node-version, '.x') - # cache: npm + cache: npm - name: Check Git Status run: node scripts/git-dirty.js - name: Reset Deps diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6823abf7a9b72..e0725498263e3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,7 +46,7 @@ jobs: with: node-version: 20.x check-latest: contains('20.x', '.x') - # cache: npm + cache: npm - name: Check Git Status run: node scripts/git-dirty.js - name: Reset Deps @@ -94,7 +94,7 @@ jobs: with: node-version: ${{ matrix.node-version }} check-latest: contains(matrix.node-version, '.x') - # cache: npm + cache: npm - name: Check Git Status run: node scripts/git-dirty.js - name: Reset Deps @@ -126,7 +126,7 @@ jobs: with: node-version: 20.x check-latest: contains('20.x', '.x') - # cache: npm + cache: npm - name: Check Git Status run: node scripts/git-dirty.js - name: Reset Deps @@ -154,7 +154,7 @@ jobs: with: node-version: 20.x check-latest: contains('20.x', '.x') - # cache: npm + cache: npm - name: Check Git Status run: node scripts/git-dirty.js - name: Reset Deps @@ -183,7 +183,7 @@ jobs: with: node-version: 20.x check-latest: contains('20.x', '.x') - # cache: npm + cache: npm - name: Check Git Status run: node scripts/git-dirty.js - name: Reset Deps diff --git a/.github/workflows/create-node-pr.yml b/.github/workflows/create-node-pr.yml index f554adff4685a..96cb3c6fe5bad 100644 --- a/.github/workflows/create-node-pr.yml +++ b/.github/workflows/create-node-pr.yml @@ -39,7 +39,7 @@ jobs: with: node-version: 20.x check-latest: contains('20.x', '.x') - # cache: npm + cache: npm - name: Check Git Status run: node scripts/git-dirty.js - name: Reset Deps diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 6984583d80c19..100b68cec4e92 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -33,7 +33,7 @@ jobs: with: node-version: 20.x check-latest: contains('20.x', '.x') - # cache: npm + cache: npm - name: Check Git Status run: node scripts/git-dirty.js - name: Reset Deps diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4750c4309581a..e2c690f52643c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -42,7 +42,7 @@ jobs: with: node-version: 20.x check-latest: contains('20.x', '.x') - # cache: npm + cache: npm - name: Check Git Status run: node scripts/git-dirty.js - name: Reset Deps @@ -121,7 +121,7 @@ jobs: with: node-version: 20.x check-latest: contains('20.x', '.x') - # cache: npm + cache: npm - name: Check Git Status run: node scripts/git-dirty.js - name: Reset Deps diff --git a/scripts/template-oss/action-install-latest-npm-yml.hbs b/scripts/template-oss/action-install-latest-npm-yml.hbs new file mode 100644 index 0000000000000..ee4234879a464 --- /dev/null +++ b/scripts/template-oss/action-install-latest-npm-yml.hbs @@ -0,0 +1,56 @@ +name: 'Install Latest npm' +description: 'Install the latest version of npm compatible with the Node version' +inputs: + node: + description: 'Current Node version' + required: true +runs: + using: "composite" + steps: + # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows + - name: Update Windows npm + if: | + runner.os == 'Windows' && ( + startsWith(inputs.node, 'v10.') || + startsWith(inputs.node, 'v12.') || + startsWith(inputs.node, 'v14.') + ) + shell: cmd + run: | + curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz + tar xf npm-7.5.4.tgz + cd package + node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz + cd .. + rmdir /s /q package + - name: Install Latest npm + shell: bash + env: + NODE_VERSION: $\{{ inputs.node }} + working-directory: $\{{ runner.temp }} + run: | + MATCH="" + SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6") + + echo "node@$NODE_VERSION" + + for SPEC in ${SPECS[@]}; do + ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node') + echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)" + + if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then + MATCH=$SPEC + echo "Found compatible version: npm@$MATCH" + break + fi + done + + if [ -z $MATCH ]; then + echo "Could not find a compatible version of npm for node@$NODE_VERSION" + exit 1 + fi + + npm i --prefer-online --no-fund --no-audit -g npm@$MATCH + - name: npm Version + shell: bash + run: npm -v diff --git a/scripts/template-oss/index.js b/scripts/template-oss/index.js index d305b46ff3689..0f214723f558c 100644 --- a/scripts/template-oss/index.js +++ b/scripts/template-oss/index.js @@ -3,5 +3,5 @@ module.exports = { // Make workspaces use the global version of in workflows. // This is needed while workspaces and npm have different engines. // TODO: make npm and its workspaces always use the same engines and delete this. - "npm": "npm", + npm: 'npm', } diff --git a/scripts/template-oss/root.js b/scripts/template-oss/root.js index ff8a67b578103..0b6a2df0496f0 100644 --- a/scripts/template-oss/root.js +++ b/scripts/template-oss/root.js @@ -16,6 +16,7 @@ module.exports = { '.github/workflows/ci.yml': 'ci-yml.hbs', '.github/workflows/create-node-pr.yml': 'create-node-pr-yml.hbs', '.github/workflows/node-integration.yml': 'node-integration-yml.hbs', + '.github/actions/install-latest-npm/action.yml': 'action-install-latest-npm-yml.hbs', }, }, workspaceRepo: { @@ -26,6 +27,7 @@ module.exports = { '.github/workflows/post-dependabot.yml': false, '.github/workflows/release.yml': false, '.github/workflows/pull-request.yml': false, + '.github/actions/install-latest-npm/action.yml': 'action-install-latest-npm-yml.hbs', }, }, workspaceModule: {