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

Recover from failed publish #455

Closed
heruan opened this issue Dec 19, 2016 · 18 comments
Closed

Recover from failed publish #455

heruan opened this issue Dec 19, 2016 · 18 comments

Comments

@heruan
Copy link

heruan commented Dec 19, 2016

I lost connectivity during lerna publish and some packages got lerna-temp published and other not. Now I have a dirty tree were lerna publish fails with:

$ lerna publish
Lerna v2.0.0-beta.30
Independent Versioning Mode
Checking for updated packages...
Errored while running PublishCommand.initialize
Error: No updated packages to publish.
    at PublishCommand.initialize (/usr/local/lib/node_modules/lerna/lib/commands/PublishCommand.js:94:18)
    at PublishCommand._attempt (/usr/local/lib/node_modules/lerna/lib/Command.js:161:21)
    at PublishCommand.runCommand (/usr/local/lib/node_modules/lerna/lib/Command.js:145:12)
    at PublishCommand.run (/usr/local/lib/node_modules/lerna/lib/Command.js:69:12)
    at Object.<anonymous> (/usr/local/lib/node_modules/lerna/bin/lerna.js:58:11)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)

How can I recover from this?

@gigabo
Copy link
Contributor

gigabo commented Dec 19, 2016

@heruan Yikes! Sorry you ran into trouble.

Lerna uses git tags to keep track of published versions. It looks like the tag for the version you were in the middle of publishing may have been created before the command failed.

You can see the latest tag with this command:

$ git describe --abbrev=0 --tags
v2.0.0-beta.31

And you can see the associated commit using the tag name:

$ git show v2.0.0-beta.31

The tag should refer to a commit on your current branch. If you haven't made any commits since the failed publish then it should be HEAD.

A few things to check:

  1. Were any of the packages actually published? You can check with npm dist-tag ls <package-name>. Packages may have been published but may not yet have received the latest tag.
  2. Were your branch and tag pushed to your remote repo? The commits may exist only locally.

It's important to know the state of your packages in the npm registry and your repo in your remote repository before proceeding.

@sccolbert
Copy link

sccolbert commented Jun 12, 2017

I just got bit by a similar issue. lerna publish failed because one of my scoped packages was not yet published with --access=public so npm rejected the publish. After correcting that, lerna thinks there is nothing updated to publish, but none of the npm tags have yet been updated.

It would be awesome if lerna could retry a publish after failing.

@KELiON
Copy link

KELiON commented Aug 7, 2017

I had the same issue: I've added new package, but when I wanted to publish it, npm publish failed with "You should confirm your email before publishing new package" and after that I can't publish new version.

I had version 0.0.13, started update to 0.0.14 with lerna, but after this fail I see vundefined tag was created, but no v0.0.14. I tried to create v0.0.14 tag manually, git pull --tags, but after running lerna publish I see vundefined again. After that I deleted tag vundefined, git describe --abbrev=0 --tags correctly shows last tag, but lerna publish says:

? Select a new version (currently undefined) (Use arrow keys)
❯ Patch (null)
  Minor (null)
  Major (null)
  Prepatch (null)
  Preminor (null)
  Premajor (null)
  Prerelease
  Custom

Any thoughts how to fix it?

UPD: fixed it with publishing custom version, but anyway "current" version in this case determined incorrectly

@pixelass
Copy link

I always get this issue when I forget to npm login before publishing new public packages

@timneedham
Copy link

@pixelass and @KELiON... that specific problem went away when I lerna init again to get a missing version property in lerna.json:

{
  "lerna": "2.9.0",
  "packages": [
    "packages/*"
  ],
  "hoist": true,
  "command": {
    "init": {
      "exact": false
    }
  },
  "version": "0.0.1"
}

@rjdestigter
Copy link

rjdestigter commented May 3, 2018

I use this script to double check if the packages that are managed by lerna have the latest dependencies as well as if they conflict with npm after publishing fails:

https://gist.github.com/rjdestigter/e673ccfcfff921d40d26246bfbb4ca60

(Install the necessary imports at the top and replace "NAMEOFYOURORGINISATION" with your npm organisation name.) The script basically collects all package.json files. Then for each package checks if it depends on packages within my organisation and is behind in a dependency version. Then it uses npm view version to check if the version is different from the version that is published on npm.

@vittalas
Copy link

vittalas commented Aug 9, 2018

I ran into this issue as well where my lerna publish failed due to some issue with our repository but the tags were created and now i am not able to republish that since it says no updated packages to publish

lerna info Checking for prereleased packages...
lerna info No updated packages to publish.

what is the solution for this? how can i republish already created tags by lerna

@berstend
Copy link

berstend commented Aug 18, 2018

I ran into this as well today (a yarn token issue mentioned in #1347). To my future self 😄:

Confirm publishing state (no commits had been pushed yet):

~/d/o/puppeteer-extra git:master ❯❯❯ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)
nothing to commit, working directory clean

~/d/o/puppeteer-extra git:master ❯❯❯ git log
commit 603032ec35b16a6eb60a9940cb0801de78fef9bb
Date:   Sat Aug 18 19:47:52 2018 +0200

    Publish

     - puppeteer-extra-plugin-anonymize-ua@2.0.8
     - puppeteer-extra-plugin-block-resources@2.0.9
     (...)

~/d/o/puppeteer-extra git:master ❯❯❯ git describe --abbrev=0 --tags
puppeteer-extra-plugin-devtools@2.0.9

Revert failed publish (doesn't reset tags, only the last commit):

~/d/o/puppeteer-extra git:master ❯❯❯ git reset --hard HEAD^
HEAD is now at c7537d0 Update docs

Confirm and fix yarn / npm issue:

❯❯❯ yarn login
yarn login v1.7.0
info npm username: berstend

❯❯❯ npm whoami
npm ERR! code E401

❯❯❯ npm login
Username: berstend

❯❯❯ npm whoami
berstend

Upgrade lerna (i was still on 2.11.0 and 3.1.1 handles publishing errors better):

~/d/o/puppeteer-extra git:master ❯❯❯ yarn add lerna --ignore-workspace-root-check --dev

Modify lerna.json to use npm instead of yarn as registry client (it just wouldn't work with yarn):

  "npmClient": "npm",
  "registry": "https://registry.npmjs.org/",

... and finally run lerna publish two times (one for good measure and one due to existing tags).

Whew!

The yarn error I was hitting (for google fu):

lerna ERR! publish error No token found and can't prompt for login when running with --non-interactive.

@andrewc89
Copy link

When publishing to the registry fails, is it possible to not only not push the "Publish" commit, but to revert the commit and delete the tags? Or just not take these steps until the packages have been successfully published?

@amphro
Copy link

amphro commented Nov 14, 2018

That would be my vote too. I don't think the "Publish" commit or tag should be pushed if the NPMs don't publish.

@flodev
Copy link

flodev commented Nov 28, 2018

I had a lerna publish error because of a wrong configured .npmrc
In my case I had to (fix my npmrc first and then) go through all my packages and and execute manually npm publish --ignore-scripts <packagename.tgz> (tgz files where already created by lerna publish)

@tehpsalmist
Copy link

What's the status with this issue? I just had a situation where I tried to lerna publish and had some things out of line, so the publishing failed (I don't think it even got to the npm publish part, tbh), but when I check github, I see that some bogus commit was already pushed to github's master branch with the message "Publish." Surely this isn't how it's supposed to work, right? What could I have been doing wrong?

@absassi
Copy link

absassi commented Apr 21, 2020

I don't know the Lerna's code base, but it seems so trivial of a change to just delay the git push to the last step. It's quite simple to revert all other Git changes manually (deleting tags and resetting to previous commit), but once tags are pushed, it can be really hard to delete them (someone else may have already fetched them and they have to manually delete them as well).

Anyway, at least there's the hidden --no-push option (it's not in the publish help, but it works), so I'm using lerna publish --no-push && git push --tags.

I've seen in other issues suggestions to use from-package to just retry without having to undo anything on Git, but, if I understand well, that only works if the issue was temporary, not if there was a bug in your code preventing the publishing to work (e.g. a mistake in some package.json that only affects the publish command), because that requires a new commit to fix it, and therefore you normally don't want leave the wrong tags the repository.

@tehpsalmist
Copy link

Thanks for pointing out --no-push, that is useful.

@kadishmal
Copy link

The way I fixed this issue is as follows:

  1. Uncommit from the local repo and tag.

    git reset --hard HEAD^
    git tag -d v1.0.0
    
  2. Remove the last commit and tag in the remote (Github) pushed by Lerna.

    git push origin +HEAD
    git push --delete origin v1.0.0
    
  3. Retry lerna publish

    lerna publish
    

@JamesHenry
Copy link
Member

Hi Folks 👋

As you may have seen in our published roadmap for Lerna v7 here: #3410 recoverable publish is a priority for us in this current phase of work.

I am going to close any duplicate issues in this area and point them here. As a lerna user myself I'm excited to land this!

Many thanks 🙏

@JamesHenry
Copy link
Member

Hi again, delighted to say that this capability is already available in the latest lerna (6.5.1 at the time of writing) thanks to #3513

Please upgrade to the latest and you should not run into republishing issues again.

Many thanks!

@jonsoku-dev
Copy link

jonsoku-dev commented Feb 23, 2023

#!/bin/sh

# Run an npm command
npm run lerna publish

# Check the exit code of the previous command
if [ $? -ne 0 ]; then

# If the exit code is not 0, an error occurred
echo "An error occurred while running the npm command. Running error script..."

# Execute the error script

# Check if the system is macOS
if [ "$(uname)" != "Darwin" ]; then
  echo "This script is only compatible with macOS."
  exit 1
fi

# Check if jq is installed and available in the PATH
if ! command -v jq >/dev/null 2>&1; then
  echo "jq is not installed or not in the PATH. Please install jq first."
  exit 1
fi

# Define variables
JSON_FILE="./lerna.json"
KEY="version"

# Extract the value of the specified key from the JSON file and save it as a variable
VALUE=v$(cat "$JSON_FILE" | jq -r ".$KEY")

# Print the value of the variable
echo "$VALUE"

# Remove the last commit and tag in the local repo
git reset --hard HEAD^
git tag -d "$VALUE"

# Remove the last commit and tag in the remote (Github) repository
git push origin +HEAD
git push --delete origin "$VALUE"

fi

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

No branches or pull requests