Github 动作脚本必须先安装 npm 才能安装包,而其他脚本则不需要

Github action script must install npm first to install packages yet others scripts don't require

这是下面的工作脚本。困扰我的部分是:

    - name: install npm
      run: npm i npm@latest
      working-directory: ./functions

我必须安装最新版本的 NPM,否则我会收到此错误:

npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!

忽略此错误不会安装我需要 运行 我的 Firebase 函数的 npm 包。我还有其他 github 不需要这种手持操作的动作脚本。我在这里做错了什么?

完整脚本:

name: Deploy to Firebase Functions

on:
  push:
    branches:
      - main
    # Optionally configure to run only for specific files. For example:
    paths:
    - "functions/**"

jobs:
  main:
    name: Deploy
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js 14
      uses: actions/setup-node@v2
      with:
        node-version: '14'
    - name: install npm
      run: npm i npm@latest
      working-directory: ./functions
    - name: install libraries
      run: npm i
      working-directory: ./functions
    - name: install firebase
      run: npm i firebase-tools -g
    - name: deploy
      run: firebase deploy --only functions --token ${{ secrets.FIREBASE_FUNCTIONS_TOKEN }}
      working-directory: ./functions

问题是,生成 package-lock.jsonnpm 版本与 Node.js V14 中包含的 npm 版本不兼容。

第一个选项可能是在 CI 中使用这样的 Node.js 版本,它已经包含与 lockfileVersion@2 兼容的 npm 版本。但是 lockfileVersion@2npm version 7, which is part of the latest Node.js 版本开始支持。由于未来的安全更新,使用 LTS 版本的 Node 是更好的选择,所以我不推荐这个选项。

作为第二个选项,packgage-lock.json 可以使用带有 npm V6 的 Node.js LTS 版本重新生成。这样 lockfileVersion 对于 Node 版本 14(现在是 LTS 版本)的 CI 是没问题的。我认为这是最好的选择。

作为第三个选项,一个想法是尝试 npm ci 命令,但我不确定这在这种情况下是否有效。