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

Rollback Git operations when publish fails and on termination #334

Merged
merged 15 commits into from
Mar 31, 2019
Merged

Rollback Git operations when publish fails and on termination #334

merged 15 commits into from
Mar 31, 2019

Conversation

itaisteinherz
Copy link
Collaborator

@itaisteinherz itaisteinherz commented Jan 20, 2019

This is my first attempt at fixing #197. The code's not really working for some reason, and I'm pushing this to get an initial review since I've been trying to get this to work for nearly two weeks.

Fixes #197

source/index.js Outdated Show resolved Hide resolved
source/index.js Outdated Show resolved Hide resolved
source/index.js Outdated Show resolved Hide resolved
source/index.js Outdated Show resolved Hide resolved
source/index.js Outdated Show resolved Hide resolved
source/index.js Outdated Show resolved Hide resolved
source/index.js Outdated Show resolved Hide resolved
source/index.js Outdated Show resolved Hide resolved
source/index.js Outdated Show resolved Hide resolved
source/git-util.js Outdated Show resolved Hide resolved
source/index.js Outdated Show resolved Hide resolved
source/index.js Outdated Show resolved Hide resolved
@sindresorhus
Copy link
Owner

When publish fails it doesn't rollback:

? Will bump from 1.2.0 to 1.2.1. Continue? Yes
  ✔ Prerequisite check
  ✔ Git
  ✔ Bumping version using npm
  ✔ Prerequisite check
  ✔ Git
  ✔ Bumping version using npm
  ✔ Publishing package using npm
  ↓ Pushing tags [skipped]
    → Couldn't publish package to npm; not pushing.
  ✔ Creating release draft on GitHub

 sindre-playground 1.2.1 published 🎉

It's weird that ✔ Publishing package using npm has a checkmark, even though it failed. And if publish fails, it should cancel any following tasks, like creating release draft.

@itaisteinherz
Copy link
Collaborator Author

It's weird that ✔ Publishing package using npm has a checkmark, even though it failed.

I noticed this as well, but haven't figured out why it happens yet. I'll dive into the issue later today.

@itaisteinherz
Copy link
Collaborator Author

@sindresorhus aae3a7e should fix some of the issues you were talking about.

source/index.js Outdated Show resolved Hide resolved
source/index.js Outdated Show resolved Hide resolved
source/index.js Outdated Show resolved Hide resolved
@sindresorhus
Copy link
Owner

Let me know when #334 (comment) is fixed.

@itaisteinherz
Copy link
Collaborator Author

@sindresorhus It is fixed. The current issue is that when terminating np while the package is being published, rollback isn't called and the project doesn't get rolled back.

@itaisteinherz
Copy link
Collaborator Author

@sindresorhus The origin of the issue was that I used async-exit-hook incorrectly (see dd540e3) 😅

@itaisteinherz itaisteinherz changed the title Rollback Git operations when publish fails and on SIGINT Rollback Git operations when publish fails and on termination Mar 1, 2019
@itaisteinherz
Copy link
Collaborator Author

itaisteinherz commented Mar 1, 2019

@sindresorhus Do you think we should add a note about this to the readme? (probably in the Why section)

@sindresorhus
Copy link
Owner

Add a note about what?

@itaisteinherz
Copy link
Collaborator Author

Add a note about what?

The fact the np rolls back the project to its previous state in case the publish fails or if it gets terminated.

@sindresorhus
Copy link
Owner

It doesn't seem to work when the publish command fails. Just for testing I changed the actual command from npm publish to npm publish2:

~/dev/oss/sindre-playground master
❯ np

Publish a new version of sindre-playground (current: 1.2.3)

? No commits found since previous release, continue? Yes
? Select semver increment or specify new version patch 	1.2.4
? Will bump from 1.2.3 to 1.2.4. Continue? Yes
  ✔ Prerequisite check
  ✔ Git
  ↓ Cleanup [skipped]
  ✔ Prerequisite check
  ✔ Git
  ↓ Cleanup [skipped]
  ✔ Installing dependencies using npm
  ✔ Running tests using npm
  ✔ Bumping version using npm
  ✖ Publishing package using npm
    → The project was rolled back to its previous state.
    Pushing tags
    Creating release draft on GitHub

✖ Error publishing package:
Command failed: npm publish2


Usage: npm <command>

where <command> is one of:
    access, adduser, audit, bin, bugs, c, cache, ci, cit,
    clean-install, clean-install-test, completion, config,
    create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
    edit, explore, get, help, help-search, hook, i, init,
    install, install-ci-test, install-test, it, link, list, ln,
    login, logout, ls, org, outdated, owner, pack, ping, prefix,
    profile, prune, publish, rb, rebuild, repo, restart, root,
    run, run-script, s, se, search, set, shrinkwrap, star,
    stars, start, stop, t, team, test, token, tst, un,
    uninstall, unpublish, unstar, up, update, v, version, view,
    whoami

npm <command> -h  quick help on <command>
npm -l            display full usage info
npm help <term>   search for help on <term>
npm help npm      involved overview

Specify configs in the ini-formatted file:
    /Users/sindresorhus/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config

[email protected] /Users/sindresorhus/n/lib/node_modules/npm

Did you mean one of these?
    publish
    unpublish


The project was rolled back to its previous state.

It says it rolled back the state, but I still have the 1.2.4 commit and tag.

@sindresorhus
Copy link
Owner

The fact the np rolls back the project to its previous state in case the publish fails or if it gets terminated.

Yes, definitely. Should also be mentioned in the highlights as it's a good feature.

@itaisteinherz
Copy link
Collaborator Author

It says it rolled back the state, but I still have the 1.2.4 commit and tag.

Fixed in 0ed1047.
(The issue was that the commit message when using npm is x.x.x while the message when using yarn is vx.x.x. The rollback function didn't account for the inconsistency, which made the rollback fail.)

@itaisteinherz
Copy link
Collaborator Author

@sindresorhus I think that this is ready to be merged.

@NeekSandhu @SamVerschueren It would be great if you could test this out and let me know if this works for you as expected.

@sindresorhus sindresorhus merged commit c7d4cd0 into sindresorhus:master Mar 31, 2019
@sindresorhus
Copy link
Owner

It's working well for me :)

@sindresorhus
Copy link
Owner

Found another issue. It shows the rollback message when a running the tests and a test fails. However, it's not technically rolling back anything then as nothing has been committed yet.

? Select semver increment or specify new version major 	2.0.0

  ✔ Prerequisite check
  ✔ Git
  ✔ Cleanup
  ✔ Installing dependencies using npm
  ✖ Running tests using npm
    →   1 error
    Bumping version using npm
    Publishing package using npm
    Pushing tags
    Creating release draft on GitHub

✖ Command failed: npm test
npm ERR! Test failed.  See above for more details.


> [email protected] test /Users/sindresorhus/dev/oss/stringify-attributes
> xo && ava && tsd


  index.js:5:8
  ✖  5:8  Parsing error: Identifier attributes has already been declared

  1 error


Publish failed. Rolling back to the previous state…

@itaisteinherz
Copy link
Collaborator Author

@sindresorhus I opened an issue to track this: #396.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rollback git operations on np fail
3 participants