New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change exit codes for updated
and publish
#807
Conversation
Check if there are any packages to update before logging out the normal output and raise an error if there are no packages to update. Related-to: lerna#802
Instead of throwing an error we really just want to return a non-zero exit code. This patch adds the possibility to return a custom exit code (with a default of zero) and utilizes that possibility to return 1 as a exit code when a user runs the `updated` command and there are no packages that need updating. Related-to: lerna#802
Instead of throwing a error we want to just output a message that there is nothing for `publish` to do at this time since there are no changes. This helps in CI systems when you'd just want to run `lerna publish` without having to conditionally running the command based on if there are any changes. This changes the exit code so it would be a breaking change for anyone that currently relies on the exit code to be non-zero. Related-to: lerna#802
Passing `false` to the callback value will cause the exit code to be 1, allowing simpler logic.
@evocateur I just noticed that you added some commits. I imagine managing a project like Lerna gets super hectic so if you need any more changes to this you can always ping me with what needs to change and I can get on it fairly quick (BST timezone tho 🇬🇧 )! Excited for this to land ✨ |
@koddsson Thanks for understanding! I was just about to merge and didn't want to bother you with fiddly stuff. :) |
@@ -11,6 +11,23 @@ const lastCommitMessage = (cwd) => | |||
execa.stdout("git", ["log", "-1", "--format=%B"], { cwd }).then(normalizeNewline); | |||
|
|||
describe("lerna publish", () => { | |||
test.concurrent("exists with a exit code 0 when there are no updates", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exists => exits.
Shouldn't there be an integration test showing the non-zero exit status results when the update command detects no changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They both use the same underlying utility, so the UpdatedCommand unit test is sufficient validation.
It is now possible to run `lerna publish` in CI unconditionally, only publishing when changes are actually detected, and never failing when it decides to not publish anything. Previously: - `lerna publish` when there are no updates to publish would throw an error - `lerna updated` when there are no updates would `exit 0`, making it ineffective as a chained filter (e.g., `lerna updated && lerna publish`) Now: - `lerna publish` when there are no updates is a no-op, exiting successfully with a helpful log message - `lerna updated` when there are no updates will exit non-zero (but _not_ throw an error), enabling it to be an effective filter Fixes lerna#802
@@ -124,7 +124,8 @@ export default class PublishCommand extends Command { | |||
: [packagesToPublish]; | |||
|
|||
if (!this.updates.length) { | |||
callback(new Error("No updated packages to publish.")); | |||
this.logger.info("No updated packages to publish."); | |||
callback(null, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per #887, we definitely need to pass false
as the second argument to callback()
, here. Otherwise it seems we attempt to make a git commit on no changes, and that's just wrong.
Is this fixed? I'm experiencing this in 2.0.0
|
This change was missing from the PR: lerna#807 Relates to the issue: lerna#887 Currently running `lerna publish` when no packages need updating causes the task to crash unnecessarily. This small fix causes the command to complete if no updates are found, instead of trying to continue to the next section.
@evocateur If we know where the issue is, why aren't we fixing it? |
Contributions welcome. |
@evocateur I can make a PR, no problem, but I'm not sure what the best way to test it. |
This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Description
This patch:
updated
command from 0 to 1 when there are no changes to publishpublish
from 1 to 0 and instead of throwing a error with a message that there is nothing to publish, logs that message out.Motivation and Context
This change enables users that want to publish packages from a CI to more easily create a flow that relies on the exit codes of lerna commands.
Before this change CI builds would fail when
lerna publish
would return a non-zero exit code and it was not possible to tacklerna updated
in front of it (!lerna updated & lerna publish
) since it would always return a zero exit code.Fixes #802
How Has This Been Tested?
I added a unit test for
lerna updated
and a integration test forlerna publish
.The
lerna updated
explicitly checks the exit code of that the command returns is 1 but the integration relies on the fact that iflerna publish
would return a non zero exit code the test would fail.Types of changes
(This might be a breaking feature if we consider changing the exit code a breaking change, I'm not sure what you think)
Checklist:
The docs don't mention exit codes as far as I can see but I can certainly add something to that effect to the docs if you'd like :)