pnpm / action-setup

Install pnpm package manager
https://github.com/marketplace/actions/setup-pnpm
MIT License
899 stars 87 forks source link

Using pnpm/action-setup in a subdirectory of a git repoository is giving: ENOENT: no such file or directory #81

Closed andresgutgon closed 1 year ago

andresgutgon commented 1 year ago

WHAT?

Hi, I'm trying to use this GitHub Action in a project that looks like this:

myproject
  |-- .github/workflows/client-ci.yml
  |-- backend
  |-- client

I want to use pnpm inside myproject/client/package.json folder but this action:

 - name: Setup pnpm
        uses: pnpm/action-setup@v2.2.4

It's giving this error:

Running self-installer...
  [Error: ENOENT: no such file or directory, open '/home/runner/work/myproject/myproject/package.json'] {
    errno: -2,
    code: 'ENOENT',
    syscall: 'open',
    path: '/home/runner/work/myproject/myproject/package.json'
  }

Specify destination

I also tried setting destination. But I get the same error.

 - name: Setup pnpm
        uses: pnpm/action-setup@v2.2.4
        with:
          dest: ~+/client

I would appreciate any help. Thanks!

andresgutgon commented 1 year ago

Ok I found what was my issue.

This line is looking always in the root of the repo: https://github.com/pnpm/action-setup/blob/11dd14d0c0916e1ad9ff1938d8d4ea509bebfe10/src/install-pnpm/run.ts#L47

The solution was to use version param:

- name: Setup pnpm
  uses: pnpm/action-setup@v2.2.4
  with:
    version: 7.15.0

So this way this action doesn't try to find a package.json in root of the repo.

I hope this can help someone : )

robotkutya commented 1 year ago

Is there a fix without pinning the version to 7.x.x?

andresgutgon commented 1 year ago

Mine is not a fix pinning to any specific version. In version you can put whatever:

- name: Setup pnpm
  uses: pnpm/action-setup@v2.2.4
  with:
    version: PUT_YOUR_VERSION

Anyway I was having this problem because I had defined packageManager in my root package.json. Another solution would be not define packageManager attribute in your package.json so you don't need the with config in the action.

robotkutya commented 1 year ago

Doesn't this mean that it pins the version...?! https://github.com/pnpm/action-setup#version

Sorry if I'm being dumb.

andresgutgon commented 1 year ago

I guess if you put a version there that's the version used by the github action. So yes, that would be pinned.

But I think anyway is a good practice to pin your project to an specific pnpm version. Either by setting packageManager in your root package.json or by setting it in the github action.

Anyway what's your problem? Mine was because I had the js monorepo inside a folder of my git repo.

robotkutya commented 1 year ago

Okay, gotcha, thanks!

I'm working with a similar setup, do you just add working-directory: foo whenever you run a command or is there a way to take care of that generally?

andresgutgon commented 1 year ago

Yes, in your job:

jobs:
  your_job:
    name: Your job name
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: client

In my case my javascript is in code/client folder

robotkutya commented 1 year ago

For future reference, you can pin any version and it will work.

Originally I thought you specifically had to pin verison 7.15.0, but any version will do.

@andresgutgon thanks for the tips!

nicodes commented 1 year ago

@andresgutgon @robotkutya I'm facing a similar issue, I've read through the docs and I saw run_install.cwd should configure this but I haven't gotten it to work. Does anyone have a working example that we could add to the docs?

Here's a code snippet of what I would expect work based on the docs:

- uses: pnpm/action-setup@v2
        with:
          run_install: |
            - cwd: client
nicodes commented 1 year ago

I found a solution by adding version: 7

- uses: pnpm/action-setup@v2
        with:
          version: 7
          run_install: |
            - cwd: client

However I do think this should be changed in a future version to use the more common syntax working-directory from the defaults like @andresgutgon showed above