Reputation: 3948
Lerna does not correctly detect packages change during running workflow of Github actions.
If I make none packages related changes, commit and runlerna updated
locally. it tells me No changed packages found which is correct and expected.
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"
}
}
}
Upvotes: 10
Views: 12504
Reputation: 111
Documenting my findings about this issue.
@eded found the correct issue, which was that by default, actions/checkout fetches only 1 commit for performance reasons. Therefore, lerna does not have access to the version tags (which are often several commits back) and assumes that all packages have changed by default :
lerna info Assuming all packages changed
You therefore need to force actions/checkout to get all commits and tags, by using the input fetch-depth: '0'
This is all you need to do, as actions/checkout was corrected to fetch all commits and tags since v2 after this issue surfaced.
This might be a performance issue as your monorepo grows.
Upvotes: 1
Reputation: 1
Possibly you use git tag xxx
without -m
parameter. If you execute git tag
yourself instead of using lerna version
or lerna publish
, you should add -m
parameter to make the tag annotated.
Ref: https://github.com/lerna/lerna/issues/1357#issuecomment-438162152
Upvotes: 0
Reputation: 241
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
Upvotes: 3
Reputation: 419
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
Upvotes: 6
Reputation: 3948
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.
Upvotes: 23