1

I tried to create a github action that operates on ./example folder. Code that is inside /.example folder was built by using create-react-app.

Workflow code:

name: CI

on:
  push:
    branches: [ origin ]
  pull_request:
    branches: [ origin ]

jobs:
  build_test:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [10.x, 15.x]

    steps:
      - uses: actions/checkout@v2
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v2
        with:
          node-version: ${{ matrix.node-version }}
      - name: npm install, build, and test example
        working-directory: example
        run: |
          npm install
          npm run build --if-present

But it causes an error: enter image description here

The structure of my project (inside ./example there is package.json):

enter image description here

Kamil
  • 49
  • 1
  • 5
  • Could you share your project (if it is public) to test the workflow on a fork? – GuiFalourd Jul 27 '21 at 20:29
  • You might be able to find an answer here: [running-actions-in-another-directory](https://stackoverflow.com/questions/58139175/running-actions-in-another-directory) – Bunny Dec 31 '22 at 08:32

1 Answers1

-1

Your workflow yaml file should look like below.

name: CI

on:
  push:
    branches: [ origin ]
  pull_request:
    branches: [ origin ]

jobs:
  build_test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [10.x, 15.x]
    steps:
      - uses: actions/checkout@v2
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v2
        with:
          node-version: ${{ matrix.node-version }}
      - name: npm install, build, and test example
        working-directory: ./example
        run: |
          npm install
          npm run build --if-present
Sam-Sundar
  • 511
  • 1
  • 4
  • 12
  • Unfortunately, it doesn't work: `npm ERR! Could not install from "../node_modules/@types/node" as it does not contain a package.json file.` – Kamil Jul 27 '21 at 18:44
  • Are you installing any local dependancy ? Because I feel this is not because NPM didn't find package.json. please find below link for reference https://github.com/npm/npm/issues/18266. If NPM didn't find your `package.json` it would have thrown below error, `no such file or directory, open '/example/package.json'` – Sam-Sundar Jul 28 '21 at 03:21
  • working-directory tag supported in v2 version? – Nikhil Wankhade Oct 23 '21 at 09:29