Skip to content
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

Merged
merged 8 commits into from May 18, 2017

Conversation

koddsson
Copy link
Contributor

@koddsson koddsson commented May 5, 2017

Description

This patch:

  • Changes the exit code for the updated command from 0 to 1 when there are no changes to publish
  • Changes the exit code from publish 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 tack lerna 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 for lerna publish.

The lerna updated explicitly checks the exit code of that the command returns is 1 but the integration relies on the fact that if lerna publish would return a non zero exit code the test would fail.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

(This might be a breaking feature if we consider changing the exit code a breaking change, I'm not sure what you think)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

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 :)

Kristján Oddsson added 3 commits May 4, 2017 22:33
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
@evocateur evocateur added this to the v2.0.0 milestone May 7, 2017
@koddsson
Copy link
Contributor Author

@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 ✨

@evocateur
Copy link
Member

@koddsson Thanks for understanding! I was just about to merge and didn't want to bother you with fiddly stuff. :)

@evocateur evocateur merged commit 880fdf3 into lerna:master May 18, 2017
@@ -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 () => {
Copy link
Contributor

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?

Copy link
Member

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.

treshugart pushed a commit to treshugart/lerna that referenced this pull request May 24, 2017
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);
Copy link
Member

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.

@dan3721
Copy link

dan3721 commented Aug 4, 2017

Is this fixed? I'm experiencing this in 2.0.0

? Are you sure you want to publish the above changes? Yes lerna ERR! execute Error: On branch master lerna ERR! execute Your branch is up-to-date with 'origin/master'. lerna ERR! execute Changes not staged for commit: lerna ERR! execute modified: lerna.json lerna ERR! execute modified: packages/bar/package.json lerna ERR! execute modified: packages/foo/package.json lerna ERR! execute lerna ERR! execute no changes added to commit lerna ERR! execute lerna ERR! execute at Function.module.exports.sync (C:\Users\BusDa001\AppData\Roaming\npm\node_modules\lerna\node_modules\execa\index.js:277:26) lerna ERR! execute at Function.execSync (C:\Users\BusDa001\AppData\Roaming\npm\node_modules\lerna\lib\ChildProcessUtilities.js:59:30) lerna ERR! execute at Function.commit (C:\Users\BusDa001\AppData\Roaming\npm\node_modules\lerna\lib\GitUtilities.js:84:39) lerna ERR! execute at PublishCommand.gitCommitAndTagVersion (C:\Users\BusDa001\AppData\Roaming\npm\node_modules\lerna\lib\commands\PublishCommand.js:612:30) lerna ERR! execute at PublishCommand.commitAndTagUpdates (C:\Users\BusDa001\AppData\Roaming\npm\node_modules\lerna\lib\commands\PublishCommand.js:582:27) lerna ERR! execute at PublishCommand.execute (C:\Users\BusDa001\AppData\Roaming\npm\node_modules\lerna\lib\commands\PublishCommand.js:261:16) lerna ERR! execute at PublishCommand._attempt (C:\Users\BusDa001\AppData\Roaming\npm\node_modules\lerna\lib\Command.js:289:21) lerna ERR! execute at C:\Users\BusDa001\AppData\Roaming\npm\node_modules\lerna\lib\Command.js:276:15 lerna ERR! execute at C:\Users\BusDa001\AppData\Roaming\npm\node_modules\lerna\lib\Command.js:298:13 lerna ERR! execute at C:\Users\BusDa001\AppData\Roaming\npm\node_modules\lerna\lib\commands\PublishCommand.js:495:11 lerna ERR! execute callback with error lerna ERR! execute { Error: On branch master lerna ERR! execute Your branch is up-to-date with 'origin/master'. lerna ERR! execute Changes not staged for commit: lerna ERR! execute modified: lerna.json lerna ERR! execute modified: packages/bar/package.json lerna ERR! execute modified: packages/foo/package.json

alisd23 added a commit to alisd23/lerna that referenced this pull request Aug 9, 2017
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.
@iMoses
Copy link

iMoses commented Aug 22, 2017

@evocateur If we know where the issue is, why aren't we fixing it?
Will it be fixed in the near future?

@evocateur
Copy link
Member

Contributions welcome.

@iMoses
Copy link

iMoses commented Aug 23, 2017

@evocateur I can make a PR, no problem, but I'm not sure what the best way to test it.
I haven't seen any tests verifying behavior when no changes were made.
Any pointers here to get me started?

@lock
Copy link

lock bot commented Dec 27, 2018

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.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lerna throws a error when there is nothing to publish
5 participants