pnpm / pnpm.io

pnpm's website
https://pnpm.io
MIT License
197 stars 460 forks source link

example continue integration config for Github Workflows #71

Open andykais opened 4 years ago

andykais commented 4 years ago

Github workflows are a fairly popular & free way to run continuous integration. This is what I have come up with for installing with pnpm on ci. I am curious if there is a better way. E.g. something that takes advantage of caching or an action to setup pnpm.

name: Node.js CI

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest

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

    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    # this line here feels a bit hacky
    - run: npm i -g pnpm
    - run: pnpm install
    - run: pnpm test
zkochan commented 4 years ago

check this: https://github.com/pnpm/action-setup

cc @KSXGitHub

andykais commented 4 years ago

Thank you! I still think its worthwhile to add this to the website. Especially since its actually part of the pnpm organization, but feel free to close this issue since I am unblocked

yume-chan commented 4 years ago

@zkochan I'm here also looking for instructions on how to use actions/cache with pnpm.

I'm a Windows and macOS user so I don't know where the pnpm store exists on Linux, and I didn't find it in documentations.

KSXGitHub commented 4 years ago

@yume-chan Add ~/.pnpm-store/v3 to your cache. Don't add node_modules.

yume-chan commented 4 years ago

@KSXGitHub Thank you! I know I can't cache node_modules, so I'm asking for pnpm store path.


Since pnpm/action-setup has a post run script to prune the store, actions/cache should run after pnpm/action-setup.

Turns out actions/cache also uses post run script to save file.

From my test, GitHub Actions run post run scripts in reverse order, so one should declare actions/cache in front of pnpm/action-setup.

Here is my workflow file:


jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [14.x]

    steps:
    - uses: actions/checkout@v2

    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}

    - name: Cache PNPM store
      uses: actions/cache@v2
      with:
        path: |
          ~/.pnpm-store/v3
        key: ${{ runner.os }}-pnpm

    - name: Setup PNPM
      uses: pnpm/action-setup@v1.2.0
      with:
        version: latest
        run_install: true

    - run: pnpm run build --if-present
    - run: pnpm test

Also note that because the store has been pruned, actions/cache can use a fixed cache key.

andykais commented 3 years ago

Also note that because the store has been pruned

what implies that the store has been pruned @yume-chan?

KSXGitHub commented 3 years ago

@andykais pnpm/action-setup has a post script that execute pnpm store prune.

anden-akkio commented 3 months ago

The subject matter here is sufficiently documented on the Continuous Integration documentation page. This issue can likely be closed.