Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify node's path in Github action?

I'm trying to use Github's node.js workflow for automating test on my repository. However, I'm having difficulties because node is set up in a child directory instead of the root of my repository. I have been looking for a way to specify the directory in which to run the npm commands but have not found any answer.

Here is the workflow code:

# 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

Here is the error generated by the action run :

    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.
like image 894
Vico Avatar asked Jun 16 '21 04:06

Vico


People also ask

How do I specify node versions in GitHub Actions?

The easiest way to specify a Node. js version is by using the setup-node action provided by GitHub. For more information see, setup-node . The setup-node action takes a Node.

What directory do GitHub Actions run in?

GitHub Actions uses YAML syntax to define the workflow. Each workflow is stored as a separate YAML file in your code repository, in a directory named . github/workflows .

How do I run jobs sequentially in GitHub Actions?

To run jobs sequentially, you can define dependencies on other jobs using the jobs. <job_id>. needs keyword. Each job runs in a runner environment specified by runs-on .


1 Answers

Please specify the "Working-Directory". Please refer to my .yml file.

  1. working-directory: ./Projects/books-store-mean/webapi

Work flow file for reference: 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
like image 133
Viswanatha Swamy Avatar answered Oct 08 '22 04:10

Viswanatha Swamy