• Home
  • Today I learned
  • When publishing npm packages with lerna through GH actions, we need more params to checkout

When publishing npm packages with lerna through GH actions, we need more params to checkout

This article was published on Mar 28, 2021, and takes approximately a minute to read.

Publishing things via pipelines are not a trivial task.

I've found myself struggling to publish my packages in a lerna repo via Github Actions until I find this FYI post.

In a nutshell, because we always use actions/checkout and by default it brings the latest commit, e need to pass a param which says "bring ALL commits".

This is important because lerna (when combined with conventional commits), uses our commit messages to determine what needs to be published or not and also generate release notes, etc. In other words, let's say you have squashed 4 commits and the latest isn't about your packages. Because of the actions/checkout behaviour, lerna will only get that and understand there's nothing to be published.

To fix that we need to add a fetch-depth: "0" param to the checkout step:

steps:
  - uses: actions/checkout@v2
      with:
        # pulls all commits (needed for lerna / semantic release to correctly version)
        fetch-depth: "0"

  # pulls all tags (needed for lerna / semantic release to correctly version)
  - run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*

Resources