Skip to content

Publishing independent lerna in CI #653

Closed

Description

@moeriki

Dears,

I'm having some issues figuring out how to publish Lerna in independent mode through a CI.

I want to:

  1. update NPM versions independently locally
  2. have CI do NPM publish

I can do 1. with lerna publish --skip-npm. But how do I do 2. ?

I checked the source code of publish and it seems to me an option is missing. Something like --current to publish all tags attached to the last commit.

Or am I missing something. Your feedback would be greatly appreciated.

Activity

  1. noherczeg commented on Mar 8, 2017

    @noherczeg
    Contributor
  2. moeriki commented on Mar 16, 2017

    @moeriki
    Author

    I have tried some things and settled with this script.

    package.json

    {
      "scripts": {
        "deploy": "node deploy.js"
      }
    }

    deploy.js

    const exec = (command) => execSync(command, { encoding: 'utf8' }).trim();
    const LERNA_BIN = path.join(exec('npm bin'), 'lerna');
    const lerna = (args) => exec(`${LERNA_BIN} ${args}`);
    
    const split = (pattern) => (chars) => chars.split(pattern);
    const zip = (destination, source) => Object.assign(destination, { [source[0]]: source[1] });
    
    const isPkg = (tag) => tag.match(/[\w-]+@\d+\.\d+\.\d+(-[\w\d]+)?/);
    
    const updatedPackages = exec('git tag --list --contain HEAD')
      .split('\n')
      .filter(isPkg)
      .map(split('@'))
      .reduce(zip, {})
    ;
    
    for (const pkg of Object.keys(updatedPackages)) {
      const version = updatedPackages[pkg];
      lerna(`--scope ${pkg} exec -- npm publish`);
    }

    It's a bit surprising such a manual effort is needed to deploy independent packages through a CI. Any plans to make anything like the script above available as lerna command?

  3. evocateur commented on Mar 16, 2017

    @evocateur
    Member

    I suppose I'm left wondering why you would want to split these decisions? If you're just trying to gate a release on tests passing, that should be a prepublish lifecycle (or other agreed-upon process).

    We definitely want to support automated publishing in CI (something like semantic-release), but I don't think we can safely support this split-decision approach in our current codebase.

    I can see an argument for improving lerna updated or lerna ls to support better filtering and perhaps even a --since=<commit-ish> flag that would make scripts like yours far easier.

  4. moeriki commented on Mar 16, 2017

    @moeriki
    Author

    No good reason. Just company policy 😖

  5. evocateur commented on Mar 16, 2017

    @evocateur
    Member

    Oh, I sympathize! I'm probably going to be in a similar situation at work Real Soon Now™️, so it's not completely hopeless.

    However, we've got a (growing) complexity problem with the codebase, and I'm trying to keep the stuff that can be an external script externalized for now. My dream is to make various parts of lerna pluggable, so we can simplify a bit of the core code and have cleaner integrations with special cases like yours.

  6. moeriki commented on Mar 16, 2017

    @moeriki
    Author

    No problem. I'm good as-is.

  7. joebowbeer commented on May 10, 2018

    @joebowbeer

    Can step 2 be accomplished using --skip-git, possibly in combination with --force-publish?

    lerna publish --skip-git

    Given the usual sequence of operations to publish an npm package:

    $ npm version patch
    $ git push --tags origin master
    $ npm publish

    I am hoping that lerna provides a way to separate the first two from the last.
    Is this what --no-npm and --no-git are designed for?

  8. lock commented on Dec 27, 2018

    @lock

    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.

  9. locked as resolved and limited conversation to collaborators on Dec 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions