Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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/[email protected]
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"
    }
  }
}
like image 830
eded Avatar asked Feb 12 '20 03:02

eded


3 Answers

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

You have to combine both

  • fetch-depth: 0
  • run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*

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

like image 106
eded Avatar answered Dec 03 '22 05:12

eded


Wow - cannot believe that I've finally found a fix to the same issue - huge thanks!

I see this as a big issue with github actions (specifically @actions/checkout), and thus I've informed them here: https://github.com/actions/checkout/issues/217

I've also informed the lerna folks here: https://github.com/lerna/lerna/issues/2542

and semantic-release people here: https://github.com/semantic-release/semantic-release/issues/1526

Thanks again! You've helped me save a lot of time & fix an annoying issue, and I hope I'll help others with this too. Cheers

like image 45
Kipras Melnikovas Avatar answered Dec 03 '22 06:12

Kipras Melnikovas


There is also the option include-merged-tags

So this should also solve the problem:

lerna updated --include-merged-tags

or for publishing:

lerna publish --include-merged-tags
like image 23
CimChd Avatar answered Dec 03 '22 06:12

CimChd