lerna / lerna

:dragon: Lerna is a fast, modern build system for managing and publishing multiple JavaScript/TypeScript packages from the same repository.
https://lerna.js.org
MIT License
35.65k stars 2.25k forks source link

[Feature] lerna --dryrun #51

Open gigabo opened 8 years ago

gigabo commented 8 years ago

Hi,

Really liking lerna so far. However I've encountered some unexpected behavior that wound up getting pushed to our public repo and published to npm.

I'd like to be able to run lerna publish to the point of creating the version commit and tag and stop it there so I can inspect what it did before proceeding.

My first thought for an interface for this is:

$ lerna prepublish
... make sure everything's as expected...
$ lerna publish

Where in this case lerna publish would see that the head revision is a version tag and skip the prepublish steps.

It might also be nice to have a lerna revert that's basically just git reset --hard HEAD^ after verifying that the HEAD revision is a version commit.

I'd be happy to do the work for this and submit a PR if you're open to the idea. How does it sound? Ideas for a better interface?

Thanks!

Bo

sebmck commented 8 years ago

Sounds like you're looking for just lerna updated then?

gigabo commented 8 years ago

I don't think lerna updated actually gives me what I want here.

Here's the output:

$ lerna updated

Lerna updated v1.1.0

Current version: 0.0.5
Version file location: /Users/bo/git/react-server/VERSION
Packages location: /Users/bo/git/react-server/packages

Checking packages...
- react-server
- react-server-gulp-module-tagger

What I'm looking for is: What exact changes will lerna make before publishing.

I just want the opportunity to review the commit before it's pushed and published in my name. :)

jamiebuilds commented 8 years ago

Oh like a --dry-run flag

gigabo commented 8 years ago

Yes, exactly! Though the partial work done during the dry run in general will be just fine and I wouldn't want to do it again for the actual publish.

gigabo commented 8 years ago

So what about this for an interface:

$ lerna publish --dry-run # Create the version commit
$ lerna publish           # Push and publish (create commit if necessary)
$ lerna publish --abort   # Revert the version commit (if present)
hzoo commented 8 years ago

Yeah ok, so you don't publish what you didn't intend?

gigabo commented 8 years ago

Exactly! If that interface looks okay I'd be happy to set it up and submit a PR.

jamiebuilds commented 8 years ago

I'd rather just the --dry-run flag that give you a detailed run through of what it would do. This requires abstracting away operations that have side-effects into utilities that can be turned off via a flag, which I already wanted to do for logging (#49), I'll take this over because it will require abstraction of a lot of things.

gigabo commented 8 years ago

Sounds good. Thanks @thejameskyle.

chrisui commented 8 years ago

Any update on the progress here? @thejameskyle Noticed some verbose logging has been merged just wondering if this flag will be following soon?

As someone picking up lerna for the first time this would be an incredibly useful feature just for getting to grips and not worrying about blowing things up! :)

jamiebuilds commented 8 years ago

It's a tough problem because some things depend on file system state. We need to do more work to read the entire file system that it cares about at the beginning and track it throughout the entire process. This will also help performance because there are places where we are re-reading files we already have in memory.

chrisui commented 8 years ago

@thejameskyle Cheers for the update!

I wonder if a proxy around node fs and https://github.com/webpack/memory-fs would do the trick for you?

tamlyn commented 6 years ago

An alternative way to test what lerna will do is to install a local npm registry and publish to that:

npm i -g verdaccio
verdaccio
npm set registry http://localhost:4873
npm adduser --registry http://localhost:4873
lerna publish

Then use npm pack <name> to inspect the tarballs it published.

(Updated to use verdaccio which is a more up to date fork of sinopia.)

mojavelinux commented 6 years ago

Thanks @tamlyn! That was super helpful advice. My only addition is that you left out the step to start sinopia.

mojavelinux commented 6 years ago

I was able to use the combination of --skip-npm and --skip-git to perform dry runs in order to learn how to use lerna and become familiar with how it works before making any permanent changes.

My one request is to be able to perform the git operations, but bypass git push. I accomplished this by setting up a remote to a dummy repository and pointing to it using the --git-remote flag.

jsardev commented 6 years ago

Any plans on this feature? For now there were suggested only few workarounds. It would be lovely to have a --dry-run in lerna.

arndissler commented 6 years ago

During the last weeks I spent some time to think about this feature. It would be a great feature, at least for lerna beginners. I would go with the interface suggestion which @gigabo posted here: https://github.com/lerna/lerna/issues/51#issuecomment-183441844.

@jamiebuilds Are there any concerns? Or is this task/feature/issue free for getting picked up?

jantimon commented 6 years ago

Maybe we could add some additional confirms:

$ lerna publish --conventional-commits

lerna info version 2.11.0
lerna info current version 0.0.0
lerna info Checking for updated packages...
lerna info Comparing with initial commit.
lerna info Checking for prereleased packages...

Changes:
 - foo: 0.0.1 => 1.1.0
 - bar: 0.0.1 => 1.1.0

? Are you sure you want write the changes to your package.json and changelog files? Yes
? Are you sure you want to push the above changes to git? Yes
? Are you sure you want to publish the above changes to npm? Yes

This would make it more obvious to the user about what is going to happen next and he could skip those questions using the --yes flag.

Bonus: A maintainer could also alter a generated changelog / package.json before confirming the publish actions.

manniL commented 5 years ago

I'd love to see that feature :clap:

theetrain commented 5 years ago

I'd like to chime in since I have similar desires in the context of continuous delivery. In the repository I help maintain, we use TravisCI to report back what packages will receive version bumps before a pull request gets merged to master. Here is an example: https://github.com/telus/tds-core/pull/862

Our goal is to eventually set up continuous delivery of packages along with the version bump insights we recieve from lerna. In lerna 2.x, we achieved this by leveraging exposed methods from lerna. This is unfortunately brittle since there is no official API in lerna 2.x nor 3.x.

I would be satisfied if I could run lerna version --conventional-commits --no in my CI pipeline, but there is no --no option; having a --no option would satisfy the 'dry run' scenario I would like to see. Consequently, as I'm in the process of upgrading to lerna 3.x, I may have to perform spawn acrobatics to achieve the above.

I'm willing to help contribute a solution once we all arrive at a consensus.

thanasis00 commented 5 years ago

The option --dryrun could be a part of almost all commands. I was thinking about the lerna version command as well, to see what will happen before tagging and generating changelog files. I could also help in this PR as well.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

trollepierre commented 5 years ago

what's about the dryRun command??

ewnd9 commented 5 years ago

I was able to get an update manifest for the version command without changing anything in fs/git only after shimming serialize in @lerna/package

Gist https://gist.github.com/ewnd9/dfcdbf67e7099da12a3973f89d48ed81

metasean commented 4 years ago

Any status updates for a --dry-run flag.

Like @theetrain I'm looking to use --dry-run in a CI environment for a pre-approval, so if the decision is to go a confirmation questions route (like @jantimon suggested), a simple --no option would serve the same purpose.

ghost commented 4 years ago

While a --dry-run flag seems ideal there are several workarounds here which seem to do the trick. However, the crux here seems to be the "it touched my code/git/npm!" and I didn't want that. For that reason my suggestion would be to tag this issue as wontfix and implement prompts as suggested here: https://github.com/lerna/lerna/issues/51#issuecomment-410973914

trollepierre commented 4 years ago

I agree with the prompt idea, only if there won't be any prompt in the CI

JounQin commented 4 years ago

Sorry, but any news on it? It should be very useful.

aibolik commented 4 years ago

Any news on --dry-run in 2020 ?) 😀

If it doesn't progress much it'd be nice to mention workarounds how to run in "dry-run"-ish mode.

Reading this thread and consolidating comments to couple of paragraphs would be nice.

I could open a PR.

joshdcomp commented 4 years ago

From what I can tell, you can accomplish a dry run with --no-git-tag-version and --no-push yes?

aibolik commented 4 years ago

@joshdcomp yeah, makes sense. I'll open a PR to add a section about this.

arvigeus commented 4 years ago

@joshdcomp I tried it now and it published my packages.

JackHowa commented 3 years ago

any updates on this? dry-run would be helpful, to reiterate.

Trying --no per https://github.com/lerna/lerna/issues/51#issuecomment-543981027 didn't work

metasean commented 3 years ago

@JackHowa - Did you try joshdcomp's suggestion https://github.com/lerna/lerna/issues/51#issuecomment-583131358

JackHowa commented 3 years ago

@metasean sort of. we had already been using --no-git-tag-version --no-push. but I just left off --yes to make sure it'd fail in github action

testing, with no publish

npx lerna publish 0.0.0-$(git rev-parse --short HEAD) --no-git-tag-version --no-push --dist-tag beta

actual, with publish

npx lerna publish 0.0.0-$(git rev-parse --short HEAD) --no-git-tag-version --no-push --dist-tag beta --yes

TrejGun commented 3 years ago

Will be very useful in managing dependencies across multi repo project

nzjony commented 3 years ago

Any update in 2021?

beamery-tomht commented 3 years ago

Hello, I'd like this too. The commands shared by @JackHowa were very useful, but the hacked dry run doesn't give information about the generated CHANGELOG.md, for example when developing the template.

joelday commented 3 years ago

--dry-run: everything except change files, create tags, push anything, or publish packages. Wild. 🤷‍♂️

https://www.youtube.com/watch?v=tYx5mphHAiw

Edit: Not being a jerk, just needed to meme.

marckraw commented 3 years ago

--dry-run ftw! would like to have that too :)

pgrabarczyk commented 3 years ago

@tamlyn thanks!

I updated your example to use it in my case in GitLab CI (maybe it will save someone's time):

# Build packages using lerna
npx lerna bootstrap
npx lerna version "${RELEASE_TAG}" --no-git-tag-version --no-push --yes
npx lerna run build

# Start local NPM registry
npx verdaccio >> "local_registry.log" &
sleep 10 # probably not needed

# Configure sample user
local username="test123"
local password="test123"
local email="test123@test123.com"
npx npm-cli-login -u "${username}" -p "${password}" -e "${email}" -r "${local_registry_url}"

# Execute publish in dry-run
npx lerna publish from-package \
    --registry "http://localhost:4873" \
    --no-git-tag-version --no-push --yes \
    --loglevel verbose
JackHowa commented 3 years ago

think this could likely be closed @gigabo as I like and use https://github.com/lerna/lerna/issues/51#issuecomment-705820466

fsmaia commented 1 year ago

Having a --dry-run flag would still be very helpful!

meteabduraman commented 1 year ago

Hey,

Seen that nobody really submitted a PR for this so I thought I'd give it a try (#3401). If you think we can do it better, I'm open to any other suggestions, hope I have some time to add them 🤕

These changes seem to solve at least my use case (want to get a preview of the versions to be created in a CI pipeline - no user inputs allowed, and have someone manually approve that they're correct)

Reach out if you find anything 🤓

ChFlick commented 1 year ago

Any updates on this? I've seen the PR #3401 was declined because it's being worked on, but there hasn't been an update since then.

I'd like to have something to programmatically get the "next versions" of packages being published (and maybe an error if there are none)

sqaisar commented 1 year ago

+1 for the feature. I've some other files like helm chart that needs the updated version/tag to be added to that file.

next-juanantoniogomez commented 7 months ago

+1 for the feature

sevilyilmaz commented 4 months ago

I run lerna version on a Gitlab CI job with some config options and log the upcoming versions in a merge request for that MR's changes.

The command below basically tries to mimic a version command without pushing anything to a registry or a repo.

npx lerna version --no-private --yes --exact --conventional-commits --no-git-tag-version --no-push --no-changelog --json --allow-branch ${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME}

It updates the versions in package.json files in the packages but since I run this command on a CI job I don't need to do anything about them as the changes will be discarded.

If you are willing to use this command until there is an official one I suggest you to check what does each config flags mean and adjust them according to your needs

cellog commented 3 months ago

The reason that the above command is not the same as --dry-run is because there is no way to be certain that you've copy/pasted what would be the same thing. --dry-run should do everything short of publishing to npm/pushing to git remotes, in order to test that you've configured CI correctly. Otherwise you're building the plane as you fly it.

--dry-run is bog standard in any destructive tool. Perhaps this should be closed with "Won't Fix" if that's the true intent?

SchulteMarkus commented 1 month ago

Thanks to open-source, just head over to lerna-lite.

--dry-run Displays the git command that would be performed without actually executing it, however please note that it will still create all the changelogs. This could be helpful for troubleshooting and also to see changelog changes without committing them to Git.

lerna-lite --dry-run