UNPKG

18.3 kBMarkdownView Raw
1# :package::rocket: semantic-release
2
3**fully automated package publishing**
4
5> **Trust us, this will change your workflow for the better.**
6
7> – [egghead.io](https://egghead.io/lessons/javascript-how-to-write-a-javascript-library-automating-releases-with-semantic-release)
8
9[![Join the chat at https://gitter.im/semantic-release/semantic-release](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/semantic-release/semantic-release?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
10[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
11[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)
12[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
13
14[![Dependency Status](https://david-dm.org/semantic-release/semantic-release/caribou.svg)](https://david-dm.org/semantic-release/semantic-release/caribou)
15[![devDependency Status](https://david-dm.org/semantic-release/semantic-release/caribou/dev-status.svg)](https://david-dm.org/semantic-release/semantic-release/caribou#info=devDependencies)
16
17[![Build Status](https://travis-ci.org/semantic-release/semantic-release.svg?branch=caribou)](https://travis-ci.org/semantic-release/semantic-release)
18[![Coverage Status](https://coveralls.io/repos/semantic-release/semantic-release/badge.svg?branch=caribou&service=github)](https://coveralls.io/github/semantic-release/semantic-release?branch=caribou)
19
20Out of the box this is just about _commit-messages_, but you can do so much more.
21
22* **Detect breaking changes** using the test suite of your last release: [cracks](https://github.com/semantic-release/cracks)
23* Detect breaking changes using your dependents’ test suites: [Help out! Implement the **dont-break** plugin](https://github.com/semantic-release/semantic-release/issues/65)
24* Detect breaking changes diffing your JSDoc interface: [Help out! Implement the **india** plugin](https://github.com/semantic-release/semantic-release/issues/66)
25* Abort releases with **insufficient test coverage**: [Help out! Implement the **istanbul** plugin](https://github.com/semantic-release/semantic-release/issues/68)
26* Abort releases with **vulnerable dependencies** in the tree: [Help out! Implement the **nsp** plugin](https://github.com/semantic-release/semantic-release/issues/67)
27* Everything you can imagine: [Build Plugins!](https://github.com/semantic-release/semantic-release#plugins)
28
29  | Commands | Comment
30--- | --- | ---
31| **manual/before** | <pre><code><div>npm version major</div><div>git push origin master --tags</div><div>npm publish</div></code></pre> | You **manually decide** what the **next version** is. You have to remember what major, minor and patch means. You have to remember to push both commits and tags. You have to wait for the CI to pass. |
32| **semantic-release/after** | <pre><code><div>git commit -m "fix: &lt;message&gt;"</div><div>git push</div></code></pre> | You **describe the changes** you’ve made. A new version is automatically published with the correct version number.
33
34This removes the immediate connection between human emotions and version numbers, so strictly following the [SemVer](http://semver.org/) spec is not a problem anymore – and that’s ultimately `semantic-release`’s goal.
35
36<table>
37 <tr>
38 <th colspan="2">
39 “How to Write a JavaScript Library - Automating Releases with semantic-release” – egghead.io
40 </th>
41 </tr>
42 <tr>
43 <td colspan="2">
44 <a href="https://egghead.io/lessons/javascript-how-to-write-a-javascript-library-automating-releases-with-semantic-release"><img src="https://cloud.githubusercontent.com/assets/908178/9730739/7b1da5d8-5610-11e5-88b6-5c75fdda7ee2.png" alt="egghead.io session"></a>
45 </td>
46 </tr>
47 <tr>
48 <td colspan="2">
49 A free egghead.io tutorial series on how to write an open source library featuring semantic-release.
50 </td>
51 </tr>
52 <tr>
53 <th>
54 “We fail to follow SemVer – and why it needn’t matter”
55 </th>
56 <th>
57 “semantic-release Q&A with Kent C. Dodds”
58 </th>
59 </tr>
60 <tr>
61 <td>
62 <a href="https://www.youtube.com/watch?v=tc2UgG5L7WM&amp;index=6&amp;list=PLFZ5NyC0xHDaaTy6tY9p0C0jd_rRRl5Zm"><img alt="JSConfBP Talk" src="https://cloud.githubusercontent.com/assets/908178/9428178/c337ed26-49a2-11e5-8ad0-a602500a65bf.png"></a>
63 </td>
64 <td>
65 <a href="https://www.youtube.com/watch?v=g6y3DnhkjrI"><img alt="Hangout on Air with Kent C. Dodds" src="https://cloud.githubusercontent.com/assets/908178/9428179/c3387318-49a2-11e5-9f5f-dccd3fbb0c1d.png"></a>
66 </td>
67 </tr>
68 <tr>
69 <td>
70 This talk gives you a complete introduction to the underlying concepts of this module. 38:30
71 </td>
72 <td>
73 A “Hangouts on Air” conversation with hands on questions and answers about how to use semantic-release. 53:52
74 </td>
75 </tr>
76</table>
77
78## How does it work?
79
80Instead of writing [meaningless commit messages](http://whatthecommit.com/), we can take our time to think about the changes in the codebase and write them down. Following formalized conventions it is then possible to generate a helpful changelog and to derive the next semantic version number from them.
81
82When `semantic-release` is setup it will do that after every successful continuous integration build of your master branch (or any other branch you specify) and publish the new version for you. This way no human is directly involved in the release process and your releases are guaranteed to be [unromantic and unsentimental](http://sentimentalversioning.org/).
83
84If you fear the loss of control over timing and marketing implications of software releases you should know that `semantic-release` supports [release channels](https://github.com/npm/npm/issues/2718) using `npm`’s [dist-tags](https://docs.npmjs.com/cli/dist-tag). This way you can keep control over what your users end up using by default, you can decide when to promote an automatically released version to the stable channel, and you can choose which versions to write blogposts and tweets about. You can use the same mechanism to [support older versions of your software](https://gist.github.com/boennemann/54042374e49c7ade8910), for example with important security fixes.
85
86This is what happens in series:
87
88| 1. `git push` | 2. `semantic-release pre` | 3. `npm publish` | 4. `semantic-release post` |
89| :--- | :--- | :--- | :---- |
90| New code is pushed and triggers a CI build. | Based on all commits that happened since the last release, the new version number gets written to the `package.json`. | The new version gets published to `npm`. | A changelog gets generated and a [release](https://help.github.com/articles/about-releases/) (including a git tag) on GitHub gets created. |
91
92_Note:_ The current release/tag implementation is tied to GitHub, but could be opened up to Bitbucket, GitLab, et al. Feel free to send PRs for these services.
93
94## Default Commit Message Format
95
96This module ships with the [AngularJS Commit Message Conventions](https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit) and changelog generator, but you can [define your own](#plugins) style.
97
98Each commit message consists of a **header**, a **body** and a **footer**. The header has a special
99format that includes a **type**, a **scope** and a **subject** ([full explanation](https://github.com/stevemao/conventional-changelog-angular/blob/master/convention.md)):
100
101```
102<type>(<scope>): <subject>
103<BLANK LINE>
104<body>
105<BLANK LINE>
106<footer>
107```
108
109You can simplify using this convention for yourself and contributors by using [commitizen](https://github.com/commitizen/cz-cli) and [validate-commit-msg](https://github.com/kentcdodds/validate-commit-msg).
110
111### Patch Release
112
113```
114fix(pencil): stop graphite breaking when too much pressure applied
115```
116
117### ~~Minor~~ Feature Release
118
119```
120feat(pencil): add 'graphiteWidth' option
121```
122
123### ~~Major~~ Breaking Release
124
125```
126perf(pencil): remove graphiteWidth option
127
128BREAKING CHANGE: The graphiteWidth option has been removed. The default graphite width of 10mm is always used for performance reason.
129```
130
131## Setup
132
133[![NPM](https://nodei.co/npm/semantic-release.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/semantic-release/)
134
135```bash
136npm install -g semantic-release-cli
137
138cd your-module
139semantic-release-cli setup
140```
141
142![dialogue](https://cloud.githubusercontent.com/assets/908178/9428123/3628dfec-499f-11e5-8bdd-8f3042dd95ed.png)
143
144_[This is what happens under the hood.](https://github.com/semantic-release/cli#manual-setup)_
145
146## Options
147
148You can pass options either via command line (in [kebab-case](https://lodash.com/docs#kebabCase)) or in the `release` field of your `package.json` (in [camelCase](https://lodash.com/docs#camelCase)). The following two examples are the same, but CLI arguments take precedence.
149
150| CLI | package.json |
151| --- | --- |
152| <pre><code>semantic-release pre --no-debug</code><pre> | <pre><code><div>//package.json</div><div>"release": {</div><div> "debug": false</div><div>}</div></code></pre><pre><code>semantic-release pre</code></pre> |
153
154
155These options are currently available:
156- `branch`: The branch on which releases should happen. Default: `'master'`
157- `debug`: If true doesn’t actually publish to npm or write things to file. Default: `!process.env.CI`
158- `githubToken`: The token used to authenticate with GitHub. Default: `process.env.GH_TOKEN`
159- `githubUrl`: Optional. Pass your GitHub Enterprise endpoint.
160- `githubApiPathPrefix`: Optional. The path prefix for your GitHub Enterprise API.
161
162_A few notes on `npm` config_:
1631. The `npm` token can only be defined in the environment as `NPM_TOKEN`, because that’s where `npm` itself is going to read it from.
164
1652. In order to publish to a different `npm` registry you can specify that inside the `package.json`’s [`publishConfig`](https://docs.npmjs.com/files/package.json#publishconfig) field.
166
1673. If you want to use another dist-tag for your publishes than `'latest'` you can specify that inside the `package.json`’s [`publishConfig`](https://docs.npmjs.com/files/package.json#publishconfig) field.
168
1694. `semantic-release` generally tries to orientate itself towards `npm` – it inherits the loglevel for example.
170
171## Plugins
172
173There are numerous steps where you can customize `semantic-release`’s behaviour using plugins. A plugin is a regular [option](#options), but passed inside the `release` block of `package.json`:
174
175```json
176{
177 "release": {
178 "analyzeCommits": "npm-module-name",
179 "generateNotes": "./path/to/a/local/module",
180 "verifyConditions": {
181 "path": "./path/to/a/module",
182 "additional": "config"
183 }
184}
185```
186
187```
188semantic-release pre --analyze-commits="npm-module-name"
189```
190
191A plugin itself is an async function that always receives three arguments.
192
193```js
194module.exports = function (pluginConfig, config, callback) {}
195```
196
197- `pluginConfig`: If the user of your plugin specifies additional plugin config in the `package.json` (see the `verifyConditions` example above) then it’s this object.
198- `config`: A config object containing a lot of information to act upon.
199 - `env`: All environment variables
200 - `npm`: Select npm configuration bits like `registry`, `tag` and `auth`
201 - `options`: `semantic-release` options like `debug`, or `branch`
202 - `pkg`: Parsed `package.json`
203 - For certain plugins the `config` object contains even more information. See below.
204- `callback`: If an error occurs pass it as first argument. Otherwise pass your result as second argument.
205
206
207### `analyzeCommits`
208
209This plugin is responsible for determining the type of the next release. It additionally receives a `commits` array inside `config`. One commit is an object with a `message` and `hash` property. Call the callback with `'major'`, `'premajor'`, `'minor'`, `'preminor'`, `'patch'`, `'prepatch'`, `'prerelease'`, or `null` if nothing changed. Have a look at the [default implementation](https://github.com/semantic-release/commit-analyzer/).
210
211### `generateNotes`
212
213This plugin is responsible for generating release notes. Call the callback with the notes as a string. Have a look at the [default implementation](https://github.com/semantic-release/release-notes-generator/).
214
215### `verifyConditions`
216
217This plugins is responsible for verifying that a release should happen in the first place. For example, the [default implementation](https://github.com/semantic-release/condition-travis/) verifies that the publish is happening on Travis, that it’s the right branch, and that all other build jobs succeeded. There are more use cases for this, e.g. verifying that test coverage is above a certain threshold or that there are no [vulnerabilities](https://nodesecurity.io/) in your dependencies. Be creative.
218
219Passing an array of plugins will run them in series.
220
221### `verifyRelease`
222
223This plugin is responsible for verifying a release that was determined before and is about to be published. There is no default implementation. It additionally receives `nextRelease`, `lastRelease` and `commits` inside `config`. While `commits` is the same as with analyzeCommits, `nextRelease` contains a `type` (e.g. `'major'`) and the new version (e.g. `'1.0.0'`) and `lastRelease` contains the old `version`, the `gitHead` at the time of the release and the npm dist-`tag` (e.g. `'latest'`). Using this information you could [detect breaking changes](https://github.com/semantic-release/cracks) or hold back certain types of releases. Again: Be creative.
224
225Passing an array of plugins will run them in series.
226
227### `getLastRelease`
228
229This plugin is responsible for determining a package’s last release version. The [default implementation](https://github.com/semantic-release/last-release-npm) uses the last published version on a npm registry.
230
231## ITYM*FAQ*LT
232> I think you might frequently ask questions like these
233
234### Why is the `package.json`’s version not updated in my repository?
235
236The `npm` docs even state:
237
238> The most important things in your package.json are the name and version fields. Those are actually required, and your package won’t install without them.
239> – [npm docs](https://docs.npmjs.com/files/package.json#version)
240
241While this entirely true the version number doesn’t have to be checked into source control. `semantic-release` takes care of the version field right before `npm publish` uses it – and this is the only point where it _really_ is required.
242
243### Is there a way to preview which version would currently get published?
244
245If you run `npm run semantic-release` locally a dry run gets performed, which logs the version that would currently get published.
246
247### Can I run this on my own machine rather than on a CI server?
248
249Of course you can, but this doesn’t necessarily mean you should. Running your tests on an independent machine before releasing software is a crucial part of this workflow. Also it is a pain to set this up locally, with tokens lying around and everything. That said, you can run the scripts with `--debug=false` explicitly. You have to export `GH_TOKEN=<your_token>` and `NPM_TOKEN=<your_other_token>`.
250
251### Can I manually trigger the release of a specific version?
252
253You can trigger a release by pushing to your GitHub repository. You deliberately cannot trigger a _specific_ version release, because this is the whole point of `semantic-release`. Start your packages with `1.0.0` and semver on.
254
255### Is it _really_ a good idea to release on every push?
256
257It is indeed a great idea because it _forces_ you to follow best practices. If you don’t feel comfortable making every passing feature or fix on your master branch addressable via `npm` you might not treat your master right. Have a look at [branch workflows](https://guides.github.com/introduction/flow/index.html). If you still think you should have control over the exact point in time of your release, e.g. because you are following a release schedule, you can release only on the `production`/`deploy`/`release` branch and push your code there in certain intervals, or better yet use [dist-tags](https://docs.npmjs.com/cli/dist-tag).
258
259### Why should I trust `semantic-release` with my releases?
260
261`semantic-release` has a full unit- and integration-test-suite that tests _actual_ `npm` publishes against the [npm-registry-couchapp](https://github.com/npm/npm-registry-couchapp/) on all major node.js versions from `^0.10` on. A new version won’t get published if it doesn’t pass on all these engines.
262
263## Badge
264
265Use this in one of your projects? Include one of these badges in your README.md to let people know that your package is published using `semantic-release`.
266
267[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
268
269```md
270[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
271```
272
273[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=plastic)](https://github.com/semantic-release/semantic-release)
274
275```md
276[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=plastic)](https://github.com/semantic-release/semantic-release)
277```
278
279[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release)
280
281```md
282[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release)
283```
284
285## License
286
287MIT License
2882015 © Stephan Bönnemann and [contributors](https://github.com/semantic-release/semantic-release/graphs/contributors)
289
290[![](https://cloud.githubusercontent.com/assets/908178/6091690/cc86f58c-aeb8-11e4-94cb-15f15f486cde.png)](https://twitter.com/trodrigues/status/509301317467373571)