Release it!

Automate versioning and package publishing-related tasks

README

Release It! 🚀


🚀 Generic CLI tool to automate versioning and package publishing-related tasks:

- Bump version (in e.g. package.json)
- [Git commit, tag, push][1]
- Execute any (test or build) commands using [hooks][2]
- [Create release at GitHub][3] or [GitLab][4]
- [Generate changelog][5]
- [Publish to npm][6]
- [Manage pre-releases][7]
- Extend with [plugins][8]
- Release from any [CI/CD environment][9]

Use release-it for version management and publish to anywhere with its versatile configuration, a powerful plugin
system, and hooks to execute any command you need to test, build, and/or publish your project.

[![Action Status][11]][10] [![npm version][13]][12]

Installation


Although release-it is a generic release tool, most projects use it for projects with npm packages. The recommended
way to install release-it uses npm and adds some minimal configuration to get started:

  1. ```bash
  2. npm init release-it
  3. ```

Alternatively, install it manually, and add the release script to package.json:

  1. ```bash
  2. npm install -D release-it
  3. ```

  1. ```json
  2. {
  3.   "name": "my-package",
  4.   "version": "1.0.0",
  5.   "scripts": {
  6.     "release": "release-it"
  7.   },
  8.   "devDependencies": {
  9.     "release-it": "^15.10.0"
  10.   }
  11. }
  12. ```

Usage


Run release-it from the root of the project using either npm run or npx:

  1. ```bash
  2. npm run release
  3. npx release-it
  4. ```

You will be prompted to select the new version, and more prompts will follow based on your configuration.

Experimental: knowledge base


You might want to ask your questions in the [Release It! knowledge base][14] (powered by OpenAI and [7-docs][15]). This
is an experimental knowledge base, answers may be incorrect.

Yarn


Using Yarn? Please see the [npm section on Yarn][16].

Monorepos


Using a monorepo? Please see this [monorepo recipe][17].

Global Installation


Per-project installation as shown above is recommended, but global installs are supported as well:

- From npm: npm install -g release-it
- From Homebrew: brew install release-it

Videos, articles & examples


Here's a list of interesting external resources:

- Video: [How to use GitHub Actions & Release-It to Easily Release Your Code][18]
- Article: [Monorepo Semantic Releases][19] ([repo][20])

Want to add yours to the list? Just open a pull request!

Configuration


Out of the box, release-it has sane defaults, and [plenty of options][21] to configure it. Most projects use a
.release-it.json file in the project root, or a release-it property in package.json.

Here's a quick example .release-it.json:

  1. ```json
  2. {
  3.   "git": {
  4.     "commitMessage": "chore: release v${version}"
  5.   },
  6.   "github": {
  7.     "release": true
  8.   }
  9. }
  10. ```

→ See [Configuration][22] for more details.

Interactive vs. CI mode


By default, release-it is interactive and allows you to confirm each task before execution:


By using the --ci option, the process is fully automated without prompts. The configured tasks will be executed as
demonstrated in the first animation above. In a Continuous Integration (CI) environment, this non-interactive mode is
activated automatically.

Use --only-version to use a prompt only to determine the version, and automate the rest.

Latest version


How does release-it determine the latest version?

1.  For projects with a package.json, its version will be used (see [npm][23] to skip this).
2.  Otherwise, release-it uses the latest Git tag to determine which version should be released.
3.  As a last resort, 0.0.0 will be used as the latest version.

Alternatively, a plugin can be used to override this (e.g. to manage a VERSION or composer.json file):

- [@release-it/bumper][24] to read from or bump the version in any file
- [@release-it/conventional-changelog][25] to get a recommended bump based on commit messages
- [release-it-calver-plugin][26] to use CalVer (Calendar Versioning)

Add the --release-version flag to print the next version without releasing anything.

Git


Git projects are supported well by release-it, automating the tasks to stage, commit, tag and push releases to any Git
remote.

→ See [Git][27] for more details.

GitHub Releases


GitHub projects can have releases attached to Git tags, containing release notes and assets. There are two ways to add
[GitHub releases][28] in your release-it flow:

1.  Automated (requires a GITHUB_TOKEN)
2.  Manual (using the GitHub web interface with pre-populated fields)

→ See [GitHub Releases][29] for more details.

GitLab Releases


GitLab projects can have releases attached to Git tags, containing release notes and assets. To automate [GitLab
releases][30]:

- Configure gitlab.release: true
- Obtain a [personal access token][31] (release-it only needs the "api" scope).
- Make sure the token is [available as an environment variable][32].

→ See [GitLab Releases][33] for more details.

Changelog


By default, release-it generates a changelog, to show and help select a version for the new release. Additionally, this
changelog serves as the release notes for the GitHub or GitLab release.

The [default command][21] is based on git log .... This setting (git.changelog) can be overridden. To further
customize the release notes for the GitHub or GitLab release, there's github.releaseNotes or gitlab.releaseNotes.
Make sure any of these commands output the changelog to stdout. Note that release-it by default is agnostic to commit
message conventions. Plugins are available for:

- GitHub and GitLab Releases
- auto-changelog
- Conventional Changelog
- Keep A Changelog

To print the changelog without releasing anything, add the --changelog flag.

→ See [Changelog][34] for more details.

Publish to npm


With a package.json in the current directory, release-it will let npm bump the version in package.json (and
package-lock.json if present), and publish to the npm registry.

→ See [Publish to npm][23] for more details.

Manage pre-releases


With release-it, it's easy to create pre-releases: a version of your software that you want to make available, while
it's not in the stable semver range yet. Often "alpha", "beta", and "rc" (release candidate) are used as identifiers for
pre-releases. An example pre-release version is 2.0.0-beta.0.

→ See [Manage pre-releases][35] for more details.

Update or re-run existing releases


Use --no-increment to not increment the last version, but update the last existing tag/version.

This may be helpful in cases where the version was already incremented. Here are a few example scenarios:

- To update or publish a (draft) GitHub Release for an existing Git tag.
- Publishing to npm succeeded, but pushing the Git tag to the remote failed. Then use
  release-it --no-increment --no-npm to skip the npm publish and try pushing the same Git tag again.

Hooks


Use script hooks to run shell commands at any moment during the release process (such as before:init or
after:release).

The format is [prefix]:[hook] or [prefix]:[plugin]:[hook]:

partvalue
-------------------------------------------------
prefix`before`
plugin`version`,
hook`init`,

Use the optional :plugin part in the middle to hook into a life cycle method exactly before or after any plugin.

The core plugins include version, git, npm, github, gitlab.

Note that hooks like after:git:release will not run when either the git push failed, or when it is configured not to
be executed (e.g. git.push: false). See [execution order][36] for more details on execution order of plugin lifecycle
methods.

All commands can use configuration variables (like template strings). An array of commands can also be provided, they
will run one after another. Some example release-it configuration:

  1. ```json
  2. {
  3.   "hooks": {
  4.     "before:init": ["npm run lint", "npm test"],
  5.     "after:my-plugin:bump": "./bin/my-script.sh",
  6.     "after:bump": "npm run build",
  7.     "after:git:release": "echo After git push, before github release",
  8.     "after:release": "echo Successfully released ${name} v${version} to ${repo.repository}."
  9.   }
  10. }
  11. ```

The variables can be found in the [default configuration][21]. Additionally, the following variables are exposed:

  1. ```text
  2. version
  3. latestVersion
  4. changelog
  5. name
  6. repo.remote, repo.protocol, repo.host, repo.owner, repo.repository, repo.project
  7. branchName
  8. ```

All variables are available in all hooks. The only exception is that the additional variables listed above are not yet
available in the init hook.

Use --verbose to log the output of the commands.

For the sake of verbosity, the full list of hooks is actually: init, beforeBump, bump, beforeRelease, release
or afterRelease. However, hooks like before:beforeRelease look weird and are usually not useful in practice.

Note that arguments need to be quoted properly when used from the command line:

  1. ```bash
  2. release-it --'hooks.after:release="echo Successfully released ${name} v${version} to ${repo.repository}."'
  3. ```

Using Inquirer.js inside custom hook scripts might cause issues (since release-it also uses this itself).