PNPM Github actions flow
Asked Answered
E

2

9

I just moved my project from npm and lerna to pnpm but now when using GitHub actions I get the following error

"line 1: pnpm: command not found"

can someone suggest how the .yml file should be, I've posted the current version below?

name: Lint & Unit Test

on: [pull_request]

jobs:
  run-linters:
    name: Run linter and Unit tests
    runs-on: ubuntu-latest

    steps:
      - name: Check out Git repository
        uses: actions/checkout@v3

      - name: ACTIONS_ALLOW_UNSECURE_COMMANDS
        run: echo 'ACTIONS_ALLOW_UNSECURE_COMMANDS=true' >> $GITHUB_ENV

      - name: Set up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 16.18.1

      - name: Portal Install Node.js dependencies
        working-directory: ./portals
        run: |
          pnpm install

      - name: Portals Lint & tests
        working-directory: ./portals
        run: |
          cat .env.example > .env
          pnpm run build:tailwind
          pnpm run lint
          pnpm test

      - name: Services Install Node.js dependencies
        working-directory: ./services
        run: |
          pnpm install

      - name: Services Lint & tests
        working-directory: ./services
        run: |
          pnpm run lint
          pnpm test
Ejector answered 22/12, 2022 at 6:15 Comment(0)
V
13

pnpm is a fast and efficient package manager for Node.js, similar to npm and yarn. It is known for saving disk space and speeding up installations.

To set up pnpm in a GitHub Actions workflow, in the GitHub Actions workflow file (usually .github/workflows/<your-workflow>.yml), add a step to install pnpm: use the pnpm/action-setup action to do this. It automatically installs pnpm in your GitHub Actions runner environment.

on:
    push:
    pull_request:

jobs:
    install:
    runs-on: ubuntu-latest

    steps:
        - uses: actions/checkout@v3
        
        - name: Setup pnpm
        uses: pnpm/action-setup@v3 # docs https://pnpm.io/continuous-integration#github-actions
        with:
            version: 8  # Optional: specify a pnpm version

        # Further steps for your build/test process

Specifying a pnpm version is optional. If omitted, the latest version is installed. If you want to make sure consistency with your local development environment, specify the same pnpm version that you use locally.


Do you have to specify a version? Do I have to grub around in my yaml every time pnpm releases a version ?

The version is optional when there is a packageManager field in the package.json.

{
  "name": "your-project",
  "version": "1.0.0",
  "packageManager": "[email protected]",
  // other fields
}

Corepack is an experimental Node.js tool that provides a way to manage multiple package managers (like npm, yarn, and pnpm). It can automatically install the correct version of these package managers based on the configuration specified in a project's package.json.

Corepack will make sure the version of pnpm used in your GitHub Actions workflow matches the version specified in your package.json. That will align your local development environment with the CI/CD environment, maintaining consistency across different environments.

Virga answered 22/12, 2022 at 7:0 Comment(3)
Do you have to specify a version? Do I have to grub around in my yaml every time pnpm releases a version ?Tarantass
Presuming that the user is unfamiliar with pnpm, it is not clear what actions to take based off of the information provided in this answer. Please edit this answer to provide better instructions.Galilean
@JohnMiller Thank you for your feedback. I have rewritten the installation process in the first part of this answer. Let me know if this is clearer.Virga
S
1

i had this & took me quite few hours to figure it out, due to version changes, but here it is, maybe it will solve the issue for next few months

jobs:
 build:
  runs-on: ubuntu-latest
  env:
    RUNNER_TOOL_CACHE: /toolcache
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
  with:
    node-version: 20
- uses: pnpm/action-setup@v3
  with:
    version: 8
    run_install: false
    standalone: true
    dest: ~/setup-pnpm

- name: Build
  run: |
    # Add your build commands here
    pnpm install && pnpm build
    zip -r dist.zip dist
`

dest: ~/setup-pnpm

note that this line abolve was basically the one that solved it finally for me, but you may have to check other issues like this one here. https://github.com/pnpm/action-setup/issues/77#issuecomment-1487408974

also in package.json you may need to add this

"packageManager": "[email protected]",

Good luck ! thanks to @thantos for posting the comment on github

Speechmaking answered 22/2 at 23:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.