You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
as far as I understand it is impossible to publish to npm as the latest version using a CI script.
I'm currently using this script, which is run on the server:
this takes the version of package.json. But npm automatically sets it default to a previous version, even when the version is incremented by 0.0.1
npm install 'package' does not return the one that was succesfully pushed, even though it exists in npm when asking for that specific version.
I'm sorry if this is not the correct place to discuss this issue, I've never opened an issue on github before, this is my second month employed in IT :)
Version can be:
patch | minor | major | prepatch | preminor | premajor | prerelease | 1.2.3
It looks like the grep you're using to produce your --repo-version is actually returning the current version? It may be that you need to increment the patch level on that to get what you're looking for. Also the -c (--canary) option you're including prohibits Lerna from tagging your newly published version as "latest", so npm won't provide it by default.
Would be nice with a short paragraph/recipe on a typical setup for CI/CD. I guess it would just be publish without pushing to npm, triggering the CI from the git repo? or is there a smarter way?
Hi, we would like to publish to npm in our ci. We need to do it non interactive.
Usually, we just bump the next version of package.json on dev branch when we tag from master. This way we just need to keep or update the version in package.json before merging to master to tag a specific version.
@evocateur do you have another purpostion on how we should adapt our publishing process to integrate Lerna in our stack? Why won't this be implemented that way?
If you're comfortable with allowing CI to make commits and push tags, I would restrict non-canary publishing to master and adopt conventional commits (available via the --conventional-commits lerna flag).
The process for automated publishing in CI is not ideal right now, so I'd recommend against it in most cases. I hope to improve this in the future.
@evocateur painful in what way ?
I feel like the simple script would just iterate for packages/**/package.json and run npm version patch then git tag. Do you see any other complication ?
Well, in that case, I guess why bother with lerna, then? There's lots of logic related to choosing "what" to publish. lerna publish --canary would get you most of the way there, but with no record of the changes, and a version number that is really awkward.
Well, in that case, I guess why bother with lerna, then?
I've been playing with lerna and it is an amazing tool, that is I think a good reason to use it.
To use it in our stack, we need to be able to release and tag during our CI process and that's a requirement.
but with no record of the changes, and a version number that is really awkward.
I don't get that point. We are doing all our change in dev branch, the CHANGELOG.md is updated manually and controlled before merging to our master.
The person who is opening the merge request to master is in charge of setting the proper version in package.json. The person who validate the commit is in charge of confirming the version.
With this in place, we have been able to manage many projects and dependencies without worrying about the release part. We'd like to keep it that way.
Now we have tried lerna, we like to be able to host multiple packages on a single git repository which will increase even more our productivity.
Do you think another option to fit that need could be requested?
If lerna can let us play that way, I'll be happy to help (writing the feature request) and programming (if assisted).
hi guys, I did manage to set up Lerna monorepo on Gitlab's CI to publish to npm. When git push is done, GitLab CI triggers and lerna bootstrap + lerna version builds the latest sources (using Conventional Commits) including changelogs and bumped package.jsons. From there on, I don't use Lerna any more for the rest of publishing. This allows me to granularly control tag pushing, committing and pushing to git source.
Main idea is, npm won't publish packages which don't have a new, bumped package.json version. It's not very efficient to manually npm publish each of the packages but it's safe and it works.
CI logs in as me into git and npm (using login details as secrets put in GitLab preferences), final bits are commited and published to npm, then git pushed to git origin. After it's done, I git pull the latest from CI onto my laptop.
Here's the GitLab CI yml:
## C O D S E N#deploy:
except:
- tagsimage: node:lateststage: deployscript:
- git config --global credential.helper store
- git remote set-url origin https://gitlab-ci-token:[email protected]/codsen/codsen.git
- git config --global user.email "$GITLAB_USER_EMAIL"
- git config --global user.name "$YOUR_NAME_SURNAME"
- npm set unsafe-perm true -g
- npm set //registry.npmjs.org/:_authToken $NPM_TOKEN -g
- npm set username $NPM_USERNAME -g
- npm set email $NPM_EMAIL -g
- echo "git user:"
- git config user.name
- echo "npm user:"
- npm whoami
- echo '█████████████████████████████ 1 █████████████████████████████'
- git status
- git checkout master
- echo '█████████████████████████████ 2 █████████████████████████████'
- git status
- npm run bootstrap
- echo '█████████████████████████████ 3 █████████████████████████████'
- git status
- npm run all:test:only
- echo '█████████████████████████████ 4 █████████████████████████████'
- git status
- npm run readme:generate
- echo '█████████████████████████████ 5 █████████████████████████████'
- git status
- git add packages
- "git commit -m '[skip ci] chore: Automated build tasks' --no-verify"
- npx lerna changed
- npm run pub:vers
- echo '█████████████████████████████ 6 █████████████████████████████'
- git status
- git add packages
- echo '█████████████████████████████ 7 █████████████████████████████'
- git status
- "git commit -m '[skip ci] chore: Automated build tasks' --no-verify"
- echo '█████████████████████████████ 8 █████████████████████████████'
- git status
- npm run republish
- echo '█████████████████████████████ 9 █████████████████████████████'
- git status
- git push origin master
- echo '█████████████████████████████ 10 █████████████████████████████ - done'
$GITLAB_USER_EMAIL and all other variables that start with dollar are secrets you set in GitLab repo preferences.
npm script pub:vers looks like this:
"pub:vers": "lerna version --conventional-commits --no-commit-hooks --yes && lernacleanchangelog '**'",
lernacleanchangelog is lerna-clean-changelogs-cli call. As you know, Conventional Commits puts "Note: Version bump only for package ranges-apply" if there were no feat/fix commits and CLI removes those changelog entries.
make republish is a shell script which loops through all package directories in packages/ and does npm publish.
Publishing using lerna in CI has been well supported for some time now and so I am going to close this older issue. If you have any requests that could enhance your usage of Lerna 6, then please do let us know by opening a new discussion (for a feature) or issue (for a bug report) with as much context as possible.
You can also check out our published roadmap for Lerna v7 here: #3410
Activity
gigabo commentedon Dec 22, 2016
Yeah, it's not really straightforward to automatically publish a new non-canary version right now.
Something like what
npdoes might be nice:It looks like the grep you're using to produce your
--repo-versionis actually returning the current version? It may be that you need to increment the patch level on that to get what you're looking for. Also the-c(--canary) option you're including prohibits Lerna from tagging your newly published version as "latest", so npm won't provide it by default.gigabo commentedon Dec 22, 2016
Welcome! 😀
kristianmandrup commentedon Apr 1, 2017
Would be nice with a short paragraph/recipe on a typical setup for CI/CD. I guess it would just be publish without pushing to npm, triggering the CI from the git repo? or is there a smarter way?
Rowno commentedon Dec 22, 2017
I got CI publishing working on CircleCI using
lerna publish --skip-npm, this script:And this CircleCI config:
kopax commentedon Apr 9, 2018
Hi, we would like to publish to npm in our ci. We need to do it non interactive.
Usually, we just bump the next version of
package.jsonondevbranch when wetagfrommaster. This way we just need to keep or update the version inpackage.jsonbefore merging tomasterto tag a specific version.Is it possible with Lerna ?
evocateur commentedon Apr 9, 2018
@kopax No, not at present.
kopax commentedon Apr 9, 2018
@evocateur do you have another purpostion on how we should adapt our publishing process to integrate Lerna in our stack? Why won't this be implemented that way?
evocateur commentedon Apr 9, 2018
If you're comfortable with allowing CI to make commits and push tags, I would restrict non-canary publishing to
masterand adopt conventional commits (available via the--conventional-commitslerna flag).The process for automated publishing in CI is not ideal right now, so I'd recommend against it in most cases. I hope to improve this in the future.
kopax commentedon Apr 9, 2018
Thanks @evocateur for conventional commits link. I will consider it in the futur to automate our changelog.
So far, the only solution in the CI is to run my own script and iterate in each package to tag ?
evocateur commentedon Apr 9, 2018
Not the only solution, but almost all of the currently-available solutions using only
lernaare painful in one way or another.semantic-release-monorepo is another approach.
kopax commentedon Apr 9, 2018
@evocateur painful in what way ?
I feel like the simple script would just iterate for
packages/**/package.jsonand runnpm version patchthengit tag. Do you see any other complication ?evocateur commentedon Apr 9, 2018
Well, in that case, I guess why bother with lerna, then? There's lots of logic related to choosing "what" to publish.
lerna publish --canarywould get you most of the way there, but with no record of the changes, and a version number that is really awkward.kopax commentedon Apr 9, 2018
I've been playing with lerna and it is an amazing tool, that is I think a good reason to use it.
To use it in our stack, we need to be able to release and tag during our CI process and that's a requirement.
I don't get that point. We are doing all our change in
devbranch, theCHANGELOG.mdis updated manually and controlled before merging to ourmaster.The person who is opening the merge request to master is in charge of setting the proper version in
package.json. The person who validate the commit is in charge of confirming the version.With this in place, we have been able to manage many projects and dependencies without worrying about the release part. We'd like to keep it that way.
Now we have tried lerna, we like to be able to host multiple packages on a single git repository which will increase even more our productivity.
Do you think another option to fit that need could be requested?
If lerna can let us play that way, I'll be happy to help (writing the feature request) and programming (if assisted).
evocateur commentedon Apr 9, 2018
Lerna doesn't really support the separation of versioning and publishing very gracefully right now.
revelt commentedon May 30, 2019
hi guys, I did manage to set up Lerna monorepo on Gitlab's CI to publish to npm. When
git pushis done, GitLab CI triggers andlerna bootstrap+lerna versionbuilds the latest sources (using Conventional Commits) including changelogs and bumpedpackage.jsons. From there on, I don't use Lerna any more for the rest of publishing. This allows me to granularly control tag pushing, committing and pushing to git source.Main idea is, npm won't publish packages which don't have a new, bumped
package.jsonversion. It's not very efficient to manually npm publish each of the packages but it's safe and it works.CI logs in as me into git and npm (using login details as secrets put in GitLab preferences), final bits are commited and published to npm, then
git pushed to git origin. After it's done, Igit pullthe latest from CI onto my laptop.Here's the GitLab CI yml:
$GITLAB_USER_EMAILand all other variables that start with dollar are secrets you set in GitLab repo preferences.npm script
pub:verslooks like this:lernacleanchangelogis lerna-clean-changelogs-cli call. As you know, Conventional Commits puts "Note: Version bump only for package ranges-apply" if there were nofeat/fixcommits and CLI removes those changelog entries.make republishis a shell script which loops through all package directories inpackages/and doesnpm publish.It took me pretty much all the Christmas holidays of 2018 to get this setup above. Whoever is interested to see the repo, it's here: https://gitlab.com/codsen/codsen — 84 npm packages.
JamesHenry commentedon Nov 29, 2022
Hi Folks 👋
Publishing using lerna in CI has been well supported for some time now and so I am going to close this older issue. If you have any requests that could enhance your usage of Lerna 6, then please do let us know by opening a new discussion (for a feature) or issue (for a bug report) with as much context as possible.
You can also check out our published roadmap for Lerna v7 here: #3410
Many thanks 🙏