Search code examples
github-actionsmicrosoft-teamsteams-toolkit

Teams-cli using Github actions fails to find package.json


Using the below script to publish a Microsoft teams app:

steps:
  # Setup environment.
  - uses: actions/setup-node@v2
    with:
      node-version: '14'
  - run: npm install

  - name: Checkout the code
    uses: actions/checkout@v2

  - uses: OfficeDev/teamsfx-cli-action@v1
    with:
      commands: validate

  # Publish the Teams App.
  - uses: OfficeDev/teamsfx-cli-action@v1
    with:
      commands: publish

I get the following find package error for both the validate and publish actions:

UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open '/home/runner/work/ms-teams-tabs-app/ms-teams-tabs-app/node_modules/teamsfx-cli/node_modules/undefined/package.json'
    at Object.openSync (fs.js:497:3)
    at Object.readFileSync (fs.js:393:35)
    at getVersionString (/home/runner/work/ms-teams-tabs-app/ms-teams-tabs-app/node_modules/teamsfx-cli/lib/cli.js:61:28)
    at /home/runner/work/ms-teams-tabs-app/ms-teams-tabs-app/node_modules/teamsfx-cli/lib/cli.js:87:18
    at Generator.next (<anonymous>)
    at /home/runner/work/ms-teams-tabs-app/ms-teams-tabs-app/node_modules/teamsfx-cli/lib/cli.js:30:71
    at new Promise (<anonymous>)
    at __awaiter (/home/runner/work/ms-teams-tabs-app/ms-teams-tabs-app/node_modules/teamsfx-cli/lib/cli.js:26:12)
    at /home/runner/work/ms-teams-tabs-app/ms-teams-tabs-app/node_modules/teamsfx-cli/lib/cli.js:68:8
    at Object.<anonymous> (/home/runner/work/ms-teams-tabs-app/ms-teams-tabs-app/node_modules/teamsfx-cli/lib/cli.js:89:4)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:1721) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:1721) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Running the commands locally through the console or using the Visual Code Teams toolkit both run successfully without issue, I can't see what I might be missing here.


Solution

  • Updated script to the following to correctly install the required packages:

    steps:
      # Setup environment.
      - uses: actions/setup-node@v2
        with:
          node-version: '14'
      - uses: pnpm/action-setup@v2.0.1
        with:
            version: 6.12.1
      - name: Checkout
        uses: actions/checkout@v2.3.1
        with:
          persist-credentials: false
      - name: Install and Build 🔧
        run: | # Install npm packages
          pnpm install
    
      - uses: OfficeDev/teamsfx-cli-action@v1
        with:
          commands: validate
    
      # Publish the Teams App.
      - uses: OfficeDev/teamsfx-cli-action@v1
        with:
          commands: publish