【问题标题】:How to specify node's path in Github action?如何在 Github 操作中指定节点的路径?
【发布时间】:2021-08-31 21:23:02
【问题描述】:

我正在尝试使用 Github 的 node.js 工作流程在我的存储库上进行自动化测试。但是,我遇到了困难,因为节点设置在子目录而不是存储库的根目录中。我一直在寻找一种方法来指定运行 npm 命令的目录,但没有找到任何答案。

这是工作流代码:

# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [12.x, 14.x, 16.x]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    steps:
    - uses: actions/checkout@v2
      with: 
        path: backend_app
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v2
      with:
        node-version: ${{ matrix.node-version }}
    - run: cd backend_app
    - run: npm ci
    - run: npm run build --if-present
    - run: npm test

这是动作运行产生的错误:

    Run npm ci
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /home/runner/work/directory_name/directory_name/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/home/runner/work/directory_name/directory_name/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2021-06-16T03_36_41_777Z-debug.log
Error: Process completed with exit code 254.

【问题讨论】:

  • 请查看下面的答案。

标签: npm github-actions


【解决方案1】:

看起来这个问题已经回答了。

How do I run my CI steps in a specific folder in github action

【讨论】:

    【解决方案2】:

    请指定“工作目录”。请参考我的 .yml 文件。

    1. 工作目录:./Projects/books-store-mean/webapi

    工作流程文件供参考:https://github.com/vishipayyallore/mini-projects-2021/actions/workflows/booksstore-nodeexpressmongo.yml

    # This workflow will do a clean install of node dependencies, build the source code, and run tests across different versions of the node
    # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
    
    name: Node.js CI
    
    on:
      push:
        branches: [ master ]
      pull_request:
        branches: [ master ]
    
    jobs:
      build:
    
        runs-on: ubuntu-latest
    
        strategy:
          matrix:
            node-version: [14.x]
            # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
    
        steps:
        - uses: actions/checkout@v2
        - name: Use Node.js ${{ matrix.node-version }}
          uses: actions/setup-node@v2
          with:
            node-version: ${{ matrix.node-version }}
        - run: npm ci
          working-directory: ./Projects/books-store-mean/webapi
        - run: npm run build --if-present
          working-directory: ./Projects/books-store-mean/webapi
        - run: npm test
          working-directory: ./Projects/books-store-mean/webapi
    

    【讨论】:

    • 如果需要为setup-node@v2步骤指定锁文件的路径,可以在with下多加一行,如下:cache-dependency-path: ./some/path/package-lock.json
    • @derekbaker783 令人惊讶的是要找到这个答案是多么困难。谢谢!
    猜你喜欢
    • 2021-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多