Git Product home page Git Product logo

nlm's Introduction

nlm

A tool for automating the release of libraries in the spirit of semantic-release.

Highlights

  • Automatically tags pull requests with semver-{patch,minor,major,none} based on the commit history
  • All information is also part of the git history
  • Smart CHANGELOG.md generator that incorporates pull request data
  • Adds license headers for JavaScript and CoffeeScript files

Getting Started

Prerequisites

  1. A Github access token with repo scope. This is required for creating version commits, releases, and tagging issues. Github has a instructions for creating an access token.
  2. A valid repository field in your package.json. E.g. https://github.mycorp.net/myorg/repo.git or https://github.com/myorg/repo.git.
  3. The repository field should point to an existing project on Github.

Install nlm

  1. Run npm install --save-dev nlm.
  2. Enter the Github token when prompted. This will be used to create the required labels on the repository.
  3. nlm will offer to write the proper posttest script if your repository doesn't contain one yet. It will also write a publishConfig.registry field, defaulting to your current npm registry setting.

After this you should have nlm release in your posttest script and 4 semver-* labels in your Github project.

Setting up CI

nlm will automatically look for well-known environment variables during CI builds like CI=true, BRANCH=branch-name, etc.. It should work out-of-the-box for both Travis and DotCI.

For Github and npm interactions to work, it requires the following additional environment variables:

  • GH_TOKEN: The access token from above.
  • NPM_TOKEN: An npm access token. You can find this in ~/.npmrc as _authToken.

For registries that don't support _authToken, it's possible to configure NPM_USERNAME, NPM_EMAIL, and NPM_PASSWORD_BASE64 instead. Those values can be found in your ~/.npmrc as username, email, and _password.

All tokens and passwords should be set up as encrypted environment variables.

Travis

For Travis you can follow the official Travis docs:

travis encrypt GH_TOKEN=your_github_token --add env

If you want to publish from CI, you can either use the official Travis feature or nlm itself. The latter gives you support for managing different dist-tags based on branches.

If you want to use nlm to publish, you'll have to add NPM_TOKEN:

travis encrypt NPM_TOKEN=your_npm_token --add env

DotCI

DotCI lacks native support for encrypted environment variables. But the EnvInject Plugin provides an option called "Inject passwords to the build as environment variables" which can fill the same role.

You should also enable builds of pull requests for pushes against the same repository. Otherwise the automated tagging of PRs won't work.

Finally enable publishing by adding the following to .ci.yml:

build:
  <% if (DOTCI_BRANCH == 'master') { %>
  after:
    - ./node_modules/.bin/nlm publish
  <% } %>

Configuration

Most nlm configuration happens via native npm options in package.json:

  • repository: This field is parsed to detect Github API baseUrl and repository name. nlm supports both public Github and Github Enterprise instances. For Github Enterprise, it assumes the API to be at https://<hostname>/api/v3.
  • files: By default nlm will add license headers to everything listed here.

In most cases these settings are enough to make nlm do the right thing. For more customization, you can use .nlmrc or an nlm section in package.json:

  • channels: A map of branch name to npm dist-tag. When publishing, this will determine what will be published and how it's tagged. By default there's one entry in this map: { master: 'latest' }. Which means that a publish from master updates the latest tag and publish from any other branch does nothing.
  • license.files: List of files and/or directories to add license headers to.
  • license.exclude: List of files to exclude that would otherwise be included. nlm will always exclude anything in node_modules.

If there's no file named LICENSE in the repository, nlm won't attempt to add the headers.

Commands

nlm init

Intended use: Run once in a project.

Parses an existing package.json and makes changes to support nlm.

  1. Ask for a Github API token.
  2. Add the semver-patch, semver-minor, and semver-major labels.
  3. Add nlm release as a posttest script.
  4. Set publishConfig.registry (default: read from npm config).

nlm verify

Intended use: posttest script for matrix builds.

Verify that the current state is valid and could be released. Will also add license headers where they are missing.

  1. Add missing license headers.
  2. Verify that the checkout is clean.
  3. Collect change log items and determine what kind of change it is.

nlm release

Intended use: deploy script, or posttest script if not running matrix builds.

Verify that the current state is valid and could be released. Will also add license headers where they are missing.

  1. Everything nlm verify does.
  2. If there are unreleased changes:
  3. Create a new CHANGELOG entry and update package.json#version.
  4. Commit and tag the release.
  5. Push the tag and the release branch (e.g. master).
  6. Create a Github release.
  7. Publish the package to npm or update dist-tag if required.

By default nlm release will not do anything unless it's running on CI. You can force a release by running nlm release --commit.

nlm changelog

Preview the changelog that would be generated by the commits between the last version tag and the current HEAD. If there are no unreleased commits, the output will be empty.

nlm's People

Contributors

jkrems avatar i-tier-bot avatar

Watchers

Shyamal Suhana Chandra avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.