UNPKG

20.9 kBMarkdownView Raw
1# Release It! 🚀
2
3CLI release tool for Git repos and npm packages.
4
5**Release It!** automates the tedious tasks of software releases:
6
7<img align="right" src="./assets/release-it.gif?raw=true" height="170">
8
9- Execute test & build commands
10- Bump version (in e.g. `package.json`)
11- Git commit, tag, push
12- [Create release at GitHub](#github-releases) (and [upload assets](#release-assets))
13- [Create release at GitLab](#gitlab-releases) (and [upload assets](#release-assets))
14- [Generate changelog](#changelogs)
15- [Publish to npm](#publish-to-npm)
16- [Manage pre-releases](#manage-pre-releases)
17- [Script Hooks](#scripts)
18- Extend with [plugins](#plugins)
19- Release from any [CI/CD environment](./docs/ci.md)
20
21[![Build Status](https://travis-ci.org/release-it/release-it.svg?branch=master)](https://travis-ci.org/release-it/release-it)
22[![npm version](https://badge.fury.io/js/release-it.svg)](https://badge.fury.io/js/release-it)
23[![codecov](https://codecov.io/gh/release-it/release-it/branch/master/graph/badge.svg)](https://codecov.io/gh/release-it/release-it)
24
25## Links
26
27- **NEW**: [release-it supports plugins](https://github.com/release-it/release-it/issues/501) (since v11), so virtually
28 any functionality can be added to your release process.
29- For **updates**, see [CHANGELOG.md](CHANGELOG.md) for major updates, and
30 [releases](https://github.com/release-it/release-it/releases) for a detailed version history.
31- To **contribute**, please read [CONTRIBUTING.md](CONTRIBUTING.md) first.
32- Please [open an issue](https://github.com/release-it/release-it/issues/new) if anything is missing or unclear in this
33 documentation.
34
35<details>
36 <summary><strong>Table of Contents</strong> (click to expand)</summary>
37
38<!-- toc -->
39
40- [Installation](#installation)
41- [Usage](#usage)
42- [Configuration](#configuration)
43- [Interactive vs. CI mode](#interactive-vs-ci-mode)
44- [Latest version](#latest-version)
45- [Prerequisite checks](#prerequisite-checks)
46- [Git](#git)
47- [GitHub Releases](#github-releases)
48- [GitLab Releases](#gitlab-releases)
49- [Changelogs](#changelogs)
50- [Publish to npm](#publish-to-npm)
51- [Manage pre-releases](#manage-pre-releases)
52- [Scripts](#scripts)
53- [Plugins](#plugins)
54- [Distribution repository](#distribution-repository)
55- [Metrics](#metrics)
56- [Troubleshooting & debugging](#troubleshooting--debugging)
57- [Use release-it programmatically](#use-release-it-programmatically)
58- [Example projects using release-it](#example-projects-using-release-it)
59- [Resources](#resources)
60- [Credits](#credits)
61
62<!-- tocstop -->
63
64</details>
65
66## Installation
67
68### Global
69
70As a globally available CLI command:
71
72```bash
73npm install --global release-it
74```
75
76### Local
77
78As a `devDependency` in your project:
79
80```
81npm install --save-dev release-it
82```
83
84Add this as a `script` to `package.json`:
85
86```json
87{
88 "name": "my-package",
89 "version": "1.0.0",
90 "scripts": {
91 "release": "release-it"
92 },
93 "devDependencies": {
94 "release-it": "*"
95 }
96}
97```
98
99Now you can run `npm run release` from the command line (any release-it arguments behind the `--`):
100
101```
102npm run release
103npm run release -- minor --ci
104```
105
106## Usage
107
108Release a new version:
109
110```bash
111release-it
112```
113
114You will be prompted to select the new version. To skip the first prompt, provide a specific increment or version:
115
116```bash
117release-it minor
118release-it 0.8.3
119```
120
121For a "dry run", to show the interactivity and the commands it _would_ execute:
122
123```bash
124release-it --dry-run
125```
126
127Note: read-only commands are still executed (`$ ...`), while the rest is not (`! ...`):
128
129```
130$ git rev-parse --git-dir
131.git
132! git add package.json
133! git commit --message="Release 0.8.3"
134```
135
136## Configuration
137
138Out of the box, release-it has sane defaults, and [plenty of options](conf/release-it.json) to configure it. Put the
139options to override in `.release-it.json` in the project root. Example:
140
141```json
142{
143 "git": {
144 "tagName": "v${version}"
145 },
146 "github": {
147 "release": true
148 }
149}
150```
151
152Or in a `release-it` property in `package.json`:
153
154```json
155{
156 "name": "my-package",
157 "devDependencies": {
158 "release-it": "*"
159 },
160 "release-it": {
161 "github": {
162 "release": true
163 }
164 }
165}
166```
167
168Notes:
169
170- Only the settings to override need to be in `.release-it.json` (or `package.json`). Everything else will fall back to
171 the [default configuration](conf/release-it.json).
172- You can use `--config` if you want to use another path for `.release-it.json`.
173- You can also export the configuration object from a custom script (e.g `--config release-it.js`).
174
175Any option can also be set on the command-line, and will have highest priority. Example:
176
177```bash
178release-it minor --git.tagName='v${version}' --github.release
179```
180
181Boolean arguments can be negated by using the `no-` prefix:
182
183```bash
184release-it --no-npm.publish
185```
186
187## Interactive vs. CI mode
188
189By default, release-it is **interactive** and allows you to confirm each task before execution:
190
191<img src="./assets/release-it-interactive.gif?raw=true" height="290">
192
193By using the `--ci` option, the process is fully automated without prompts. The configured tasks will be executed as
194demonstrated in the first animation above. On a Continuous Integration (CI) environment, this non-interactive mode is
195activated automatically.
196
197Note: the old `-n` (or `--non-interactive`) option still works and is identical to `--ci`.
198
199## Latest version
200
201For projects with a `package.json`, its `version` will be used. Otherwise, release-it uses the latest Git tag to
202determine which version should be released. In any case, as a last resort, `0.0.0` will be used as the latest version.
203
204Use `--no-npm` (or `"npm": false`) to ignore and skip bumping `package.json` (and skip `npm publish`).
205
206Alternatively, a plugin can be used to get the version from anywhere else. Also see [plugins](docs/plugins/README.md).
207
208## Prerequisite checks
209
210Read more about [prerequisites checks](./docs/prerequisites.md) release-it does to help prevent incorrect or polluted
211releases.
212
213## Git
214
215### SSH keys & Git remotes
216
217SSH keys and Git remotes are assumed to be configured correctly. If a manual `git push` from the command line works,
218release-it should be able to do the same.
219
220The following help pages might be useful: [SSH](https://help.github.com/articles/connecting-to-github-with-ssh/) and
221[Managing Remotes](https://help.github.com/categories/managing-remotes/) (GitHub),
222[SSH keys](https://confluence.atlassian.com/bitbucket/ssh-keys-935365775.html) (Bitbucket),
223[SSH keys](https://gitlab.com/help/ssh/README.md) (GitLab).
224
225### Remote repository
226
227By default, `release-it` uses `origin` as the remote name to push to. Use `git.pushRepo` to override this with a
228different remote name (or a different git url).
229
230### Extra arguments
231
232In case extra arguments should be provided to Git, these options are available:
233
234- `git.commitArgs`
235- `git.tagArgs`
236- `git.pushArgs`
237
238For example, use `"git.commitArgs": "-S"` to sign commits (also see
239[#35](https://github.com/release-it/release-it/issues/350)).
240
241### Skip Git steps
242
243To skip the Git steps (commit, tag, push) entirely (e.g. to only `npm publish`), use the shorthand:
244
245```
246release-it --no-git
247```
248
249Use e.g. `git.tag: false` or `--no-git.tag` to skip a single step.
250
251### Untracked files
252
253By default, untracked files are not added to the release commit. Use `git.addUntrackedFiles: true` to override this
254behavior.
255
256## GitHub Releases
257
258The "Releases" tab on GitHub projects links to a page to store the changelog. To add
259[GitHub releases](https://help.github.com/articles/creating-releases/) in your release-it flow:
260
261- Configure `github.release: true`.
262- Obtain a [personal access token](https://github.com/settings/tokens) (release-it only needs "repo" access; no "admin"
263 or other scopes).
264- Make sure the token is available as an environment variable. Example:
265
266```bash
267export GITHUB_TOKEN="f941e0..."
268```
269
270Do not put the actual token in the release-it configuration. It will be read from the `GITHUB_TOKEN` environment
271variable. You can change this variable name by setting the `github.tokenRef` option to something else.
272
273Obviously, release-it uses this feature extensively:
274[release-it's releases page](https://github.com/release-it/release-it/releases).
275
276### Release notes
277
278By default, the output of `git.changelog` is used for the GitHub release notes. This is the printed `Changelog: ...`
279when release-it boots. Override this with the `github.releaseNotes` option. This script will run just before the actual
280GitHub release itself. Make sure it outputs to `stdout`. An example:
281
282```
283{
284 "github": {
285 "release": true,
286 "releaseNotes": "generate-release-notes.sh ${latestVersion} ${version}"
287 }
288}
289```
290
291### Release assets
292
293To upload binary release assets with a GitHub release (such as compiled executables, minified scripts, documentation),
294provide one or more glob patterns for the `github.assets` option. After the release, the assets are available to
295download from the GitHub release page. Example:
296
297```json
298{
299 "github": {
300 "release": true,
301 "assets": ["dist/*.zip"]
302 }
303}
304```
305
306## GitLab Releases
307
308[GitLab releases](https://docs.gitlab.com/ee/workflow/releases.html#releases) work just like GitHub releases:
309
310- Configure `gitlab.release: true`.
311- Obtain a [personal access token](https://gitlab.com/profile/personal_access_tokens) (release-it only needs the "api"
312 scope).
313- Make sure the token is available as an environment variable. Example:
314
315```bash
316export GITLAB_TOKEN="f941e0..."
317```
318
319The output of `git.changelog` (or `gitlab.releaseNotes` if set) will be attached to the latest tag.
320
321GitLab 11.7 introduces [Releases](https://docs.gitlab.com/ce/user/project/releases.html) to create release entries (much
322like GitHub), including release assets. For GitLab 11.6 and lower, release-it will automatically fall back to
323[attach releases notes to a tag](https://docs.gitlab.com/ce/workflow/releases.html). In this case, assets will not get
324included.
325
326Uploading assets work just like [GitHub Release assets](#release-assets), e.g. `--gitlab.assets=*.dmg`.
327
328## Changelogs
329
330By default, release-it generates a changelog, to show and help select a version for the new release. Additionally, this
331changelog serves as the release notes for the GitHub or GitLab release.
332
333The [default command](conf/release-it.json) is based on `git log ...`. This setting (`git.changelog`) can be overridden.
334To customize the release notes for the GitHub or GitLab release, use `github.releaseNotes` or `gitlab.releaseNotes`.
335Make sure any of these commands output the changelog to `stdout`.
336
337Instead of executing a shell command, a (Handlebars) template can be used to generate the changelog. See
338[auto-changelog](#auto-changelog) below for more details.
339
340Some projects keep their changelog in e.g. `CHANGELOG.md` or `history.md`. To auto-update this file with the release,
341the recommended configuration is to use a command that does this in `scripts.beforeStage`. See below for examples and
342workflows.
343
344### Auto-changelog
345
346A tool like [auto-changelog](https://github.com/CookPete/auto-changelog) is a great companion to release-it:
347
348```json
349{
350 "git": {
351 "changelog": "npx auto-changelog --stdout --commit-limit false -u --template ./changelog.hbs"
352 },
353 "scripts": {
354 "beforeStage": "npx auto-changelog -p"
355 }
356}
357```
358
359With this `git.changelog`, the changelog preview is based on the `changelog.hbs` template file. This would be used for
360[GitHub](#github-releases) or [GitLab releases](#gitlab-releases) as well.
361
362Additionally, `scripts.beforeStage` will update the `CHANGELOG.md` with each release to get included with the release
363commit. This can be omitted if the project does not keep a `CHANGELOG.md` or similar.
364
365See the [auto-changelog recipe](docs/recipes/auto-changelog.md) for an example setup and template.
366
367### Conventional Changelog
368
369If your project follows conventions, such as the
370[Angular commit guidelines](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#commits), the
371`@release-it/conventional-changelog` plugin is useful.
372
373```bash
374npm install @release-it/conventional-changelog --save-dev
375```
376
377Use this plugin to get the recommended bump based on the commit messages, generate a conventional changelog, and update
378the `CHANGELOG.md` file:
379
380```json
381{
382 "plugins": {
383 "@release-it/conventional-changelog": {
384 "preset": "angular",
385 "infile": "CHANGELOG.md"
386 }
387 }
388}
389```
390
391- Omit the `infile` at will. If set, but the file does not exist yet, it's created with the full history.
392- Please find the
393 [list of available presets](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages)
394 (`angular`, `ember`, etc).
395- The options are sent verbatim to
396 [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog/README.md).
397
398## Publish to npm
399
400With a `package.json` in the current directory, release-it will let `npm` bump the version in `package.json` (and
401`package-lock.json` if present), and publish to the npm registry.
402
403### Tags
404
405Use e.g. `--npm.tag=beta` to tag the package in the npm repository. With the `--preRelease=beta` shorthand, the npm
406dist-tag will have the same value (unless `--npm.tag` is used to override this). The default tag is "latest".
407
408For a pre-release, the default tag is "next". The tag will be derived from the pre-release version (e.g. version
409`2.0.0-alpha.3` will result in tag "alpha"), unless overridden by setting `npm.tag`.
410
411### Public scoped packages
412
413A [scoped package](https://docs.npmjs.com/misc/plugin) (e.g. `@user/package`) is either public or private. To
414[publish scoped packages](https://docs.npmjs.com/misc/plugin#publishing-scoped-packages), make sure this is in
415`package.json`:
416
417```json
418{
419 "publishConfig": {
420 "access": "public"
421 }
422}
423```
424
425By default, `npm publish` will
426[publish a scoped package as private](https://docs.npmjs.com/creating-and-publishing-private-packages) (requires paid
427account).
428
429### Two-factor authentication
430
431In case two-factor authentication (2FA) is enabled for the package, release-it will ask for the one-time password (OTP).
432
433The OTP can be provided from the command line (`--npm.otp=123456`). However, providing the OTP without a prompt
434basically defeats the purpose of 2FA (also, the OTP expires after a short period).
435
436### Monorepos
437
438Monorepos do not require extra configuration, but release-it handles only one package at a time. Also see how
439[Git steps can be skipped](#skip-git-steps) (e.g. if tagging the Git repo should be skipped).
440
441### Misc.
442
443- Learn how to [authenticate and publish from a CI/CD environment](./docs/ci.md#npm).
444- The `"private": true` setting in package.json will be respected, and `release-it` will skip this step.
445- Getting an `ENEEDAUTH` error while a manual `npm publish` works? Please see
446 [#95](https://github.com/release-it/release-it/issues/95#issuecomment-344919384).
447
448## Manage pre-releases
449
450With release-it, it's easy to create pre-releases: a version of your software that you want to make available, while
451it's not in the stable semver range yet. Often "alpha", "beta", and "rc" (release candidate) are used as identifier for
452pre-releases.
453
454An example. The `awesome-pkg` is at version 1.3.0, and work is done for a new major update. To publish the latest beta
455of the new major version:
456
457```
458release-it major --preRelease=beta
459```
460
461This will tag and release version `2.0.0-beta.0`. Notes:
462
463- A normal installation of `awesome-pkg` will still be at version 1.3.0.
464- The [npm tag](https://docs.npmjs.com/cli/dist-tag) will be "beta", install it using `npm install awesome-pkg@beta`
465- A GitHub release will be marked as a "Pre-release".
466
467The above command is actually a shortcut for:
468
469```
470release-it premajor --preReleaseId=beta --npm.tag=beta --github.preRelease
471```
472
473Consecutive beta releases (`2.0.0-beta.1` and so on):
474
475```
476release-it --preRelease
477```
478
479And when ready to release the next phase (e.g. release candidate, in this case `2.0.0-rc.0`):
480
481```
482release-it --preRelease=rc
483```
484
485And eventually, for `2.0.0`:
486
487```
488release-it major
489```
490
491<img src="./assets/release-it-prerelease.gif?raw=true" height="524">
492
493Notes:
494
495- Pre-releases work in tandem with [recommended bumps](#recommended-bump).
496- You can still override individual options, e.g. `release-it --preRelease=rc --npm.tag=next`.
497- See [semver.org](http://semver.org) for more details about semantic versioning.
498
499## Scripts
500
501These script hooks can be used to execute commands (from the root directory of the repository):
502
503- `scripts.beforeStart`
504- `scripts.beforeBump`
505- `scripts.afterBump`
506- `scripts.beforeStage`
507- `scripts.afterRelease`
508
509All commands can use configuration variables (like template strings). An array of commands can also be provided, they
510will run one after another. Some examples:
511
512```json
513{
514 "scripts": {
515 "beforeStart": ["npm run lint", "npm test"],
516 "afterBump": "tar -czvf foo-${version}.tar.gz",
517 "afterRelease": "echo Successfully released ${name} v${version} to ${repo.repository}."
518 }
519}
520```
521
522The variables can be found in the [default configuration](conf/release-it.json). Additionally, the following variables
523are exposed:
524
525```
526version
527latestVersion
528changelog
529name
530repo.remote, repo.protocol, repo.host, repo.owner, repo.repository, repo.project
531```
532
533## Plugins
534
535Since v11, release-it can be extended in many, many ways. Please head over to [plugins](docs/plugins/README.md) for more
536details.
537
538## Distribution repository
539
540Some projects use a distribution repository. Generated files (such as compiled assets or documentation) can be
541distributed to a separate repository. Or to a separate branch, such as a `gh-pages`. Some examples include
542[shim repositories](https://github.com/components) and a separate
543[packaged Angular.js repository](https://github.com/angular/bower-angular) for distribution on npm and Bower.
544
545The `dist.repo` option was removed in v10, but similar setups can still be achieved. Please see the
546[distribution repository](docs/recipes/distribution-repo.md) recipe for example configurations.
547
548## Metrics
549
550Use `--disable-metrics` to opt-out of sending some anonymous statistical data to Google Analytics. For details, refer to
551[lib/metrics.js](lib/metrics.js). Please consider to not opt-out: more data means more support for future development.
552
553## Troubleshooting & debugging
554
555- With `release-it --verbose`, release-it prints every command and its output.
556- Prepend `DEBUG=release-it:* release-it [...]` to print configuration and more error details.
557- Use `DEBUG=* release-it [...]` to include debug output for dependencies, such as
558 [@octokit/rest](https://github.com/octokit/rest.js).
559
560## Use release-it programmatically
561
562While mostly used as a CLI tool, release-it can be used as a dependency to ingrate in your own scripts. See
563[use release-it programmatically](docs/recipes/programmatic.md) for example code.
564
565## Example projects using release-it
566
567- [react-navigation/react-navigation](https://github.com/react-navigation/react-navigation)
568- [swagger-api/swagger-ui](https://github.com/swagger-api/swagger-ui)
569- [StevenBlack/hosts](https://github.com/StevenBlack/hosts)
570- [react-native-community/react-native-tab-view](https://github.com/react-native-community/react-native-tab-view)
571- [callstack/linaria](https://github.com/callstack/linaria)
572- [blockchain/blockchain-wallet-v4-frontend](https://github.com/blockchain/blockchain-wallet-v4-frontend)
573- [infor-design/enterprise](https://github.com/infor-design/enterprise)
574- [tsqllint/tsqllint](https://github.com/tsqllint/tsqllint)
575- [segmentio/typewriter](https://github.com/segmentio/typewriter)
576- [Repositories that depend on release-it](https://github.com/release-it/release-it/network/dependents)
577- GitHub search for
578 [projects with .release-it.json](https://github.com/search?o=desc&q=in%3Apath+.release-it.json&s=indexed&type=Code)
579
580## Resources
581
582- [semver.org](http://semver.org)
583- [GitHub Help](https://help.github.com) (→ [About Releases](https://help.github.com/articles/about-releases/))
584- [npm Blog: Publishing what you mean to publish](https://blog.npmjs.org/post/165769683050/publishing-what-you-mean-to-publish)
585- [npm Documentation: package.json](https://docs.npmjs.com/files/package.json)
586- [Prereleases and npm](https://medium.com/@mbostock/prereleases-and-npm-e778fc5e2420)
587- [Glob Primer (node-glob)](https://github.com/isaacs/node-glob#glob-primer) (release-it uses
588 [globby](https://github.com/sindresorhus/globby#readme))
589
590## Credits
591
592Major dependencies:
593
594- [ShellJS](https://documentup.com/shelljs/shelljs)
595- [Inquirer.js](https://github.com/SBoudrias/Inquirer.js)
596- [@octokit/rest](https://github.com/octokit/rest.js)
597
598The following Grunt plugins have been a source of inspiration:
599
600- [grunt-release](https://github.com/geddski/grunt-release)
601- [grunt-release-component](https://github.com/walmartlabs/grunt-release-component)