githubnpmgithub-actionslernamonorepo

Lerna always lists all packages ready to publish when running workflow of Github actions


Lerna does not correctly detect packages change during running workflow of Github actions.

  1. If I make none packages related changes, commit and runlerna updatedlocally. it tells me No changed packages found which is correct and expected.

  2. If I make package related changes, commit and run lerna updated locally. it tells me found x packages ready to publish which is also correct and expected.

However, if I push the commit based on 1 or 2. the step which I run lerna updated in my github actions workflow always tells/lists me all the package are available to publish which is wrong.

I am wondering why and how to fix it ???

here is what I see locally if I made none packages related changes

lerna notice cli v3.20.2
lerna info versioning independent
lerna info Looking for changed packages since @xxx/bar@2.3.4
lerna info No changed packages found

here is what I see on workflow log after pusing the none packages related changes to Github

> lerna updated -l

lerna notice cli v3.20.2
lerna info versioning independent
lerna info Assuming all packages changed
@xxx/bar  v2.3.4 packages/Bar
@xxx/foo  v1.4.4 packages/Foo
@xxx/hulk v1.0.4 packages/Hulk
lerna success found 3 packages ready to publish

here is my workflows

name: Publish
on:
  push:
    branches:
      - master
jobs:
  unit-test:
    name: UnitTest
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: 12
      - run: npm ci
      - run: npm test

  publish:
    name: Publish NPM Packages
    needs: unit-test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: 12
          registry-url: https://registry.npmjs.org/
      - run: npm ci
      - run: git config --global user.email "xxx"
      - run: git config --global user.name "xxx"
      - run: npm run updated
        env:
          NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}

here is my package.json

{
  "name": "root",
  "devDependencies": {
    "jest": "^25.1.0",
    "lerna": "^3.20.2"
  },
  "scripts": {
    "updated": "lerna updated -l",
    "test": "jest"
  }
}

here is my lerna setting

{
  "packages": [
    "packages/*"
  ],
  "version": "independent",
  "command": {
    "publish": {
      "allowBranch": "master",
      "conventionalCommits": true,
      "message": "chore(release): updated release notes and package versions"
    }
  }
}

Solution

  • After hours of debugging. I found the answer myself and thanks to @peterevans for the tip

    You have to combine both

    so that all git history and tag are exposed to lerna.